2525import javafx .collections .FXCollections ;
2626import javafx .collections .ObservableList ;
2727import javafx .util .Duration ;
28+ import org .junit .BeforeClass ;
2829import org .junit .Test ;
2930
3031import java .util .Arrays ;
3536
3637public final class JavaFxObservableTest {
3738
39+ @ BeforeClass
40+ public static void initJFX () {
41+ javafx .application .Platform .startup (() ->{});
42+ }
43+
3844 @ Test
3945 public void testIntervalSource () {
4046
@@ -87,6 +93,27 @@ public void testListPropertyEmitOnChanged() {
8793
8894 testObserver .assertValueCount (3 );
8995 }
96+ @ Test
97+ public void testRxObservableChanges () {
98+ Property <String > sourceProperty = new SimpleStringProperty ();
99+ Observable <Change <String >> emissions = JavaFxObservable .changesOf (sourceProperty ).take (4 );
100+
101+ TestObserver <Change <String >> testObserver = new TestObserver <>();
102+
103+ emissions .subscribe (testObserver );
104+
105+ sourceProperty .setValue ("Alpha" );
106+ sourceProperty .setValue ("Beta" );
107+ sourceProperty .setValue (null );
108+ sourceProperty .setValue ("Gamma" );
109+
110+ testObserver .assertValues (
111+ new Change <>(null , "Alpha" ),
112+ new Change <>("Alpha" , "Beta" ),
113+ new Change <>("Beta" , null ),
114+ new Change <>(null , "Gamma" )
115+ );
116+ }
90117
91118 @ Test
92119 public void testRxObservableListAdds () {
@@ -101,7 +128,7 @@ public void testRxObservableListAdds() {
101128 .take (3 )
102129 .toList ()
103130 .toObservable ()
104- .subscribe (l -> assertTrue (l .containsAll (Arrays .asList ("Alpha" ,"Beta" ,"Gamma" ))),Throwable ::printStackTrace ,gate ::countDown );
131+ .subscribe (l -> assertTrue (l .equals (Arrays .asList ("Alpha" , "Beta" , "Gamma" ))), Throwable ::printStackTrace , gate ::countDown ); ;
105132
106133 Platform .runLater (() -> {
107134 sourceList .add ("Alpha" );
0 commit comments