File tree Expand file tree Collapse file tree
src/test/java/com/baeldung/java9/streams.reactive Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
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 >
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments