Skip to content

Commit 49ce027

Browse files
tomekl007pivovarit
authored andcommitted
Bael 679 reactive streams (eugenp#1978)
* BAEL-679 code for reactive streams * BAEL-679 typo * BAEL-679 awaitility
1 parent af40bd4 commit 49ce027

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎core-java-9/pom.xml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
<version>${mockito.version}</version>
4848
<scope>test</scope>
4949
</dependency>
50+
<dependency>
51+
<groupId>com.jayway.awaitility</groupId>
52+
<artifactId>awaitility</artifactId>
53+
<version>${awaitility.version}</version>
54+
<scope>test</scope>
55+
</dependency>
56+
5057

5158
</dependencies>
5259

@@ -90,6 +97,7 @@
9097
<org.hamcrest.version>1.3</org.hamcrest.version>
9198
<junit.version>4.12</junit.version>
9299
<mockito.version>1.10.19</mockito.version>
100+
<awaitility.version>1.7.0</awaitility.version>
93101
</properties>
94102

95103
</project>

‎core-java-9/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ public void givenPublisher_whenSubscribeToIt_thenShouldConsumeAllElements() thro
2424
publisher.close();
2525

2626
//then
27-
Thread.sleep(1000);
28-
assertThat(subscriber.consumedElements).containsExactlyElementsOf(items);
27+
28+
await().atMost(1000, TimeUnit.MILLISECONDS).until(
29+
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(items)
30+
);
2931
}
3032

3133
@Test
@@ -44,8 +46,9 @@ public void givenPublisher_whenSubscribeAndTransformElements_thenShouldConsumeAl
4446
publisher.close();
4547

4648
//then
47-
Thread.sleep(1000);
48-
assertThat(subscriber.consumedElements).containsExactlyElementsOf(expectedResult);
49+
await().atMost(1000, TimeUnit.MILLISECONDS).until(
50+
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expectedResult)
51+
);
4952
}
5053

5154
@Test
@@ -63,7 +66,8 @@ public void givenPublisher_whenRequestForOnlyOneElement_thenShouldConsumeOnlyTha
6366
publisher.close();
6467

6568
//then
66-
Thread.sleep(1000);
67-
assertThat(subscriber.consumedElements).containsExactlyElementsOf(expected);
69+
await().atMost(1000, TimeUnit.MILLISECONDS).until(
70+
() -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expected)
71+
);
6872
}
6973
}

0 commit comments

Comments
 (0)