Skip to content

Commit 5d7f549

Browse files
authored
2.x: make any() and all() return Single, patch up tests (#4573)
1 parent 994d8fc commit 5d7f549

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1658
-273
lines changed

src/main/java/io/reactivex/Completable.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import io.reactivex.internal.operators.observable.ObservableDelaySubscriptionOther;
3030
import io.reactivex.internal.operators.single.SingleDelayWithCompletable;
3131
import io.reactivex.internal.util.ExceptionHelper;
32+
import io.reactivex.observers.TestObserver;
3233
import io.reactivex.plugins.RxJavaPlugins;
3334
import io.reactivex.schedulers.Schedulers;
34-
import io.reactivex.subscribers.TestSubscriber;
3535

3636
/**
3737
* Represents a deferred computation without any value but only indication for completion or exception.
@@ -1804,41 +1804,41 @@ public final Completable unsubscribeOn(final Scheduler scheduler) {
18041804
// -------------------------------------------------------------------------
18051805

18061806
/**
1807-
* Creates a TestSubscriber and subscribes
1807+
* Creates a TestObserver and subscribes
18081808
* it to this Completable.
18091809
* <dl>
18101810
* <dt><b>Scheduler:</b></dt>
18111811
* <dd>{@code test} does not operate by default on a particular {@link Scheduler}.</dd>
18121812
* </dl>
1813-
* @return the new TestSubscriber instance
1813+
* @return the new TestObserver instance
18141814
* @since 2.0
18151815
*/
18161816
@SchedulerSupport(SchedulerSupport.NONE)
1817-
public final TestSubscriber<Void> test() {
1818-
TestSubscriber<Void> ts = new TestSubscriber<Void>();
1819-
subscribe(new SubscriberCompletableObserver<Void>(ts));
1817+
public final TestObserver<Void> test() {
1818+
TestObserver<Void> ts = new TestObserver<Void>();
1819+
subscribe(ts);
18201820
return ts;
18211821
}
18221822

18231823
/**
1824-
* Creates a TestSubscriber optionally in cancelled state, then subscribes it to this Completable.
1825-
* @param cancelled if true, the TestSubscriber will be cancelled before subscribing to this
1824+
* Creates a TestObserver optionally in cancelled state, then subscribes it to this Completable.
1825+
* @param cancelled if true, the TestObserver will be cancelled before subscribing to this
18261826
* Completable.
18271827
* <dl>
18281828
* <dt><b>Scheduler:</b></dt>
18291829
* <dd>{@code test} does not operate by default on a particular {@link Scheduler}.</dd>
18301830
* </dl>
1831-
* @return the new TestSubscriber instance
1831+
* @return the new TestObserver instance
18321832
* @since 2.0
18331833
*/
18341834
@SchedulerSupport(SchedulerSupport.NONE)
1835-
public final TestSubscriber<Void> test(boolean cancelled) {
1836-
TestSubscriber<Void> ts = new TestSubscriber<Void>();
1835+
public final TestObserver<Void> test(boolean cancelled) {
1836+
TestObserver<Void> ts = new TestObserver<Void>();
18371837

18381838
if (cancelled) {
18391839
ts.cancel();
18401840
}
1841-
subscribe(new SubscriberCompletableObserver<Void>(ts));
1841+
subscribe(ts);
18421842
return ts;
18431843
}
18441844
}

src/main/java/io/reactivex/Flowable.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4862,15 +4862,15 @@ public static <T, R> Flowable<R> zipIterable(Iterable<? extends Publisher<? exte
48624862
*
48634863
* @param predicate
48644864
* a function that evaluates an item and returns a Boolean
4865-
* @return a Flowable that emits {@code true} if all items emitted by the source Publisher satisfy the
4865+
* @return a Single that emits {@code true} if all items emitted by the source Publisher satisfy the
48664866
* predicate; otherwise, {@code false}
48674867
* @see <a href="http://reactivex.io/documentation/operators/all.html">ReactiveX operators documentation: All</a>
48684868
*/
48694869
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
48704870
@SchedulerSupport(SchedulerSupport.NONE)
4871-
public final Flowable<Boolean> all(Predicate<? super T> predicate) {
4871+
public final Single<Boolean> all(Predicate<? super T> predicate) {
48724872
ObjectHelper.requireNonNull(predicate, "predicate is null");
4873-
return RxJavaPlugins.onAssembly(new FlowableAll<T>(this, predicate));
4873+
return RxJavaPlugins.onAssembly(new FlowableAllSingle<T>(this, predicate));
48744874
}
48754875

48764876
/**
@@ -4919,15 +4919,15 @@ public final Flowable<T> ambWith(Publisher<? extends T> other) {
49194919
*
49204920
* @param predicate
49214921
* the condition to test items emitted by the source Publisher
4922-
* @return a Flowable that emits a Boolean that indicates whether any item emitted by the source
4922+
* @return a Single that emits a Boolean that indicates whether any item emitted by the source
49234923
* Publisher satisfies the {@code predicate}
49244924
* @see <a href="http://reactivex.io/documentation/operators/contains.html">ReactiveX operators documentation: Contains</a>
49254925
*/
49264926
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
49274927
@SchedulerSupport(SchedulerSupport.NONE)
4928-
public final Flowable<Boolean> any(Predicate<? super T> predicate) {
4928+
public final Single<Boolean> any(Predicate<? super T> predicate) {
49294929
ObjectHelper.requireNonNull(predicate, "predicate is null");
4930-
return RxJavaPlugins.onAssembly(new FlowableAny<T>(this, predicate));
4930+
return RxJavaPlugins.onAssembly(new FlowableAnySingle<T>(this, predicate));
49314931
}
49324932

49334933
/**
@@ -6660,7 +6660,7 @@ public final Flowable<T> concatWith(Publisher<? extends T> other) {
66606660
*/
66616661
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
66626662
@SchedulerSupport(SchedulerSupport.NONE)
6663-
public final Flowable<Boolean> contains(final Object item) {
6663+
public final Single<Boolean> contains(final Object item) {
66646664
ObjectHelper.requireNonNull(item, "item is null");
66656665
return any(Functions.equalsWith(item));
66666666
}
@@ -8814,7 +8814,7 @@ public final Flowable<T> ignoreElements() {
88148814
*/
88158815
@BackpressureSupport(BackpressureKind.UNBOUNDED_IN)
88168816
@SchedulerSupport(SchedulerSupport.NONE)
8817-
public final Flowable<Boolean> isEmpty() {
8817+
public final Single<Boolean> isEmpty() {
88188818
return all(Functions.alwaysFalse());
88198819
}
88208820

src/main/java/io/reactivex/Maybe.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import io.reactivex.internal.operators.flowable.*;
2727
import io.reactivex.internal.operators.maybe.*;
2828
import io.reactivex.internal.util.*;
29+
import io.reactivex.observers.TestObserver;
2930
import io.reactivex.plugins.RxJavaPlugins;
3031
import io.reactivex.schedulers.Schedulers;
31-
import io.reactivex.subscribers.TestSubscriber;
3232

3333
/**
3434
* Represents a deferred computation and emission of a maybe value or exception.
@@ -3776,40 +3776,40 @@ public final <U, R> Maybe<R> zipWith(MaybeSource<? extends U> other, BiFunction<
37763776
// ------------------------------------------------------------------
37773777

37783778
/**
3779-
* Creates a TestSubscriber and subscribes
3779+
* Creates a TestObserver and subscribes
37803780
* it to this Maybe.
37813781
* <dl>
37823782
* <dt><b>Scheduler:</b></dt>
37833783
* <dd>{@code test} does not operate by default on a particular {@link Scheduler}.</dd>
37843784
* </dl>
3785-
* @return the new TestSubscriber instance
3785+
* @return the new TestObserver instance
37863786
*/
37873787
@SchedulerSupport(SchedulerSupport.NONE)
3788-
public final TestSubscriber<T> test() {
3789-
TestSubscriber<T> ts = new TestSubscriber<T>();
3790-
toFlowable().subscribe(ts);
3788+
public final TestObserver<T> test() {
3789+
TestObserver<T> ts = new TestObserver<T>();
3790+
subscribe(ts);
37913791
return ts;
37923792
}
37933793

37943794
/**
3795-
* Creates a TestSubscriber optionally in cancelled state, then subscribes it to this Maybe.
3795+
* Creates a TestObserver optionally in cancelled state, then subscribes it to this Maybe.
37963796
* <dl>
37973797
* <dt><b>Scheduler:</b></dt>
37983798
* <dd>{@code test} does not operate by default on a particular {@link Scheduler}.</dd>
37993799
* </dl>
3800-
* @param cancelled if true, the TestSubscriber will be cancelled before subscribing to this
3800+
* @param cancelled if true, the TestObserver will be cancelled before subscribing to this
38013801
* Maybe.
3802-
* @return the new TestSubscriber instance
3802+
* @return the new TestObserver instance
38033803
*/
38043804
@SchedulerSupport(SchedulerSupport.NONE)
3805-
public final TestSubscriber<T> test(boolean cancelled) {
3806-
TestSubscriber<T> ts = new TestSubscriber<T>();
3805+
public final TestObserver<T> test(boolean cancelled) {
3806+
TestObserver<T> ts = new TestObserver<T>();
38073807

38083808
if (cancelled) {
38093809
ts.cancel();
38103810
}
38113811

3812-
toFlowable().subscribe(ts);
3812+
subscribe(ts);
38133813
return ts;
38143814
}
38153815
}

src/main/java/io/reactivex/Observable.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,14 +4260,14 @@ public static <T, R> Observable<R> zipIterable(Iterable<? extends ObservableSour
42604260
*
42614261
* @param predicate
42624262
* a function that evaluates an item and returns a Boolean
4263-
* @return an Observable that emits {@code true} if all items emitted by the source ObservableSource satisfy the
4263+
* @return a Single that emits {@code true} if all items emitted by the source ObservableSource satisfy the
42644264
* predicate; otherwise, {@code false}
42654265
* @see <a href="http://reactivex.io/documentation/operators/all.html">ReactiveX operators documentation: All</a>
42664266
*/
42674267
@SchedulerSupport(SchedulerSupport.NONE)
4268-
public final Observable<Boolean> all(Predicate<? super T> predicate) {
4268+
public final Single<Boolean> all(Predicate<? super T> predicate) {
42694269
ObjectHelper.requireNonNull(predicate, "predicate is null");
4270-
return RxJavaPlugins.onAssembly(new ObservableAll<T>(this, predicate));
4270+
return RxJavaPlugins.onAssembly(new ObservableAllSingle<T>(this, predicate));
42714271
}
42724272

42734273
/**
@@ -4309,14 +4309,14 @@ public final Observable<T> ambWith(ObservableSource<? extends T> other) {
43094309
*
43104310
* @param predicate
43114311
* the condition to test items emitted by the source ObservableSource
4312-
* @return an Observable that emits a Boolean that indicates whether any item emitted by the source
4312+
* @return a Single that emits a Boolean that indicates whether any item emitted by the source
43134313
* ObservableSource satisfies the {@code predicate}
43144314
* @see <a href="http://reactivex.io/documentation/operators/contains.html">ReactiveX operators documentation: Contains</a>
43154315
*/
43164316
@SchedulerSupport(SchedulerSupport.NONE)
4317-
public final Observable<Boolean> any(Predicate<? super T> predicate) {
4317+
public final Single<Boolean> any(Predicate<? super T> predicate) {
43184318
ObjectHelper.requireNonNull(predicate, "predicate is null");
4319-
return RxJavaPlugins.onAssembly(new ObservableAny<T>(this, predicate));
4319+
return RxJavaPlugins.onAssembly(new ObservableAnySingle<T>(this, predicate));
43204320
}
43214321

43224322
/**
@@ -5798,12 +5798,12 @@ public final Observable<T> concatWith(ObservableSource<? extends T> other) {
57985798
*
57995799
* @param element
58005800
* the item to search for in the emissions from the source ObservableSource
5801-
* @return an Observable that emits {@code true} if the specified item is emitted by the source ObservableSource,
5801+
* @return a Single that emits {@code true} if the specified item is emitted by the source ObservableSource,
58025802
* or {@code false} if the source ObservableSource completes without emitting that item
58035803
* @see <a href="http://reactivex.io/documentation/operators/contains.html">ReactiveX operators documentation: Contains</a>
58045804
*/
58055805
@SchedulerSupport(SchedulerSupport.NONE)
5806-
public final Observable<Boolean> contains(final Object element) {
5806+
public final Single<Boolean> contains(final Object element) {
58075807
ObjectHelper.requireNonNull(element, "element is null");
58085808
return any(Functions.equalsWith(element));
58095809
}
@@ -7594,11 +7594,11 @@ public final Observable<T> ignoreElements() {
75947594
* <dd>{@code isEmpty} does not operate by default on a particular {@link Scheduler}.</dd>
75957595
* </dl>
75967596
*
7597-
* @return an Observable that emits a Boolean
7597+
* @return a Single that emits a Boolean
75987598
* @see <a href="http://reactivex.io/documentation/operators/contains.html">ReactiveX operators documentation: Contains</a>
75997599
*/
76007600
@SchedulerSupport(SchedulerSupport.NONE)
7601-
public final Observable<Boolean> isEmpty() {
7601+
public final Single<Boolean> isEmpty() {
76027602
return all(Functions.alwaysFalse());
76037603
}
76047604

src/main/java/io/reactivex/Single.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import java.util.concurrent.*;
1717

18-
import org.reactivestreams.*;
18+
import org.reactivestreams.Publisher;
1919

2020
import io.reactivex.annotations.*;
2121
import io.reactivex.disposables.Disposable;
@@ -30,9 +30,9 @@
3030
import io.reactivex.internal.operators.observable.ObservableConcatMap;
3131
import io.reactivex.internal.operators.single.*;
3232
import io.reactivex.internal.util.*;
33+
import io.reactivex.observers.TestObserver;
3334
import io.reactivex.plugins.RxJavaPlugins;
3435
import io.reactivex.schedulers.Schedulers;
35-
import io.reactivex.subscribers.TestSubscriber;
3636

3737
/**
3838
* The Single class implements the Reactive Pattern for a single value response.
@@ -2806,42 +2806,42 @@ public final <U, R> Single<R> zipWith(SingleSource<U> other, BiFunction<? super
28062806
// Fluent test support, super handy and reduces test preparation boilerplate
28072807
// -------------------------------------------------------------------------
28082808
/**
2809-
* Creates a TestSubscriber and subscribes
2809+
* Creates a TestObserver and subscribes
28102810
* it to this Single.
28112811
* <dl>
28122812
* <dt><b>Scheduler:</b></dt>
28132813
* <dd>{@code test} does not operate by default on a particular {@link Scheduler}.</dd>
28142814
* </dl>
2815-
* @return the new TestSubscriber instance
2815+
* @return the new TestObserver instance
28162816
* @since 2.0
28172817
*/
28182818
@SchedulerSupport(SchedulerSupport.NONE)
2819-
public final TestSubscriber<T> test() {
2820-
TestSubscriber<T> ts = new TestSubscriber<T>();
2821-
toFlowable().subscribe(ts);
2819+
public final TestObserver<T> test() {
2820+
TestObserver<T> ts = new TestObserver<T>();
2821+
subscribe(ts);
28222822
return ts;
28232823
}
28242824

28252825
/**
2826-
* Creates a TestSubscriber optionally in cancelled state, then subscribes it to this Single.
2826+
* Creates a TestObserver optionally in cancelled state, then subscribes it to this Single.
28272827
* <dl>
28282828
* <dt><b>Scheduler:</b></dt>
28292829
* <dd>{@code test} does not operate by default on a particular {@link Scheduler}.</dd>
28302830
* </dl>
2831-
* @param cancelled if true, the TestSubscriber will be cancelled before subscribing to this
2831+
* @param cancelled if true, the TestObserver will be cancelled before subscribing to this
28322832
* Single.
2833-
* @return the new TestSubscriber instance
2833+
* @return the new TestObserver instance
28342834
* @since 2.0
28352835
*/
28362836
@SchedulerSupport(SchedulerSupport.NONE)
2837-
public final TestSubscriber<T> test(boolean cancelled) {
2838-
TestSubscriber<T> ts = new TestSubscriber<T>();
2837+
public final TestObserver<T> test(boolean cancelled) {
2838+
TestObserver<T> ts = new TestObserver<T>();
28392839

28402840
if (cancelled) {
28412841
ts.cancel();
28422842
}
28432843

2844-
toFlowable().subscribe(ts);
2844+
subscribe(ts);
28452845
return ts;
28462846
}
28472847
}

0 commit comments

Comments
 (0)