diff --git a/rxjava/pom.xml b/rxjava/pom.xml index 7b78d09eb6..bf5f073d8d 100644 --- a/rxjava/pom.xml +++ b/rxjava/pom.xml @@ -25,6 +25,12 @@ rxjava 2.1.3 + + + com.jayway.awaitility + awaitility + 1.7.0 + diff --git a/rxjava/src/test/java/com/baeldung/rxjava/ConnectableObservableTest.java b/rxjava/src/test/java/com/baeldung/rxjava/ConnectableObservableTest.java index 981875510d..031ff0c5bb 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/ConnectableObservableTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/ConnectableObservableTest.java @@ -6,6 +6,7 @@ import rx.observables.ConnectableObservable; import java.util.concurrent.TimeUnit; +import static com.jayway.awaitility.Awaitility.await; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; @@ -15,12 +16,12 @@ public class ConnectableObservableTest { public void givenConnectableObservable_whenConnect_thenGetMessage() throws InterruptedException { String[] result = {""}; ConnectableObservable connectable - = Observable.interval(200, TimeUnit.MILLISECONDS).publish(); + = Observable.interval(500, TimeUnit.MILLISECONDS).publish(); connectable.subscribe(i -> result[0] += i); assertFalse(result[0].equals("01")); connectable.connect(); - Thread.sleep(500); - assertTrue(result[0].equals("01")); + await() + .until(() -> assertTrue(result[0].equals("01"))); } }