@@ -328,19 +328,22 @@ public void assertReceivedOnNext(List<T> items) {
328328 }
329329
330330 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 " );
343341 }
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+
344347 }
345348 }
346349
@@ -670,4 +673,35 @@ final void assertionError(String message) {
670673 }
671674 throw ae ;
672675 }
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+ }
673707}
0 commit comments