15
15
*/
16
16
package rx .operators ;
17
17
18
- import static org .mockito . Matchers .*;
18
+ import static org .junit . Assert .*;
19
19
import static org .mockito .Mockito .*;
20
20
21
- import org .junit .Test ;
21
+ import java .util .concurrent .CountDownLatch ;
22
+ import java .util .concurrent .TimeUnit ;
22
23
24
+ import org .junit .Test ;
23
25
import org .mockito .InOrder ;
26
+ import org .mockito .invocation .InvocationOnMock ;
27
+ import org .mockito .stubbing .Answer ;
28
+
24
29
import rx .Observable ;
25
30
import rx .Observer ;
26
31
import rx .Scheduler ;
@@ -66,7 +71,6 @@ public void testObserveOn() {
66
71
verify (observer , times (1 )).onCompleted ();
67
72
}
68
73
69
-
70
74
@ Test
71
75
@ SuppressWarnings ("unchecked" )
72
76
public void testOrdering () throws InterruptedException {
@@ -76,9 +80,21 @@ public void testOrdering() throws InterruptedException {
76
80
77
81
InOrder inOrder = inOrder (observer );
78
82
83
+ final CountDownLatch completedLatch = new CountDownLatch (1 );
84
+ doAnswer (new Answer <Void >() {
85
+
86
+ @ Override
87
+ public Void answer (InvocationOnMock invocation ) throws Throwable {
88
+ completedLatch .countDown ();
89
+ return null ;
90
+ }
91
+ }).when (observer ).onCompleted ();
92
+
79
93
obs .observeOn (Schedulers .threadPoolForComputation ()).subscribe (observer );
80
94
81
- Thread .sleep (500 ); // !!! not a true unit test
95
+ if (!completedLatch .await (1000 , TimeUnit .MILLISECONDS )) {
96
+ fail ("timed out waiting" );
97
+ }
82
98
83
99
inOrder .verify (observer , times (1 )).onNext ("one" );
84
100
inOrder .verify (observer , times (1 )).onNext (null );
0 commit comments