@@ -328,19 +328,22 @@ public void assertReceivedOnNext(List<T> items) {
328
328
}
329
329
330
330
for (int i = 0 ; i < items .size (); i ++) {
331
- T expected = items .get (i );
332
- T actual = values .get (i );
333
- if (expected == null ) {
334
- // check for null equality
335
- if (actual != null ) {
336
- assertionError ("Value at index: " + i + " expected to be [null] but was: [" + actual + "]\n " );
337
- }
338
- } else if (!expected .equals (actual )) {
339
- assertionError ("Value at index: " + i
340
- + " expected to be [" + expected + "] (" + expected .getClass ().getSimpleName ()
341
- + ") but was: [" + actual + "] (" + (actual != null ? actual .getClass ().getSimpleName () : "null" ) + ")\n " );
342
-
331
+ assertItem (items .get (i ), i );
332
+ }
333
+ }
334
+
335
+ private void assertItem (T expected , int i ) {
336
+ T actual = values .get (i );
337
+ if (expected == null ) {
338
+ // check for null equality
339
+ if (actual != null ) {
340
+ assertionError ("Value at index: " + i + " expected to be [null] but was: [" + actual + "]\n " );
343
341
}
342
+ } else if (!expected .equals (actual )) {
343
+ assertionError ("Value at index: " + i
344
+ + " expected to be [" + expected + "] (" + expected .getClass ().getSimpleName ()
345
+ + ") but was: [" + actual + "] (" + (actual != null ? actual .getClass ().getSimpleName () : "null" ) + ")\n " );
346
+
344
347
}
345
348
}
346
349
@@ -670,4 +673,35 @@ final void assertionError(String message) {
670
673
}
671
674
throw ae ;
672
675
}
676
+
677
+ /**
678
+ * Assert that the TestSubscriber contains the given first and optional rest values exactly
679
+ * and if so, clears the internal list of values.
680
+ * <p>
681
+ * <code><pre>
682
+ * TestSubscriber ts = new TestSubscriber();
683
+ *
684
+ * ts.onNext(1);
685
+ *
686
+ * ts.assertValuesAndClear(1);
687
+ *
688
+ * ts.onNext(2);
689
+ * ts.onNext(3);
690
+ *
691
+ * ts.assertValuesAndClear(2, 3); // no mention of 1
692
+ * </pre></code>
693
+ * @param expectedFirstValue the expected first value
694
+ * @param expectedRestValues the optional rest values
695
+ * @since (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
696
+ */
697
+ @ Experimental
698
+ public final void assertValuesAndClear (T expectedFirstValue , T ... expectedRestValues ) {
699
+ int n = 1 + expectedRestValues .length ;
700
+ assertValueCount (n );
701
+ assertItem (expectedFirstValue , 0 );
702
+ for (int i = 0 ; i < expectedRestValues .length ; i ++) {
703
+ assertItem (expectedRestValues [i ], i + 1 );
704
+ }
705
+ values .clear ();
706
+ }
673
707
}
0 commit comments