Skip to content

Commit 36dde84

Browse files
authored
2.x: add fluent requestMore to TestSubscriber (#4838)
1 parent bbae4a5 commit 36dde84

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/main/java/io/reactivex/subscribers/TestSubscriber.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616

1717
import org.reactivestreams.*;
1818

19+
import io.reactivex.annotations.Experimental;
1920
import io.reactivex.disposables.Disposable;
2021
import io.reactivex.functions.Consumer;
2122
import io.reactivex.internal.fuseable.QueueSubscription;
2223
import io.reactivex.internal.subscriptions.SubscriptionHelper;
23-
import io.reactivex.internal.util.*;
24+
import io.reactivex.internal.util.ExceptionHelper;
2425
import io.reactivex.observers.BaseTestConsumer;
2526

2627
/**
@@ -403,6 +404,18 @@ public final TestSubscriber<T> assertOf(Consumer<? super TestSubscriber<T>> chec
403404
return this;
404405
}
405406

407+
/**
408+
* Calls {@link #request(long)} and returns this.
409+
* @param n the request amount
410+
* @return this
411+
* @since 2.0.1 - experimental
412+
*/
413+
@Experimental
414+
public final TestSubscriber<T> requestMore(long n) {
415+
request(n);
416+
return this;
417+
}
418+
406419
/**
407420
* A subscriber that ignores all events and does not report errors.
408421
*/

src/test/java/io/reactivex/subscribers/TestSubscriberTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,4 +1707,16 @@ public void assertValueAtInvalidIndex() {
17071707
}
17081708
});
17091709
}
1710+
1711+
@Test
1712+
public void requestMore() {
1713+
Flowable.range(1, 5)
1714+
.test(0)
1715+
.requestMore(1)
1716+
.assertValue(1)
1717+
.requestMore(2)
1718+
.assertValues(1, 2, 3)
1719+
.requestMore(3)
1720+
.assertResult(1, 2, 3, 4, 5);
1721+
}
17101722
}

0 commit comments

Comments
 (0)