-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sizeOf(ObservableCollection) factory methods.
- Loading branch information
1 parent
2e7115d
commit 1515b01
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.reactfx; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
|
||
import org.junit.Test; | ||
|
||
public class SizeOfTest { | ||
|
||
@Test | ||
public void test() { | ||
ObservableList<Integer> list = FXCollections.observableArrayList(); | ||
EventStream<Integer> size = EventStreams.sizeOf(list); | ||
List<Integer> sizes = new ArrayList<>(); | ||
Subscription sub = size.subscribe(sizes::add); | ||
list.add(1); | ||
list.addAll(2, 3, 4); | ||
assertEquals(Arrays.asList(0, 1, 4), sizes); | ||
|
||
sub.unsubscribe(); | ||
sizes.clear(); | ||
list.addAll(5, 6); | ||
assertEquals(Arrays.asList(), sizes); | ||
|
||
size.subscribe(sizes::add); | ||
list.addAll(7, 8); | ||
assertEquals(Arrays.asList(6, 8), sizes); | ||
} | ||
|
||
} |