23
23
import org .junit .Before ;
24
24
import org .junit .Ignore ;
25
25
import org .junit .Test ;
26
+ import org .mockito .InOrder ;
26
27
import org .mockito .Mock ;
27
28
import org .mockito .MockitoAnnotations ;
28
29
@@ -361,12 +362,6 @@ public void whenThrowNonEmpty() {
361
362
verify (observer , never ()).onCompleted ();
362
363
}
363
364
364
- /**
365
- * Disabled for now as I am not sure what this should assert to and it is non-deterministic.
366
- *
367
- * Where is the non-determinism coming from since there is no concurrency in this test?
368
- */
369
- @ Ignore
370
365
@ Test
371
366
public void whenComplicated () {
372
367
PublishSubject <Integer > xs = PublishSubject .create ();
@@ -379,53 +374,41 @@ public void whenComplicated() {
379
374
ys .toObservable ().and (zs .toObservable ()).then (sub2 ) // 4-7=-3, 5-8=-3, 6-9=-3
380
375
);
381
376
382
- // 5, 7, 9, 7, 16, 27, -3, -3, -3
383
-
384
- // order they join is ...
385
- // 7, 16, 5, -3, 27, 7, -3, 9, -3
386
-
387
- // 7, 16, 7, -4
388
-
389
377
TestObserver <Integer > to = new TestObserver <Integer >(observer );
390
378
m .subscribe (to );
391
379
392
- xs .onNext (1 ); // t == 210
380
+ xs .onNext (1 ); // t == 210, xs[1], ys[], zs[]
393
381
394
- xs .onNext (2 ); // t == 220
395
- zs .onNext (7 ); // t == 220
382
+ xs .onNext (2 ); // t == 220, xs[1, 2], ys[], zs[]
383
+ zs .onNext (7 ); // t == 220, xs[1, 2], ys[], zs[7] triggers x and z; emit 1 * 7, remains xs[2], ys[], zs[]
396
384
397
- xs .onNext (3 ); // t == 230
398
- zs .onNext (8 ); // t == 230
385
+ xs .onNext (3 ); // t == 230, xs[2,3], ys[], zs[]
386
+ zs .onNext (8 ); // t == 230, xs[2,3], ys[], zs[8] triggers x and z, emit 2 * 8, remains xs[3], ys[], zs[]
399
387
400
- ys .onNext (4 ); // t == 240
401
- zs .onNext (9 ); // t == 240
402
- xs .onCompleted (); // t == 240
388
+ ys .onNext (4 ); // t == 240, xs[], ys[4], zs[] triggers x and y, emit 3 + 4, remains xs[], ys[], zs[]
389
+ zs .onNext (9 ); // t == 240, xs[], ys[], zs[9]
390
+ xs .onCompleted (); // t == 240, completed 1
403
391
404
- ys .onNext (5 ); // t == 250
392
+ ys .onNext (5 ); // t == 250, xs[], ys[5], zs[9], triggers ys and zs, emits 5 - 9, remains xs[], ys[], zs[]
405
393
406
- ys .onNext (6 ); // t == 260
394
+ ys .onNext (6 ); // t == 260, xs[], ys[6], zs[]
407
395
408
- ys .onCompleted (); // t == 270
396
+ ys .onCompleted (); // t == 270, completed 2
409
397
410
- zs .onCompleted (); // t == 300
398
+ zs .onCompleted (); // t == 300, completed 3, triggers when() oncompleted
411
399
412
400
System .out .println ("Events: " + to .getOnNextEvents ());
413
401
414
- to .assertReceivedOnNext (Arrays .asList (7 , 16 , 5 , - 3 , 27 , 7 , -3 , 9 , - 3 ));
402
+ to .assertReceivedOnNext (Arrays .asList (7 , 16 , 7 , -4 ));
415
403
to .assertTerminalEvent ();
416
404
417
- // TODO validate the following
418
- /**
419
- * The following assertions existed and passed in 0.16. How did it ever pass?
420
- * What is this supposed to do if not [7, 16, 5, -3, 27, 7, -3, 9, -3] ?
421
- */
422
- // InOrder inOrder = inOrder(observer);
423
- //
424
- // inOrder.verify(observer, times(1)).onNext(1 * 7);
425
- // inOrder.verify(observer, times(1)).onNext(2 * 8);
426
- // inOrder.verify(observer, times(1)).onNext(3 + 4);
427
- // inOrder.verify(observer, times(1)).onNext(5 - 9);
428
- // inOrder.verify(observer, times(1)).onCompleted();
429
- // verify(observer, never()).onError(any(Throwable.class));
405
+ InOrder inOrder = inOrder (observer );
406
+
407
+ inOrder .verify (observer , times (1 )).onNext (1 * 7 );
408
+ inOrder .verify (observer , times (1 )).onNext (2 * 8 );
409
+ inOrder .verify (observer , times (1 )).onNext (3 + 4 );
410
+ inOrder .verify (observer , times (1 )).onNext (5 - 9 );
411
+ inOrder .verify (observer , times (1 )).onCompleted ();
412
+ verify (observer , never ()).onError (any (Throwable .class ));
430
413
}
431
414
}
0 commit comments