From 52625427736bc68a08f8764ef97752bb957f2f87 Mon Sep 17 00:00:00 2001 From: akarnokd Date: Thu, 20 Jun 2019 17:25:59 +0200 Subject: [PATCH] 3.x: Remove methods from test consumers, make internal versions --- src/main/java/io/reactivex/Completable.java | 8 +- src/main/java/io/reactivex/Maybe.java | 8 +- src/main/java/io/reactivex/Single.java | 8 +- .../CompletableAndThenCompletable.java | 2 +- .../operators/flowable/FlowablePublish.java | 1 + .../observable/ObservablePublish.java | 4 +- .../reactivex/observers/BaseTestConsumer.java | 500 +---- .../io/reactivex/observers/TestObserver.java | 161 +- .../reactivex/subscribers/TestSubscriber.java | 149 +- src/test/java/io/reactivex/XFlatMapTest.java | 42 +- .../completable/CompletableTest.java | 15 +- .../disposables/CompositeDisposableTest.java | 2 +- .../disposables/DisposablesTest.java | 2 +- .../reactivex/exceptions/ExceptionsTest.java | 1 + .../OnErrorNotImplementedExceptionTest.java | 1 + .../flowable/FlowableBackpressureTests.java | 94 +- .../flowable/FlowableCollectTest.java | 1 + .../flowable/FlowableCovarianceTest.java | 9 +- .../flowable/FlowableEventStreamTest.java | 2 +- .../flowable/FlowableFuseableTest.java | 34 +- .../reactivex/flowable/FlowableNullTests.java | 1 + .../flowable/FlowableSubscriberTest.java | 1 + .../io/reactivex/flowable/FlowableTests.java | 3 +- .../flowable/FlowableThrottleLastTests.java | 2 +- .../FlowableThrottleWithTimeoutTests.java | 1 + .../ArrayCompositeDisposableTest.java | 2 +- .../CancellableDisposableTest.java | 2 +- .../disposables/DisposableHelperTest.java | 2 +- .../disposables/EmptyDisposableTest.java | 2 +- .../ListCompositeDisposableTest.java | 2 +- .../internal/functions/FunctionsTest.java | 2 +- .../internal/functions/ObjectHelperTest.java | 3 +- .../observers/BasicFuseableObserverTest.java | 5 +- .../observers/DeferredScalarObserverTest.java | 37 +- .../DisposableLambdaObserverTest.java | 2 +- .../observers/FutureObserverTest.java | 2 +- .../observers/FutureSingleObserverTest.java | 1 + .../observers/LambdaObserverTest.java | 2 +- .../observers/QueueDrainObserverTest.java | 1 + .../completable/CompletableAmbTest.java | 1 + .../CompletableAndThenCompletableabTest.java | 13 +- .../completable/CompletableAndThenTest.java | 5 +- .../completable/CompletableCacheTest.java | 13 +- .../completable/CompletableConcatTest.java | 9 +- .../completable/CompletableCreateTest.java | 1 + .../completable/CompletableDelayTest.java | 5 +- .../completable/CompletableDetachTest.java | 3 +- .../completable/CompletableDisposeOnTest.java | 3 +- .../completable/CompletableDoFinallyTest.java | 3 +- .../completable/CompletableDoOnTest.java | 13 +- .../CompletableFromCallableTest.java | 3 +- .../CompletableFromPublisherTest.java | 1 + .../completable/CompletableHideTest.java | 6 +- .../completable/CompletableLiftTest.java | 1 + .../CompletableMaterializeTest.java | 1 + .../CompletableMergeIterableTest.java | 5 +- .../completable/CompletableMergeTest.java | 23 +- .../completable/CompletableObserveOnTest.java | 1 + .../completable/CompletablePeekTest.java | 1 + .../CompletableResumeNextTest.java | 3 +- .../CompletableSubscribeOnTest.java | 1 + .../completable/CompletableTakeUntilTest.java | 1 + .../completable/CompletableTimeoutTest.java | 10 +- .../completable/CompletableTimerTest.java | 3 +- .../CompletableToFlowableTest.java | 1 + .../CompletableToObservableTest.java | 1 + .../completable/CompletableUnsafeTest.java | 1 + .../completable/CompletableUsingTest.java | 29 +- .../flowable/BlockingFlowableLatestTest.java | 1 + .../BlockingFlowableMostRecentTest.java | 1 + .../flowable/BlockingFlowableNextTest.java | 1 + .../operators/flowable/FlowableAllTest.java | 9 +- .../operators/flowable/FlowableAmbTest.java | 23 +- .../operators/flowable/FlowableAnyTest.java | 11 +- .../flowable/FlowableAsObservableTest.java | 1 + .../flowable/FlowableBlockingTest.java | 7 +- .../flowable/FlowableBufferTest.java | 11 +- .../operators/flowable/FlowableCacheTest.java | 21 +- .../operators/flowable/FlowableCastTest.java | 1 + .../flowable/FlowableCombineLatestTest.java | 15 +- .../FlowableConcatDelayErrorTest.java | 5 +- .../flowable/FlowableConcatMapEagerTest.java | 21 +- .../flowable/FlowableConcatMapTest.java | 1 + .../flowable/FlowableConcatTest.java | 37 +- .../FlowableConcatWithCompletableTest.java | 1 + .../operators/flowable/FlowableCountTest.java | 1 + .../flowable/FlowableCreateTest.java | 27 +- .../flowable/FlowableDebounceTest.java | 7 +- .../flowable/FlowableDefaultIfEmptyTest.java | 10 +- .../operators/flowable/FlowableDeferTest.java | 1 + .../FlowableDelaySubscriptionOtherTest.java | 7 +- .../operators/flowable/FlowableDelayTest.java | 23 +- .../flowable/FlowableDematerializeTest.java | 4 +- .../flowable/FlowableDetachTest.java | 1 + .../flowable/FlowableDistinctTest.java | 12 +- .../FlowableDistinctUntilChangedTest.java | 39 +- .../flowable/FlowableDoAfterNextTest.java | 29 +- .../FlowableDoAfterTerminateTest.java | 1 + .../flowable/FlowableDoFinallyTest.java | 42 +- .../flowable/FlowableDoOnEachTest.java | 63 +- .../flowable/FlowableDoOnLifecycleTest.java | 3 +- .../flowable/FlowableDoOnUnsubscribeTest.java | 6 +- .../flowable/FlowableElementAtTest.java | 3 +- .../flowable/FlowableFilterTest.java | 65 +- .../operators/flowable/FlowableFirstTest.java | 5 +- .../FlowableFlatMapCompletableTest.java | 35 +- .../flowable/FlowableFlatMapMaybeTest.java | 36 +- .../flowable/FlowableFlatMapSingleTest.java | 35 +- .../flowable/FlowableFlatMapTest.java | 39 +- .../flowable/FlowableFlattenIterableTest.java | 17 +- .../flowable/FlowableFromArrayTest.java | 1 + .../flowable/FlowableFromCallableTest.java | 1 + .../flowable/FlowableFromIterableTest.java | 19 +- .../flowable/FlowableFromObservableTest.java | 1 + .../flowable/FlowableFromSourceTest.java | 7 +- .../flowable/FlowableGenerateTest.java | 3 +- .../flowable/FlowableGroupByTest.java | 65 +- .../flowable/FlowableGroupJoinTest.java | 9 +- .../operators/flowable/FlowableHideTest.java | 1 + .../flowable/FlowableIgnoreElementsTest.java | 15 +- .../flowable/FlowableInternalHelperTest.java | 2 +- .../flowable/FlowableIntervalRangeTest.java | 1 + .../flowable/FlowableIntervalTest.java | 1 + .../operators/flowable/FlowableJoinTest.java | 9 +- .../operators/flowable/FlowableLastTest.java | 3 +- .../operators/flowable/FlowableLiftTest.java | 1 + .../operators/flowable/FlowableLimitTest.java | 1 + .../flowable/FlowableMapNotificationTest.java | 7 +- .../operators/flowable/FlowableMapTest.java | 40 +- .../flowable/FlowableMaterializeTest.java | 5 +- .../flowable/FlowableMergeDelayErrorTest.java | 19 +- .../FlowableMergeMaxConcurrentTest.java | 17 +- .../operators/flowable/FlowableMergeTest.java | 91 +- .../FlowableMergeWithCompletableTest.java | 1 + .../flowable/FlowableMergeWithMaybeTest.java | 1 + .../flowable/FlowableMergeWithSingleTest.java | 1 + .../flowable/FlowableObserveOnTest.java | 111 +- ...wableOnBackpressureBufferStrategyTest.java | 6 +- .../FlowableOnBackpressureBufferTest.java | 23 +- .../FlowableOnBackpressureDropTest.java | 9 +- .../FlowableOnBackpressureErrorTest.java | 1 + .../FlowableOnBackpressureLatestTest.java | 13 +- ...wableOnErrorResumeNextViaFlowableTest.java | 12 +- ...wableOnErrorResumeNextViaFunctionTest.java | 12 +- .../flowable/FlowableOnErrorReturnTest.java | 11 +- ...eOnExceptionResumeNextViaFlowableTest.java | 8 +- .../flowable/FlowablePublishFunctionTest.java | 7 +- .../FlowablePublishMulticastTest.java | 2 +- .../flowable/FlowablePublishTest.java | 55 +- .../flowable/FlowableRangeLongTest.java | 23 +- .../operators/flowable/FlowableRangeTest.java | 27 +- .../flowable/FlowableReduceTest.java | 3 +- .../FlowableReduceWithSingleTest.java | 1 + .../flowable/FlowableRefCountTest.java | 30 +- .../flowable/FlowableRepeatTest.java | 11 +- .../flowable/FlowableReplayTest.java | 67 +- .../operators/flowable/FlowableRetryTest.java | 17 +- .../FlowableRetryWithPredicateTest.java | 17 +- .../flowable/FlowableSampleTest.java | 1 + .../flowable/FlowableScalarXMapTest.java | 1 + .../operators/flowable/FlowableScanTest.java | 7 +- .../flowable/FlowableSequenceEqualTest.java | 9 +- .../flowable/FlowableSerializeTest.java | 1 + .../flowable/FlowableSingleTest.java | 3 +- .../flowable/FlowableSkipLastTest.java | 9 +- .../flowable/FlowableSkipLastTimedTest.java | 3 +- .../operators/flowable/FlowableSkipTest.java | 10 +- .../flowable/FlowableSkipTimedTest.java | 1 + .../flowable/FlowableSkipUntilTest.java | 1 + .../flowable/FlowableSkipWhileTest.java | 1 + .../flowable/FlowableSubscribeOnTest.java | 33 +- .../flowable/FlowableSwitchIfEmptyTest.java | 2 +- .../flowable/FlowableSwitchTest.java | 35 +- .../flowable/FlowableTakeLastOneTest.java | 11 +- .../flowable/FlowableTakeLastTest.java | 10 +- .../flowable/FlowableTakeLastTimedTest.java | 3 +- .../operators/flowable/FlowableTakeTest.java | 5 +- .../flowable/FlowableTakeTimedTest.java | 1 + .../FlowableTakeUntilPredicateTest.java | 5 +- .../flowable/FlowableTakeUntilTest.java | 11 +- .../flowable/FlowableTakeWhileTest.java | 5 +- .../flowable/FlowableThrottleFirstTest.java | 1 + .../flowable/FlowableThrottleLatestTest.java | 1 + .../flowable/FlowableTimeIntervalTest.java | 1 + .../flowable/FlowableTimeoutTests.java | 39 +- .../FlowableTimeoutWithSelectorTest.java | 11 +- .../operators/flowable/FlowableTimerTest.java | 17 +- .../flowable/FlowableTimestampTest.java | 1 + .../flowable/FlowableToCompletableTest.java | 3 +- .../flowable/FlowableToFutureTest.java | 11 +- .../flowable/FlowableToListTest.java | 17 +- .../operators/flowable/FlowableToMapTest.java | 1 + .../flowable/FlowableToMultimapTest.java | 1 + .../flowable/FlowableToSortedListTest.java | 10 +- .../flowable/FlowableUnsubscribeOnTest.java | 14 +- .../operators/flowable/FlowableUsingTest.java | 15 +- .../FlowableWindowWithFlowableTest.java | 35 +- .../flowable/FlowableWindowWithSizeTest.java | 26 +- ...lowableWindowWithStartEndFlowableTest.java | 7 +- .../flowable/FlowableWindowWithTimeTest.java | 9 +- .../flowable/FlowableWithLatestFromTest.java | 25 +- .../flowable/FlowableZipCompletionTest.java | 1 + .../flowable/FlowableZipIterableTest.java | 3 +- .../operators/flowable/FlowableZipTest.java | 53 +- .../flowable/NotificationLiteTest.java | 2 +- .../operators/maybe/MaybeAmbTest.java | 3 +- .../operators/maybe/MaybeCacheTest.java | 5 +- .../maybe/MaybeCallbackObserverTest.java | 3 +- .../operators/maybe/MaybeConcatArrayTest.java | 1 + .../maybe/MaybeConcatIterableTest.java | 7 +- .../operators/maybe/MaybeContainsTest.java | 3 +- .../operators/maybe/MaybeCountTest.java | 3 +- .../operators/maybe/MaybeCreateTest.java | 1 + .../operators/maybe/MaybeDelayOtherTest.java | 21 +- .../maybe/MaybeDelaySubscriptionTest.java | 1 + .../operators/maybe/MaybeDelayTest.java | 5 +- .../operators/maybe/MaybeDetachTest.java | 3 +- .../maybe/MaybeDoAfterSuccessTest.java | 1 + .../operators/maybe/MaybeDoFinallyTest.java | 5 +- .../operators/maybe/MaybeDoOnEventTest.java | 3 +- .../maybe/MaybeDoOnTerminateTest.java | 19 +- .../operators/maybe/MaybeEqualTest.java | 1 + .../maybe/MaybeFilterSingleTest.java | 1 + .../maybe/MaybeFlatMapBiSelectorTest.java | 3 +- .../maybe/MaybeFlatMapCompletableTest.java | 1 + .../MaybeFlatMapIterableFlowableTest.java | 39 +- .../MaybeFlatMapIterableObservableTest.java | 32 +- .../maybe/MaybeFlatMapNotificationTest.java | 6 +- .../maybe/MaybeFlatMapSingleElementTest.java | 5 +- .../maybe/MaybeFlatMapSingleTest.java | 5 +- .../operators/maybe/MaybeFlattenTest.java | 1 + .../operators/maybe/MaybeFromActionTest.java | 3 +- .../maybe/MaybeFromCallableTest.java | 5 +- .../maybe/MaybeFromCompletableTest.java | 1 + .../operators/maybe/MaybeFromFutureTest.java | 4 +- .../maybe/MaybeFromRunnableTest.java | 3 +- .../operators/maybe/MaybeFromSingleTest.java | 1 + .../operators/maybe/MaybeHideTest.java | 1 + .../maybe/MaybeIgnoreElementTest.java | 1 + .../operators/maybe/MaybeIsEmptyTest.java | 1 + .../operators/maybe/MaybeMapTest.java | 1 + .../operators/maybe/MaybeMaterializeTest.java | 1 + .../operators/maybe/MaybeMergeArrayTest.java | 21 +- .../operators/maybe/MaybeMergeTest.java | 3 +- .../operators/maybe/MaybeOfTypeTest.java | 1 + .../operators/maybe/MaybeOnErrorXTest.java | 9 +- .../operators/maybe/MaybePeekTest.java | 9 +- .../operators/maybe/MaybeSubscribeOnTest.java | 1 + .../maybe/MaybeSwitchIfEmptySingleTest.java | 5 +- .../maybe/MaybeSwitchIfEmptyTest.java | 5 +- .../maybe/MaybeTakeUntilPublisherTest.java | 1 + .../operators/maybe/MaybeTakeUntilTest.java | 1 + .../maybe/MaybeTimeoutPublisherTest.java | 5 +- .../operators/maybe/MaybeTimeoutTest.java | 5 +- .../operators/maybe/MaybeTimerTest.java | 3 +- .../maybe/MaybeToCompletableTest.java | 1 + .../operators/maybe/MaybeToFlowableTest.java | 1 + .../maybe/MaybeToObservableTest.java | 1 + .../operators/maybe/MaybeToSingleTest.java | 1 + .../maybe/MaybeUnsubscribeOnTest.java | 1 + .../operators/maybe/MaybeUsingTest.java | 21 +- .../operators/maybe/MaybeZipArrayTest.java | 5 +- .../operators/maybe/MaybeZipIterableTest.java | 13 +- .../CompletableAndThenObservableTest.java | 5 +- .../CompletableAndThenPublisherTest.java | 1 + .../FlowableConcatMapCompletableTest.java | 16 +- .../mixed/FlowableConcatMapMaybeTest.java | 39 +- .../mixed/FlowableConcatMapSingleTest.java | 24 +- .../FlowableSwitchMapCompletableTest.java | 5 +- .../mixed/FlowableSwitchMapMaybeTest.java | 13 +- .../mixed/FlowableSwitchMapSingleTest.java | 13 +- .../mixed/MaybeFlatMapObservableTest.java | 5 +- .../mixed/MaybeFlatMapPublisherTest.java | 1 + .../ObservableConcatMapCompletableTest.java | 16 +- .../mixed/ObservableConcatMapMaybeTest.java | 41 +- .../mixed/ObservableConcatMapSingleTest.java | 26 +- .../ObservableSwitchMapCompletableTest.java | 5 +- .../mixed/ObservableSwitchMapMaybeTest.java | 21 +- .../mixed/ObservableSwitchMapSingleTest.java | 21 +- .../mixed/ScalarXMapZHelperTest.java | 2 +- .../mixed/SingleFlatMapObservableTest.java | 5 +- .../BlockingObservableLatestTest.java | 2 +- .../BlockingObservableNextTest.java | 1 + .../observable/ObservableAllTest.java | 6 +- .../observable/ObservableAmbTest.java | 11 +- .../observable/ObservableAnyTest.java | 8 +- .../observable/ObservableBlockingTest.java | 2 +- .../observable/ObservableBufferTest.java | 11 +- .../observable/ObservableCacheTest.java | 15 +- .../observable/ObservableCastTest.java | 1 + .../observable/ObservableCollectTest.java | 1 + .../ObservableCombineLatestTest.java | 13 +- .../ObservableConcatMapCompletableTest.java | 1 + .../ObservableConcatMapEagerTest.java | 25 +- .../observable/ObservableConcatMapTest.java | 1 + .../observable/ObservableConcatTest.java | 19 +- .../ObservableConcatWithCompletableTest.java | 2 +- .../ObservableConcatWithMaybeTest.java | 2 +- .../ObservableConcatWithSingleTest.java | 2 +- .../observable/ObservableCountTest.java | 1 + .../observable/ObservableCreateTest.java | 23 +- .../observable/ObservableDebounceTest.java | 10 +- .../ObservableDefaultIfEmptyTest.java | 1 + .../observable/ObservableDeferTest.java | 1 + .../ObservableDelaySubscriptionOtherTest.java | 3 +- .../observable/ObservableDelayTest.java | 19 +- .../ObservableDematerializeTest.java | 4 +- .../observable/ObservableDetachTest.java | 3 +- .../observable/ObservableDistinctTest.java | 13 +- .../ObservableDistinctUntilChangedTest.java | 17 +- .../observable/ObservableDoAfterNextTest.java | 26 +- .../observable/ObservableDoFinallyTest.java | 47 +- .../observable/ObservableDoOnEachTest.java | 51 +- .../ObservableDoOnSubscribeTest.java | 3 +- .../observable/ObservableElementAtTest.java | 3 +- .../observable/ObservableFilterTest.java | 16 +- .../observable/ObservableFinallyTest.java | 1 + .../observable/ObservableFirstTest.java | 5 +- .../ObservableFlatMapCompletableTest.java | 31 +- .../ObservableFlatMapMaybeTest.java | 26 +- .../ObservableFlatMapSingleTest.java | 27 +- .../observable/ObservableFlatMapTest.java | 43 +- .../ObservableFlattenIterableTest.java | 2 +- .../observable/ObservableForEachTest.java | 2 +- .../ObservableFromCallableTest.java | 7 +- .../ObservableFromIterableTest.java | 15 +- .../observable/ObservableFromTest.java | 6 +- .../observable/ObservableGenerateTest.java | 1 + .../observable/ObservableGroupByTest.java | 43 +- .../observable/ObservableGroupJoinTest.java | 11 +- .../observable/ObservableHideTest.java | 1 + .../ObservableIgnoreElementsTest.java | 17 +- .../ObservableInternalHelperTest.java | 2 +- .../ObservableIntervalRangeTest.java | 1 + .../observable/ObservableIntervalTest.java | 1 + .../observable/ObservableJoinTest.java | 7 +- .../observable/ObservableLastTest.java | 3 +- .../ObservableMapNotificationTest.java | 5 +- .../observable/ObservableMapTest.java | 18 +- .../observable/ObservableMaterializeTest.java | 5 +- .../ObservableMergeDelayErrorTest.java | 16 +- .../ObservableMergeMaxConcurrentTest.java | 13 +- .../observable/ObservableMergeTest.java | 72 +- .../ObservableMergeWithCompletableTest.java | 3 +- .../ObservableMergeWithMaybeTest.java | 3 +- .../ObservableMergeWithSingleTest.java | 3 +- .../observable/ObservableObserveOnTest.java | 31 +- ...vableOnErrorResumeNextViaFunctionTest.java | 12 +- ...bleOnErrorResumeNextViaObservableTest.java | 10 +- .../ObservableOnErrorReturnTest.java | 9 +- ...nExceptionResumeNextViaObservableTest.java | 6 +- .../observable/ObservablePublishTest.java | 37 +- .../observable/ObservableRangeLongTest.java | 13 +- .../observable/ObservableRangeTest.java | 7 +- .../observable/ObservableRedoTest.java | 2 +- .../observable/ObservableReduceTest.java | 1 + .../observable/ObservableRefCountTest.java | 25 +- .../observable/ObservableRepeatTest.java | 7 +- .../observable/ObservableReplayTest.java | 47 +- .../ObservableResourceWrapperTest.java | 2 +- .../observable/ObservableRetryTest.java | 11 +- .../ObservableRetryWithPredicateTest.java | 21 +- .../observable/ObservableSampleTest.java | 1 + .../observable/ObservableScalarXMapTest.java | 1 + .../observable/ObservableScanTest.java | 7 +- .../ObservableSequenceEqualTest.java | 5 +- .../observable/ObservableSerializeTest.java | 1 + .../observable/ObservableSingleTest.java | 3 +- .../observable/ObservableSkipLastTest.java | 6 +- .../ObservableSkipLastTimedTest.java | 3 +- .../observable/ObservableSkipTest.java | 7 +- .../observable/ObservableSkipTimedTest.java | 1 + .../observable/ObservableSkipUntilTest.java | 1 + .../observable/ObservableSkipWhileTest.java | 1 + .../observable/ObservableSubscribeOnTest.java | 15 +- .../observable/ObservableSwitchTest.java | 28 +- .../observable/ObservableTakeLastOneTest.java | 8 +- .../observable/ObservableTakeLastTest.java | 8 +- .../ObservableTakeLastTimedTest.java | 5 +- .../observable/ObservableTakeTest.java | 7 +- .../observable/ObservableTakeTimedTest.java | 1 + .../ObservableTakeUntilPredicateTest.java | 4 +- .../observable/ObservableTakeUntilTest.java | 7 +- .../observable/ObservableTakeWhileTest.java | 6 +- .../ObservableThrottleFirstTest.java | 1 + .../ObservableThrottleLatestTest.java | 1 + .../ObservableTimeIntervalTest.java | 1 + .../observable/ObservableTimeoutTests.java | 19 +- .../ObservableTimeoutWithSelectorTest.java | 11 +- .../observable/ObservableTimerTest.java | 3 +- .../observable/ObservableTimestampTest.java | 1 + .../observable/ObservableToFutureTest.java | 1 + .../observable/ObservableToListTest.java | 5 +- .../observable/ObservableToMapTest.java | 1 + .../observable/ObservableToMultimapTest.java | 1 + .../ObservableToSortedListTest.java | 1 + .../ObservableUnsubscribeOnTest.java | 14 +- .../observable/ObservableUsingTest.java | 19 +- .../ObservableWindowWithObservableTest.java | 43 +- .../ObservableWindowWithSizeTest.java | 35 +- ...vableWindowWithStartEndObservableTest.java | 3 +- .../ObservableWindowWithTimeTest.java | 9 +- .../ObservableWithLatestFromTest.java | 19 +- .../ObservableZipCompletionTest.java | 1 + .../observable/ObservableZipIterableTest.java | 3 +- .../observable/ObservableZipTest.java | 13 +- .../operators/single/SingleAmbTest.java | 1 + .../operators/single/SingleCacheTest.java | 3 +- .../operators/single/SingleConcatTest.java | 6 +- .../operators/single/SingleCreateTest.java | 1 + .../operators/single/SingleDelayTest.java | 1 + .../single/SingleDematerializeTest.java | 1 + .../operators/single/SingleDetachTest.java | 3 +- .../single/SingleDoAfterSuccessTest.java | 1 + .../single/SingleDoAfterTerminateTest.java | 6 +- .../operators/single/SingleDoFinallyTest.java | 3 +- .../single/SingleDoOnTerminateTest.java | 19 +- .../operators/single/SingleDoOnTest.java | 16 +- .../operators/single/SingleEqualsTest.java | 3 +- .../single/SingleFlatMapCompletableTest.java | 1 + .../SingleFlatMapIterableFlowableTest.java | 39 +- .../SingleFlatMapIterableObservableTest.java | 30 +- .../single/SingleFlatMapMaybeTest.java | 5 +- .../operators/single/SingleFlatMapTest.java | 14 +- .../single/SingleFromCallableTest.java | 17 +- .../single/SingleFromPublisherTest.java | 3 +- .../operators/single/SingleHideTest.java | 1 + .../single/SingleInternalHelperTest.java | 1 + .../operators/single/SingleMapTest.java | 5 +- .../single/SingleMaterializeTest.java | 1 + .../operators/single/SingleMergeTest.java | 3 +- .../operators/single/SingleObserveOnTest.java | 1 + .../operators/single/SingleOnErrorXTest.java | 8 +- .../single/SingleSubscribeOnTest.java | 1 + .../operators/single/SingleTakeUntilTest.java | 1 + .../operators/single/SingleTimeoutTest.java | 5 +- .../operators/single/SingleTimerTest.java | 3 +- .../single/SingleToFlowableTest.java | 3 +- .../single/SingleToObservableTest.java | 1 + .../single/SingleUnsubscribeOnTest.java | 1 + .../operators/single/SingleUsingTest.java | 15 +- .../operators/single/SingleZipArrayTest.java | 5 +- .../single/SingleZipIterableTest.java | 11 +- .../schedulers/AbstractDirectTaskTest.java | 2 +- .../schedulers/InstantPeriodicTaskTest.java | 2 +- .../ScheduledDirectPeriodicTaskTest.java | 2 +- .../schedulers/ScheduledRunnableTest.java | 2 +- .../SchedulerMultiWorkerSupportTest.java | 2 +- .../schedulers/SchedulerPoolFactoryTest.java | 2 +- .../schedulers/SchedulerWhenTest.java | 1 + .../schedulers/SingleSchedulerTest.java | 1 + ...asicFuseableConditionalSubscriberTest.java | 2 +- .../BasicFuseableSubscriberTest.java | 2 +- .../subscribers/BlockingSubscriberTest.java | 2 +- .../subscribers/BoundedSubscriberTest.java | 3 +- .../DeferredScalarSubscriberTest.java | 5 +- .../subscribers/EmptyComponentTest.java | 2 +- .../subscribers/FutureSubscriberTest.java | 2 +- .../subscribers/LambdaSubscriberTest.java | 2 + .../subscribers/QueueDrainSubscriberTest.java | 2 +- .../SinglePostCompleteSubscriberTest.java | 2 +- .../subscribers/StrictSubscriberTest.java | 14 +- .../SubscriberResourceWrapperTest.java | 1 + .../ArrayCompositeSubscriptionTest.java | 2 +- .../DeferredScalarSubscriptionTest.java | 6 +- .../subscriptions/QueueSubscriptionTest.java | 3 +- .../subscriptions/ScalarSubscriptionTest.java | 2 +- .../SubscriptionArbiterTest.java | 2 +- .../subscriptions/SubscriptionHelperTest.java | 2 +- .../internal/util/BackpressureHelperTest.java | 2 +- .../internal/util/BlockingHelperTest.java | 2 +- .../internal/util/EndConsumerHelperTest.java | 1 + .../internal/util/ExceptionHelperTest.java | 2 +- .../util/HalfSerializerObserverTest.java | 7 +- .../util/HalfSerializerSubscriberTest.java | 7 +- .../reactivex/internal/util/MiscUtilTest.java | 2 +- .../internal/util/NotificationLiteTest.java | 6 +- .../internal/util/QueueDrainHelperTest.java | 2 +- .../io/reactivex/maybe/MaybeCreateTest.java | 1 + .../java/io/reactivex/maybe/MaybeTest.java | 69 +- .../observable/ObservableCovarianceTest.java | 6 +- .../observable/ObservableFuseableTest.java | 32 +- .../observable/ObservableSubscriberTest.java | 1 + .../reactivex/observable/ObservableTest.java | 5 +- .../ObservableThrottleLastTests.java | 1 + .../ObservableThrottleWithTimeoutTests.java | 1 + .../DisposableCompletableObserverTest.java | 1 + .../DisposableMaybeObserverTest.java | 1 + .../observers/DisposableObserverTest.java | 2 +- .../DisposableSingleObserverTest.java | 1 + .../reactivex/observers/ObserverFusion.java | 177 -- .../ResourceCompletableObserverTest.java | 2 +- .../observers/ResourceMaybeObserverTest.java | 2 +- .../observers/ResourceObserverTest.java | 2 +- .../observers/ResourceSingleObserverTest.java | 2 +- .../reactivex/observers/SafeObserverTest.java | 9 +- .../observers/SerializedObserverTest.java | 18 +- .../reactivex/observers/TestObserverTest.java | 637 +----- .../parallel/ParallelCollectTest.java | 1 + .../parallel/ParallelDoOnNextTryTest.java | 12 +- .../parallel/ParallelFilterTest.java | 1 + .../parallel/ParallelFilterTryTest.java | 12 +- .../parallel/ParallelFlowableTest.java | 46 +- .../parallel/ParallelFromPublisherTest.java | 8 +- .../reactivex/parallel/ParallelJoinTest.java | 7 +- .../reactivex/parallel/ParallelMapTest.java | 1 + .../parallel/ParallelMapTryTest.java | 12 +- .../reactivex/parallel/ParallelPeekTest.java | 1 + .../parallel/ParallelReduceFullTest.java | 1 + .../parallel/ParallelReduceTest.java | 1 + .../reactivex/parallel/ParallelRunOnTest.java | 1 + .../parallel/ParallelSortedJoinTest.java | 1 + .../reactivex/plugins/RxJavaPluginsTest.java | 1 + .../processors/AsyncProcessorTest.java | 22 +- .../processors/BehaviorProcessorTest.java | 7 +- .../processors/MulticastProcessorTest.java | 1 + .../processors/PublishProcessorTest.java | 11 +- ...ReplayProcessorBoundedConcurrencyTest.java | 7 +- .../ReplayProcessorConcurrencyTest.java | 7 +- .../processors/ReplayProcessorTest.java | 5 +- .../processors/SerializedProcessorTest.java | 24 +- .../processors/UnicastProcessorTest.java | 41 +- .../ExecutorSchedulerInterruptibleTest.java | 1 + .../schedulers/ExecutorSchedulerTest.java | 1 + .../reactivex/schedulers/SchedulerTest.java | 1 + .../schedulers/TrampolineSchedulerTest.java | 8 +- .../io/reactivex/single/SingleCacheTest.java | 2 +- .../reactivex/single/SingleSubscribeTest.java | 1 + .../java/io/reactivex/single/SingleTest.java | 21 +- .../reactivex/subjects/AsyncSubjectTest.java | 39 +- .../subjects/BehaviorSubjectTest.java | 5 +- .../subjects/CompletableSubjectTest.java | 5 +- .../reactivex/subjects/MaybeSubjectTest.java | 3 +- .../subjects/PublishSubjectTest.java | 11 +- .../ReplaySubjectBoundedConcurrencyTest.java | 7 +- .../ReplaySubjectConcurrencyTest.java | 7 +- .../reactivex/subjects/ReplaySubjectTest.java | 9 +- .../subjects/SerializedSubjectTest.java | 25 +- .../reactivex/subjects/SingleSubjectTest.java | 7 +- .../io/reactivex/subjects/SubjectTest.java | 4 +- .../subjects/UnicastSubjectTest.java | 47 +- .../subscribers/DisposableSubscriberTest.java | 1 + .../subscribers/ResourceSubscriberTest.java | 1 + .../subscribers/SafeSubscriberTest.java | 8 +- .../subscribers/SerializedSubscriberTest.java | 17 +- .../subscribers/SubscriberFusion.java | 192 -- .../subscribers/TestSubscriberTest.java | 717 +------ .../testsupport/BaseTestConsumerEx.java | 303 +++ .../{ => testsupport}/TestHelper.java | 224 +- .../reactivex/testsupport/TestObserverEx.java | 318 +++ .../testsupport/TestObserverExTest.java | 1383 ++++++++++++ .../testsupport/TestSubscriberEx.java | 387 ++++ .../testsupport/TestSubscriberExTest.java | 1886 +++++++++++++++++ .../CheckLocalVariablesInTests.java | 8 +- .../ParamValidationCheckerTest.java | 1 + 555 files changed, 7467 insertions(+), 4838 deletions(-) delete mode 100644 src/test/java/io/reactivex/observers/ObserverFusion.java delete mode 100644 src/test/java/io/reactivex/subscribers/SubscriberFusion.java create mode 100644 src/test/java/io/reactivex/testsupport/BaseTestConsumerEx.java rename src/test/java/io/reactivex/{ => testsupport}/TestHelper.java (93%) create mode 100644 src/test/java/io/reactivex/testsupport/TestObserverEx.java create mode 100644 src/test/java/io/reactivex/testsupport/TestObserverExTest.java create mode 100644 src/test/java/io/reactivex/testsupport/TestSubscriberEx.java create mode 100644 src/test/java/io/reactivex/testsupport/TestSubscriberExTest.java diff --git a/src/main/java/io/reactivex/Completable.java b/src/main/java/io/reactivex/Completable.java index fdeaaccf91..92de75d97b 100644 --- a/src/main/java/io/reactivex/Completable.java +++ b/src/main/java/io/reactivex/Completable.java @@ -2690,7 +2690,7 @@ public final TestObserver test() { /** * Creates a TestObserver optionally in cancelled state, then subscribes it to this Completable. - * @param cancelled if true, the TestObserver will be cancelled before subscribing to this + * @param dispose if true, the TestObserver will be cancelled before subscribing to this * Completable. *

* @@ -2703,11 +2703,11 @@ public final TestObserver test() { */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - public final TestObserver test(boolean cancelled) { + public final TestObserver test(boolean dispose) { TestObserver to = new TestObserver(); - if (cancelled) { - to.cancel(); + if (dispose) { + to.dispose(); } subscribe(to); return to; diff --git a/src/main/java/io/reactivex/Maybe.java b/src/main/java/io/reactivex/Maybe.java index f5c3085259..5b03dd8184 100644 --- a/src/main/java/io/reactivex/Maybe.java +++ b/src/main/java/io/reactivex/Maybe.java @@ -4700,17 +4700,17 @@ public final TestObserver test() { *

Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
* - * @param cancelled if true, the TestObserver will be cancelled before subscribing to this + * @param dispose if true, the TestObserver will be dispose before subscribing to this * Maybe. * @return the new TestObserver instance */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - public final TestObserver test(boolean cancelled) { + public final TestObserver test(boolean dispose) { TestObserver to = new TestObserver(); - if (cancelled) { - to.cancel(); + if (dispose) { + to.dispose(); } subscribe(to); diff --git a/src/main/java/io/reactivex/Single.java b/src/main/java/io/reactivex/Single.java index 9de155b256..7fa1f5b905 100644 --- a/src/main/java/io/reactivex/Single.java +++ b/src/main/java/io/reactivex/Single.java @@ -4030,18 +4030,18 @@ public final TestObserver test() { *
Scheduler:
*
{@code test} does not operate by default on a particular {@link Scheduler}.
* - * @param cancelled if true, the TestObserver will be cancelled before subscribing to this + * @param dispose if true, the TestObserver will be cancelled before subscribing to this * Single. * @return the new TestObserver instance * @since 2.0 */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) - public final TestObserver test(boolean cancelled) { + public final TestObserver test(boolean dispose) { TestObserver to = new TestObserver(); - if (cancelled) { - to.cancel(); + if (dispose) { + to.dispose(); } subscribe(to); diff --git a/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java b/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java index 20d2332214..ff7b6cced5 100644 --- a/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java +++ b/src/main/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletable.java @@ -84,7 +84,7 @@ static final class NextObserver implements CompletableObserver { final CompletableObserver downstream; - public NextObserver(AtomicReference parent, CompletableObserver downstream) { + NextObserver(AtomicReference parent, CompletableObserver downstream) { this.parent = parent; this.downstream = downstream; } diff --git a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java index 6dac8e3ac1..2ac2aea951 100644 --- a/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/flowable/FlowablePublish.java @@ -61,6 +61,7 @@ public Publisher source() { } /** + * The internal buffer size of this FloawblePublishAlt operator. * @return The internal buffer size of this FloawblePublishAlt operator. */ public int publishBufferSize() { diff --git a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java index 932f0b1468..dc5358021e 100644 --- a/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java +++ b/src/main/java/io/reactivex/internal/operators/observable/ObservablePublish.java @@ -149,7 +149,7 @@ static final class PublishConnection Throwable error; @SuppressWarnings("unchecked") - public PublishConnection(AtomicReference> current) { + PublishConnection(AtomicReference> current) { this.connect = new AtomicBoolean(); this.current = current; this.upstream = new AtomicReference(); @@ -268,7 +268,7 @@ static final class InnerDisposable final Observer downstream; - public InnerDisposable(Observer downstream, PublishConnection parent) { + InnerDisposable(Observer downstream, PublishConnection parent) { this.downstream = downstream; lazySet(parent); } diff --git a/src/main/java/io/reactivex/observers/BaseTestConsumer.java b/src/main/java/io/reactivex/observers/BaseTestConsumer.java index 8560830919..958c0063af 100644 --- a/src/main/java/io/reactivex/observers/BaseTestConsumer.java +++ b/src/main/java/io/reactivex/observers/BaseTestConsumer.java @@ -16,8 +16,6 @@ import java.util.*; import java.util.concurrent.*; -import io.reactivex.Notification; -import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Predicate; import io.reactivex.internal.functions.*; @@ -28,7 +26,7 @@ * @param the value type consumed * @param the subclass of this BaseTestConsumer */ -public abstract class BaseTestConsumer> implements Disposable { +public abstract class BaseTestConsumer> { /** The latch that indicates an onError or onComplete has been called. */ protected final CountDownLatch done; /** The list of values received. */ @@ -42,10 +40,6 @@ public abstract class BaseTestConsumer> impl protected boolean checkSubscriptionOnce; - protected int initialFusionMode; - - protected int establishedFusionMode; - /** * The optional tag associated with this test consumer. * @since 2.0.7 @@ -64,14 +58,6 @@ public BaseTestConsumer() { this.done = new CountDownLatch(1); } - /** - * Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber. - * @return the last thread which called the onXXX methods - */ - public final Thread lastThread() { - return lastThread; - } - /** * Returns a shared list of received onNext values. *

@@ -94,60 +80,6 @@ public final List values() { return values; } - /** - * Returns a shared list of received onError exceptions. - *

- * Note that accessing the errors via certain methods of the {@link List} - * interface while the upstream is still actively emitting - * more items or errors may result in a {@code ConcurrentModificationException}. - *

- * The {@link List#size()} method will return the number of errors - * already received by this TestObserver/TestSubscriber in a thread-safe - * manner that can be read via {@link List#get(int)}) method - * (index range of 0 to {@code List.size() - 1}). - *

- * A view of the returned List can be created via {@link List#subList(int, int)} - * by using the bounds 0 (inclusive) to {@link List#size()} (exclusive) which, - * when accessed in a read-only fashion, should be also thread-safe and not throw any - * {@code ConcurrentModificationException}. - * @return a list of received events onError exceptions - */ - public final List errors() { - return errors; - } - - /** - * Returns the number of times onComplete was called. - * @return the number of times onComplete was called - */ - public final long completions() { - return completions; - } - - /** - * Returns true if TestObserver/TestSubscriber received any onError or onComplete events. - * @return true if TestObserver/TestSubscriber received any onError or onComplete events - */ - public final boolean isTerminated() { - return done.getCount() == 0; - } - - /** - * Returns the number of onNext values received. - * @return the number of onNext values received - */ - public final int valueCount() { - return values.size(); - } - - /** - * Returns the number of onError exceptions received. - * @return the number of onError exceptions received - */ - public final int errorCount() { - return errors.size(); - } - /** * Fail with the given message and add the sequence of errors as suppressed ones. *

Note this is deliberately the only fail method. Most of the times an assertion @@ -202,7 +134,6 @@ protected final AssertionError fail(String message) { * Awaits until this TestObserver/TestSubscriber receives an onError or onComplete events. * @return this * @throws InterruptedException if the current thread is interrupted while waiting - * @see #awaitTerminalEvent() */ @SuppressWarnings("unchecked") public final U await() throws InterruptedException { @@ -221,7 +152,6 @@ public final U await() throws InterruptedException { * @param unit the time unit of the waiting time * @return true if the TestObserver/TestSubscriber terminated, false if timeout happened * @throws InterruptedException if the current thread is interrupted while waiting - * @see #awaitTerminalEvent(long, TimeUnit) */ public final boolean await(long time, TimeUnit unit) throws InterruptedException { boolean d = done.getCount() == 0 || (done.await(time, unit)); @@ -360,28 +290,6 @@ public final U assertValue(T value) { return (U)this; } - /** - * Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to - * the given value with respect to null-safe Object.equals. - * - *

History: 2.0.5 - experimental - * @param value the value to expect not being received - * @return this - * @since 2.1 - */ - @SuppressWarnings("unchecked") - public final U assertNever(T value) { - int s = values.size(); - - for (int i = 0; i < s; i++) { - T v = this.values.get(i); - if (ObjectHelper.equals(v, value)) { - throw fail("Value at position " + i + " is equal to " + valueAndClass(value) + "; Expected them to be different"); - } - } - return (U) this; - } - /** * Asserts that this TestObserver/TestSubscriber received exactly one onNext value for which * the provided predicate returns true. @@ -401,33 +309,6 @@ public final U assertValue(Predicate valuePredicate) { return (U)this; } - /** - * Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which - * the provided predicate returns true. - * - *

History: 2.0.5 - experimental - * @param valuePredicate the predicate that receives the onNext value - * and should return true for the expected value. - * @return this - * @since 2.1 - */ - @SuppressWarnings("unchecked") - public final U assertNever(Predicate valuePredicate) { - int s = values.size(); - - for (int i = 0; i < s; i++) { - T v = this.values.get(i); - try { - if (valuePredicate.test(v)) { - throw fail("Value at position " + i + " matches predicate " + valuePredicate.toString() + ", which was not expected."); - } - } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); - } - } - return (U)this; - } - /** * Asserts that this TestObserver/TestSubscriber received an onNext value at the given index * which is equal to the given value with respect to null-safe Object.equals. @@ -529,7 +410,6 @@ public final U assertNoValues() { * Assert that the TestObserver/TestSubscriber received only the specified values in the specified order. * @param values the values expected * @return this - * @see #assertValueSet(Collection) */ @SuppressWarnings("unchecked") public final U assertValues(T... values) { @@ -555,7 +435,6 @@ public final U assertValues(T... values) { * @return this * @since 2.2 */ - @SuppressWarnings("unchecked") public final U assertValuesOnly(T... values) { return assertSubscribed() .assertValues(values) @@ -563,47 +442,6 @@ public final U assertValuesOnly(T... values) { .assertNotComplete(); } - /** - * Assert that the TestObserver/TestSubscriber received only items that are in the specified - * collection as well, irrespective of the order they were received. - *

- * This helps asserting when the order of the values is not guaranteed, i.e., when merging - * asynchronous streams. - *

- * To ensure that only the expected items have been received, no more and no less, in any order, - * apply {@link #assertValueCount(int)} with {@code expected.size()}. - * - * @param expected the collection of values expected in any order - * @return this - */ - @SuppressWarnings("unchecked") - public final U assertValueSet(Collection expected) { - if (expected.isEmpty()) { - assertNoValues(); - return (U)this; - } - for (T v : this.values) { - if (!expected.contains(v)) { - throw fail("Value not in the expected collection: " + valueAndClass(v)); - } - } - return (U)this; - } - - /** - * Assert that the TestObserver/TestSubscriber received only the specified values in any order without terminating. - *

History: 2.1.14 - experimental - * @param expected the collection of values expected in any order - * @return this - * @since 2.2 - */ - public final U assertValueSetOnly(Collection expected) { - return assertSubscribed() - .assertValueSet(expected) - .assertNoErrors() - .assertNotComplete(); - } - /** * Assert that the TestObserver/TestSubscriber received only the specified sequence of values in the same order. * @param sequence the sequence of expected values in order @@ -642,145 +480,11 @@ public final U assertValueSequence(Iterable sequence) { return (U)this; } - /** - * Assert that the TestObserver/TestSubscriber received only the specified values in the specified order without terminating. - *

History: 2.1.14 - experimental - * @param sequence the sequence of expected values in order - * @return this - * @since 2.2 - */ - public final U assertValueSequenceOnly(Iterable sequence) { - return assertSubscribed() - .assertValueSequence(sequence) - .assertNoErrors() - .assertNotComplete(); - } - - /** - * Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero). - * @return this - */ - @SuppressWarnings("unchecked") - public final U assertTerminated() { - if (done.getCount() != 0) { - throw fail("Subscriber still running!"); - } - long c = completions; - if (c > 1) { - throw fail("Terminated with multiple completions: " + c); - } - int s = errors.size(); - if (s > 1) { - throw fail("Terminated with multiple errors: " + s); - } - - if (c != 0 && s != 0) { - throw fail("Terminated with multiple completions and errors: " + c); - } - return (U)this; - } - - /** - * Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero). - * @return this - */ - @SuppressWarnings("unchecked") - public final U assertNotTerminated() { - if (done.getCount() == 0) { - throw fail("Subscriber terminated!"); - } - return (U)this; - } - - /** - * Waits until the any terminal event has been received by this TestObserver/TestSubscriber - * or returns false if the wait has been interrupted. - * @return true if the TestObserver/TestSubscriber terminated, false if the wait has been interrupted - */ - public final boolean awaitTerminalEvent() { - try { - await(); - return true; - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - return false; - } - } - - /** - * Awaits the specified amount of time or until this TestObserver/TestSubscriber - * receives an onError or onComplete events, whichever happens first. - * @param duration the waiting time - * @param unit the time unit of the waiting time - * @return true if the TestObserver/TestSubscriber terminated, false if timeout or interrupt happened - */ - public final boolean awaitTerminalEvent(long duration, TimeUnit unit) { - try { - return await(duration, unit); - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - return false; - } - } - - /** - * Assert that there is a single error and it has the given message. - * @param message the message expected - * @return this - */ - @SuppressWarnings("unchecked") - public final U assertErrorMessage(String message) { - int s = errors.size(); - if (s == 0) { - throw fail("No errors"); - } else - if (s == 1) { - Throwable e = errors.get(0); - String errorMessage = e.getMessage(); - if (!ObjectHelper.equals(message, errorMessage)) { - throw fail("Error message differs; exptected: " + message + " but was: " + errorMessage); - } - } else { - throw fail("Multiple errors"); - } - return (U)this; - } - - /** - * Returns a list of 3 other lists: the first inner list contains the plain - * values received; the second list contains the potential errors - * and the final list contains the potential completions as Notifications. - * - * @return a list of (values, errors, completion-notifications) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - public final List> getEvents() { - List> result = new ArrayList>(); - - result.add((List)values()); - - result.add((List)errors()); - - List completeList = new ArrayList(); - for (long i = 0; i < completions; i++) { - completeList.add(Notification.createOnComplete()); - } - result.add(completeList); - - return result; - } - /** * Assert that the onSubscribe method was called exactly once. * @return this */ - public abstract U assertSubscribed(); - - /** - * Assert that the onSubscribe method hasn't been called at all. - * @return this - */ - public abstract U assertNotSubscribed(); + protected abstract U assertSubscribed(); /** * Assert that the upstream signalled the specified values in order and @@ -788,8 +492,6 @@ public final List> getEvents() { * @param values the expected values, asserted in order * @return this * @see #assertFailure(Class, Object...) - * @see #assertFailure(Predicate, Object...) - * @see #assertFailureAndMessage(Class, String, Object...) */ public final U assertResult(T... values) { return assertSubscribed() @@ -812,40 +514,6 @@ public final U assertFailure(Class error, T... values) { .assertNotComplete(); } - /** - * Assert that the upstream signalled the specified values in order and then failed - * with a Throwable for which the provided predicate returns true. - * @param errorPredicate - * the predicate that receives the error Throwable - * and should return true for expected errors. - * @param values the expected values, asserted in order - * @return this - */ - public final U assertFailure(Predicate errorPredicate, T... values) { - return assertSubscribed() - .assertValues(values) - .assertError(errorPredicate) - .assertNotComplete(); - } - - /** - * Assert that the upstream signalled the specified values in order, - * then failed with a specific class or subclass of Throwable - * and with the given exact error message. - * @param error the expected exception (parent) class - * @param message the expected failure message - * @param values the expected values, asserted in order - * @return this - */ - public final U assertFailureAndMessage(Class error, - String message, T... values) { - return assertSubscribed() - .assertValues(values) - .assertError(error) - .assertErrorMessage(message) - .assertNotComplete(); - } - /** * Awaits until the internal latch is counted down. *

If the wait times out or gets interrupted, the TestObserver/TestSubscriber is cancelled. @@ -893,69 +561,6 @@ public final U withTag(CharSequence tag) { return (U)this; } - /** - * Enumeration of default wait strategies when waiting for a specific number of - * items in {@link BaseTestConsumer#awaitCount(int, Runnable)}. - *

History: 2.0.7 - experimental - * @since 2.1 - */ - public enum TestWaitStrategy implements Runnable { - /** The wait loop will spin as fast as possible. */ - SPIN { - @Override - public void run() { - // nothing to do - } - }, - /** The current thread will be yielded. */ - YIELD { - @Override - public void run() { - Thread.yield(); - } - }, - /** The current thread sleeps for 1 millisecond. */ - SLEEP_1MS { - @Override - public void run() { - sleep(1); - } - }, - /** The current thread sleeps for 10 milliseconds. */ - SLEEP_10MS { - @Override - public void run() { - sleep(10); - } - }, - /** The current thread sleeps for 100 milliseconds. */ - SLEEP_100MS { - @Override - public void run() { - sleep(100); - } - }, - /** The current thread sleeps for 1000 milliseconds. */ - SLEEP_1000MS { - @Override - public void run() { - sleep(1000); - } - } - ; - - @Override - public abstract void run(); - - static void sleep(int millis) { - try { - Thread.sleep(millis); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - } - } - /** * Await until the TestObserver/TestSubscriber receives the given * number of items or terminates by sleeping 10 milliseconds at a time @@ -963,50 +568,14 @@ static void sleep(int millis) { *

History: 2.0.7 - experimental * @param atLeast the number of items expected at least * @return this - * @see #awaitCount(int, Runnable, long) - * @since 2.1 - */ - public final U awaitCount(int atLeast) { - return awaitCount(atLeast, TestWaitStrategy.SLEEP_10MS, 5000); - } - - /** - * Await until the TestObserver/TestSubscriber receives the given - * number of items or terminates by waiting according to the wait - * strategy and up to 5000 milliseconds of timeout. - *

History: 2.0.7 - experimental - * @param atLeast the number of items expected at least - * @param waitStrategy a Runnable called when the current received count - * hasn't reached the expected value and there was - * no terminal event either, see {@link TestWaitStrategy} - * for examples - * @return this - * @see #awaitCount(int, Runnable, long) - * @since 2.1 - */ - public final U awaitCount(int atLeast, Runnable waitStrategy) { - return awaitCount(atLeast, waitStrategy, 5000); - } - - /** - * Await until the TestObserver/TestSubscriber receives the given - * number of items or terminates. - *

History: 2.0.7 - experimental - * @param atLeast the number of items expected at least - * @param waitStrategy a Runnable called when the current received count - * hasn't reached the expected value and there was - * no terminal event either, see {@link TestWaitStrategy} - * for examples - * @param timeoutMillis if positive, the await ends if the specified amount of - * time has passed no matter how many items were received - * @return this * @since 2.1 */ @SuppressWarnings("unchecked") - public final U awaitCount(int atLeast, Runnable waitStrategy, long timeoutMillis) { + public final U awaitCount(int atLeast) { long start = System.currentTimeMillis(); + long timeoutMillis = 5000; for (;;) { - if (timeoutMillis > 0L && System.currentTimeMillis() - start >= timeoutMillis) { + if (System.currentTimeMillis() - start >= timeoutMillis) { timeout = true; break; } @@ -1017,62 +586,23 @@ public final U awaitCount(int atLeast, Runnable waitStrategy, long timeoutMillis break; } - waitStrategy.run(); + try { + Thread.sleep(10); + } catch (InterruptedException ex) { + throw new RuntimeException(ex); + } } return (U)this; } /** - * Returns true if an await timed out. - * @return true if one of the timeout-based await methods has timed out. - *

History: 2.0.7 - experimental - * @see #clearTimeout() - * @see #assertTimeout() - * @see #assertNoTimeout() - * @since 2.1 - */ - public final boolean isTimeout() { - return timeout; - } - - /** - * Clears the timeout flag set by the await methods when they timed out. - *

History: 2.0.7 - experimental - * @return this - * @since 2.1 - * @see #isTimeout() - */ - @SuppressWarnings("unchecked") - public final U clearTimeout() { - timeout = false; - return (U)this; - } - - /** - * Asserts that some awaitX method has timed out. - *

History: 2.0.7 - experimental - * @return this - * @since 2.1 + * Returns true if this test consumer was cancelled/disposed. + * @return true if this test consumer was cancelled/disposed. */ - @SuppressWarnings("unchecked") - public final U assertTimeout() { - if (!timeout) { - throw fail("No timeout?!"); - } - return (U)this; - } + protected abstract boolean isDisposed(); /** - * Asserts that some awaitX method has not timed out. - *

History: 2.0.7 - experimental - * @return this - * @since 2.1 + * Cancel/dispose this test consumer. */ - @SuppressWarnings("unchecked") - public final U assertNoTimeout() { - if (timeout) { - throw fail("Timeout?!"); - } - return (U)this; - } + protected abstract void dispose(); } diff --git a/src/main/java/io/reactivex/observers/TestObserver.java b/src/main/java/io/reactivex/observers/TestObserver.java index 3909059b27..296d738afe 100644 --- a/src/main/java/io/reactivex/observers/TestObserver.java +++ b/src/main/java/io/reactivex/observers/TestObserver.java @@ -16,10 +16,7 @@ import io.reactivex.*; import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; import io.reactivex.internal.disposables.DisposableHelper; -import io.reactivex.internal.fuseable.*; -import io.reactivex.internal.util.ExceptionHelper; /** * An Observer that records events and allows making assertions about them. @@ -40,8 +37,6 @@ public class TestObserver /** Holds the current subscription if any. */ private final AtomicReference upstream = new AtomicReference(); - private QueueDisposable qd; - /** * Constructs a non-forwarding TestObserver. * @param the value type received @@ -76,7 +71,6 @@ public TestObserver(Observer downstream) { this.downstream = downstream; } - @SuppressWarnings("unchecked") @Override public void onSubscribe(Disposable d) { lastThread = Thread.currentThread(); @@ -93,33 +87,6 @@ public void onSubscribe(Disposable d) { return; } - if (initialFusionMode != 0) { - if (d instanceof QueueDisposable) { - qd = (QueueDisposable)d; - - int m = qd.requestFusion(initialFusionMode); - establishedFusionMode = m; - - if (m == QueueDisposable.SYNC) { - checkSubscriptionOnce = true; - lastThread = Thread.currentThread(); - try { - T t; - while ((t = qd.poll()) != null) { - values.add(t); - } - completions++; - - upstream.lazySet(DisposableHelper.DISPOSED); - } catch (Throwable ex) { - // Exceptions.throwIfFatal(e); TODO add fatal exceptions? - errors.add(ex); - } - return; - } - } - } - downstream.onSubscribe(d); } @@ -134,19 +101,6 @@ public void onNext(T t) { lastThread = Thread.currentThread(); - if (establishedFusionMode == QueueDisposable.ASYNC) { - try { - while ((t = qd.poll()) != null) { - values.add(t); - } - } catch (Throwable ex) { - // Exceptions.throwIfFatal(e); TODO add fatal exceptions? - errors.add(ex); - qd.dispose(); - } - return; - } - values.add(t); if (t == null) { @@ -198,23 +152,6 @@ public void onComplete() { } } - /** - * Returns true if this TestObserver has been cancelled. - * @return true if this TestObserver has been cancelled - */ - public final boolean isCancelled() { - return isDisposed(); - } - - /** - * Cancels the TestObserver (before or after the subscription happened). - *

This operation is thread-safe. - *

This method is provided as a convenience when converting Flowable tests that cancel. - */ - public final void cancel() { - dispose(); - } - @Override public final void dispose() { DisposableHelper.dispose(upstream); @@ -239,109 +176,13 @@ public final boolean hasSubscription() { * @return this; */ @Override - public final TestObserver assertSubscribed() { + protected final TestObserver assertSubscribed() { if (upstream.get() == null) { throw fail("Not subscribed!"); } return this; } - /** - * Assert that the onSubscribe method hasn't been called at all. - * @return this; - */ - @Override - public final TestObserver assertNotSubscribed() { - if (upstream.get() != null) { - throw fail("Subscribed!"); - } else - if (!errors.isEmpty()) { - throw fail("Not subscribed but errors found"); - } - return this; - } - - /** - * Run a check consumer with this TestObserver instance. - * @param check the check consumer to run - * @return this - */ - public final TestObserver assertOf(Consumer> check) { - try { - check.accept(this); - } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); - } - return this; - } - - /** - * Sets the initial fusion mode if the upstream supports fusion. - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use ObserverFusion to work with such tests. - * @param mode the mode to establish, see the {@link QueueDisposable} constants - * @return this - */ - final TestObserver setInitialFusionMode(int mode) { - this.initialFusionMode = mode; - return this; - } - - /** - * Asserts that the given fusion mode has been established - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use ObserverFusion to work with such tests. - * @param mode the expected mode - * @return this - */ - final TestObserver assertFusionMode(int mode) { - int m = establishedFusionMode; - if (m != mode) { - if (qd != null) { - throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) - + ", actual: " + fusionModeToString(m)); - } else { - throw fail("Upstream is not fuseable"); - } - } - return this; - } - - static String fusionModeToString(int mode) { - switch (mode) { - case QueueFuseable.NONE : return "NONE"; - case QueueFuseable.SYNC : return "SYNC"; - case QueueFuseable.ASYNC : return "ASYNC"; - default: return "Unknown(" + mode + ")"; - } - } - - /** - * Assert that the upstream is a fuseable source. - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use ObserverFusion to work with such tests. - * @return this - */ - final TestObserver assertFuseable() { - if (qd == null) { - throw new AssertionError("Upstream is not fuseable."); - } - return this; - } - - /** - * Assert that the upstream is not a fuseable source. - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use ObserverFusion to work with such tests. - * @return this - */ - final TestObserver assertNotFuseable() { - if (qd != null) { - throw new AssertionError("Upstream is fuseable."); - } - return this; - } - @Override public void onSuccess(T value) { onNext(value); diff --git a/src/main/java/io/reactivex/subscribers/TestSubscriber.java b/src/main/java/io/reactivex/subscribers/TestSubscriber.java index 3b02dbdd09..cf251d3eca 100644 --- a/src/main/java/io/reactivex/subscribers/TestSubscriber.java +++ b/src/main/java/io/reactivex/subscribers/TestSubscriber.java @@ -17,11 +17,7 @@ import org.reactivestreams.*; import io.reactivex.FlowableSubscriber; -import io.reactivex.disposables.Disposable; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.fuseable.QueueSubscription; import io.reactivex.internal.subscriptions.SubscriptionHelper; -import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.observers.BaseTestConsumer; /** @@ -39,7 +35,7 @@ */ public class TestSubscriber extends BaseTestConsumer> -implements FlowableSubscriber, Subscription, Disposable { +implements FlowableSubscriber, Subscription { /** The actual subscriber to forward events to. */ private final Subscriber downstream; @@ -52,8 +48,6 @@ public class TestSubscriber /** Holds the requested amount until a subscription arrives. */ private final AtomicLong missedRequested; - private QueueSubscription qs; - /** * Creates a TestSubscriber with Long.MAX_VALUE initial request. * @param the value type @@ -125,7 +119,6 @@ public TestSubscriber(Subscriber actual, long initialRequest) { this.missedRequested = new AtomicLong(initialRequest); } - @SuppressWarnings("unchecked") @Override public void onSubscribe(Subscription s) { lastThread = Thread.currentThread(); @@ -142,31 +135,6 @@ public void onSubscribe(Subscription s) { return; } - if (initialFusionMode != 0) { - if (s instanceof QueueSubscription) { - qs = (QueueSubscription)s; - - int m = qs.requestFusion(initialFusionMode); - establishedFusionMode = m; - - if (m == QueueSubscription.SYNC) { - checkSubscriptionOnce = true; - lastThread = Thread.currentThread(); - try { - T t; - while ((t = qs.poll()) != null) { - values.add(t); - } - completions++; - } catch (Throwable ex) { - // Exceptions.throwIfFatal(e); TODO add fatal exceptions? - errors.add(ex); - } - return; - } - } - } - downstream.onSubscribe(s); long mr = missedRequested.getAndSet(0L); @@ -194,19 +162,6 @@ public void onNext(T t) { } lastThread = Thread.currentThread(); - if (establishedFusionMode == QueueSubscription.ASYNC) { - try { - while ((t = qs.poll()) != null) { - values.add(t); - } - } catch (Throwable ex) { - // Exceptions.throwIfFatal(e); TODO add fatal exceptions? - errors.add(ex); - qs.cancel(); - } - return; - } - values.add(t); if (t == null) { @@ -278,12 +233,12 @@ public final boolean isCancelled() { } @Override - public final void dispose() { + protected final void dispose() { cancel(); } @Override - public final boolean isDisposed() { + protected final boolean isDisposed() { return cancelled; } @@ -304,109 +259,13 @@ public final boolean hasSubscription() { * @return this */ @Override - public final TestSubscriber assertSubscribed() { + protected final TestSubscriber assertSubscribed() { if (upstream.get() == null) { throw fail("Not subscribed!"); } return this; } - /** - * Assert that the onSubscribe method hasn't been called at all. - * @return this - */ - @Override - public final TestSubscriber assertNotSubscribed() { - if (upstream.get() != null) { - throw fail("Subscribed!"); - } else - if (!errors.isEmpty()) { - throw fail("Not subscribed but errors found"); - } - return this; - } - - /** - * Sets the initial fusion mode if the upstream supports fusion. - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use SubscriberFusion to work with such tests. - * @param mode the mode to establish, see the {@link QueueSubscription} constants - * @return this - */ - final TestSubscriber setInitialFusionMode(int mode) { - this.initialFusionMode = mode; - return this; - } - - /** - * Asserts that the given fusion mode has been established - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use SubscriberFusion to work with such tests. - * @param mode the expected mode - * @return this - */ - final TestSubscriber assertFusionMode(int mode) { - int m = establishedFusionMode; - if (m != mode) { - if (qs != null) { - throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) - + ", actual: " + fusionModeToString(m)); - } else { - throw fail("Upstream is not fuseable"); - } - } - return this; - } - - static String fusionModeToString(int mode) { - switch (mode) { - case QueueSubscription.NONE : return "NONE"; - case QueueSubscription.SYNC : return "SYNC"; - case QueueSubscription.ASYNC : return "ASYNC"; - default: return "Unknown(" + mode + ")"; - } - } - - /** - * Assert that the upstream is a fuseable source. - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use SubscriberFusion to work with such tests. - * @return this - */ - final TestSubscriber assertFuseable() { - if (qs == null) { - throw new AssertionError("Upstream is not fuseable."); - } - return this; - } - - /** - * Assert that the upstream is not a fuseable source. - *

Package-private: avoid leaking the now internal fusion properties into the public API. - * Use SubscriberFusion to work with such tests. - * @return this - */ - final TestSubscriber assertNotFuseable() { - if (qs != null) { - throw new AssertionError("Upstream is fuseable."); - } - return this; - } - - /** - * Run a check consumer with this TestSubscriber instance. - * @param check the check consumer to run - * @return this - */ - public final TestSubscriber assertOf(Consumer> check) { - try { - check.accept(this); - } catch (Throwable ex) { - throw ExceptionHelper.wrapOrThrow(ex); - } - return this; - } - /** * Calls {@link #request(long)} and returns this. *

History: 2.0.1 - experimental diff --git a/src/test/java/io/reactivex/XFlatMapTest.java b/src/test/java/io/reactivex/XFlatMapTest.java index 8a6ec939c5..03a0fb4712 100644 --- a/src/test/java/io/reactivex/XFlatMapTest.java +++ b/src/test/java/io/reactivex/XFlatMapTest.java @@ -27,6 +27,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class XFlatMapTest { @@ -48,11 +49,20 @@ void sleep() throws Exception { } } - void beforeCancelSleep(BaseTestConsumer ts) throws Exception { + void beforeCancelSleep(TestSubscriber ts) throws Exception { long before = System.currentTimeMillis(); Thread.sleep(50); if (System.currentTimeMillis() - before > 100) { - ts.dispose(); + ts.cancel(); + throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before)); + } + } + + void beforeCancelSleep(TestObserver to) throws Exception { + long before = System.currentTimeMillis(); + Thread.sleep(50); + if (System.currentTimeMillis() - before > 100) { + to.dispose(); throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before)); } } @@ -169,7 +179,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -232,7 +242,7 @@ public Observable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -263,7 +273,7 @@ public Single apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -294,7 +304,7 @@ public Maybe apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -325,7 +335,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -357,7 +367,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -388,7 +398,7 @@ public Single apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -419,7 +429,7 @@ public Maybe apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -450,7 +460,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -482,7 +492,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -513,7 +523,7 @@ public Single apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -544,7 +554,7 @@ public Maybe apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -575,7 +585,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); @@ -607,7 +617,7 @@ public Completable apply(Integer v) throws Exception { beforeCancelSleep(to); - to.cancel(); + to.dispose(); Thread.sleep(SLEEP_AFTER_CANCEL); diff --git a/src/test/java/io/reactivex/completable/CompletableTest.java b/src/test/java/io/reactivex/completable/CompletableTest.java index 0898c6a362..d4829592cb 100644 --- a/src/test/java/io/reactivex/completable/CompletableTest.java +++ b/src/test/java/io/reactivex/completable/CompletableTest.java @@ -40,6 +40,7 @@ import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; /** * Test Completable methods and operators. @@ -3542,7 +3543,7 @@ public void accept(Integer t) { } }; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Completable.using(new Supplier() { @Override @@ -3694,7 +3695,7 @@ public void accept(Throwable e) { } @Test public void andThenSubscribeOn() { - TestSubscriber ts = new TestSubscriber(0); + TestSubscriberEx ts = new TestSubscriberEx(0); TestScheduler scheduler = new TestScheduler(); Completable.complete().andThen(Flowable.just("foo").delay(1, TimeUnit.SECONDS, scheduler)).subscribe(ts); @@ -3711,7 +3712,7 @@ public void andThenSubscribeOn() { @Test public void andThenSingleNever() { - TestSubscriber ts = new TestSubscriber(0); + TestSubscriberEx ts = new TestSubscriberEx(0); Completable.never().andThen(Single.just("foo")).toFlowable().subscribe(ts); ts.request(1); ts.assertNoValues(); @@ -3739,7 +3740,7 @@ public void subscribeActual(SingleObserver observer) { @Test public void andThenSingleSubscribeOn() { - TestSubscriber ts = new TestSubscriber(0); + TestSubscriberEx ts = new TestSubscriberEx(0); TestScheduler scheduler = new TestScheduler(); Completable.complete().andThen(Single.just("foo").delay(1, TimeUnit.SECONDS, scheduler)).toFlowable().subscribe(ts); @@ -4055,7 +4056,7 @@ public void accept(Integer t) { } }; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Completable.using(new Supplier() { @Override @@ -4265,7 +4266,7 @@ public void onStart() { @Test public void onErrorCompleteFunctionThrows() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); error.completable.onErrorComplete(new Predicate() { @Override @@ -4425,7 +4426,7 @@ public void accept(Integer integer) { @Test public void andThenNever() { - TestSubscriber ts = new TestSubscriber(0); + TestSubscriberEx ts = new TestSubscriberEx(0); Completable.never().andThen(Flowable.just("foo")).subscribe(ts); ts.request(1); ts.assertNoValues(); diff --git a/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java b/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java index aec399a3e7..096da93988 100644 --- a/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java +++ b/src/test/java/io/reactivex/disposables/CompositeDisposableTest.java @@ -22,9 +22,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.exceptions.CompositeException; import io.reactivex.functions.Action; +import io.reactivex.testsupport.TestHelper; public class CompositeDisposableTest { diff --git a/src/test/java/io/reactivex/disposables/DisposablesTest.java b/src/test/java/io/reactivex/disposables/DisposablesTest.java index 779b85fead..792433dbf0 100644 --- a/src/test/java/io/reactivex/disposables/DisposablesTest.java +++ b/src/test/java/io/reactivex/disposables/DisposablesTest.java @@ -24,10 +24,10 @@ import org.junit.Test; import org.reactivestreams.Subscription; -import io.reactivex.TestHelper; import io.reactivex.functions.Action; import io.reactivex.internal.disposables.DisposableHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposablesTest { diff --git a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java index e1cff53e29..c4b5d01088 100644 --- a/src/test/java/io/reactivex/exceptions/ExceptionsTest.java +++ b/src/test/java/io/reactivex/exceptions/ExceptionsTest.java @@ -31,6 +31,7 @@ import io.reactivex.observables.GroupedObservable; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ExceptionsTest { diff --git a/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java b/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java index 4097f9a52e..0ccc74114d 100644 --- a/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java +++ b/src/test/java/io/reactivex/exceptions/OnErrorNotImplementedExceptionTest.java @@ -22,6 +22,7 @@ import io.reactivex.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class OnErrorNotImplementedExceptionTest { diff --git a/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java b/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java index 7898628f70..323210bdfc 100644 --- a/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableBackpressureTests.java @@ -84,10 +84,10 @@ public void testObserveOn() { AtomicInteger c = new AtomicInteger(); TestSubscriber ts = new TestSubscriber(); incrementingIntegers(c).observeOn(Schedulers.computation()).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testObserveOn => Received: " + ts.valueCount() + " Emitted: " + c.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testObserveOn => Received: " + ts.values().size() + " Emitted: " + c.get()); + assertEquals(num, ts.values().size()); assertTrue(c.get() < Flowable.bufferSize() * 4); } @@ -109,10 +109,10 @@ public Integer apply(Integer i) { } } ).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testObserveOnWithSlowConsumer => Received: " + ts.valueCount() + " Emitted: " + c.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testObserveOnWithSlowConsumer => Received: " + ts.values().size() + " Emitted: " + c.get()); + assertEquals(num, ts.values().size()); assertTrue(c.get() < Flowable.bufferSize() * 2); } @@ -125,11 +125,11 @@ public void testMergeSync() { Flowable merged = Flowable.merge(incrementingIntegers(c1), incrementingIntegers(c2)); merged.take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("Expected: " + num + " got: " + ts.valueCount()); - System.out.println("testMergeSync => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); - assertEquals(num, ts.valueCount()); + System.out.println("Expected: " + num + " got: " + ts.values().size()); + System.out.println("testMergeSync => Received: " + ts.values().size() + " Emitted: " + c1.get() + " / " + c2.get()); + assertEquals(num, ts.values().size()); // either one can starve the other, but neither should be capable of doing more than 5 batches (taking 4.1) // TODO is it possible to make this deterministic rather than one possibly starving the other? // benjchristensen => In general I'd say it's not worth trying to make it so, as "fair" algoritms generally take a performance hit @@ -148,10 +148,10 @@ public void testMergeAsync() { incrementingIntegers(c2).subscribeOn(Schedulers.computation())); merged.take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testMergeAsync => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testMergeAsync => Received: " + ts.values().size() + " Emitted: " + c1.get() + " / " + c2.get()); + assertEquals(num, ts.values().size()); // either one can starve the other, but neither should be capable of doing more than 5 batches (taking 4.1) // TODO is it possible to make this deterministic rather than one possibly starving the other? // benjchristensen => In general I'd say it's not worth trying to make it so, as "fair" algoritms generally take a performance hit @@ -181,11 +181,11 @@ public void testMergeAsyncThenObserveOnLoop() { .take(num) .subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertComplete(); ts.assertNoErrors(); - System.out.println("testMergeAsyncThenObserveOn => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testMergeAsyncThenObserveOn => Received: " + ts.values().size() + " Emitted: " + c1.get() + " / " + c2.get()); + assertEquals(num, ts.values().size()); } } @@ -200,10 +200,10 @@ public void testMergeAsyncThenObserveOn() { incrementingIntegers(c2).subscribeOn(Schedulers.computation())); merged.observeOn(Schedulers.newThread()).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testMergeAsyncThenObserveOn => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testMergeAsyncThenObserveOn => Received: " + ts.values().size() + " Emitted: " + c1.get() + " / " + c2.get()); + assertEquals(num, ts.values().size()); // either one can starve the other, but neither should be capable of doing more than 5 batches (taking 4.1) // TODO is it possible to make this deterministic rather than one possibly starving the other? // benjchristensen => In general I'd say it's not worth trying to make it so, as "fair" algoritms generally take a performance hit @@ -227,10 +227,10 @@ public Publisher apply(Integer i) { }) .take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testFlatMapSync => Received: " + ts.valueCount() + " Emitted: " + c.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testFlatMapSync => Received: " + ts.values().size() + " Emitted: " + c.get()); + assertEquals(num, ts.values().size()); // expect less than 1 buffer since the flatMap is emitting 10 each time, so it is num/10 that will be taken. assertTrue(c.get() < Flowable.bufferSize()); } @@ -255,10 +255,10 @@ public Publisher apply(Integer i) { ) .take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testFlatMapAsync => Received: " + ts.valueCount() + " Emitted: " + c.get() + " Size: " + Flowable.bufferSize()); - assertEquals(num, ts.valueCount()); + System.out.println("testFlatMapAsync => Received: " + ts.values().size() + " Emitted: " + c.get() + " Size: " + Flowable.bufferSize()); + assertEquals(num, ts.values().size()); // even though we only need 10, it will request at least Flowable.bufferSize(), and then as it drains keep requesting more // and then it will be non-deterministic when the take() causes the unsubscribe as it is scheduled on 10 different schedulers (threads) // normally this number is ~250 but can get up to ~1200 when Flowable.bufferSize() == 1024 @@ -285,10 +285,10 @@ public Integer apply(Integer t1, Integer t2) { zipped.take(num) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testZipSync => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testZipSync => Received: " + ts.values().size() + " Emitted: " + c1.get() + " / " + c2.get()); + assertEquals(num, ts.values().size()); assertTrue(c1.get() < Flowable.bufferSize() * 7); assertTrue(c2.get() < Flowable.bufferSize() * 7); } @@ -310,10 +310,10 @@ public Integer apply(Integer t1, Integer t2) { }); zipped.take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testZipAsync => Received: " + ts.valueCount() + " Emitted: " + c1.get() + " / " + c2.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testZipAsync => Received: " + ts.values().size() + " Emitted: " + c1.get() + " / " + c2.get()); + assertEquals(num, ts.values().size()); int max = Flowable.bufferSize() * 5; assertTrue("" + c1.get() + " >= " + max, c1.get() < max); assertTrue("" + c2.get() + " >= " + max, c2.get() < max); @@ -329,10 +329,10 @@ public void testSubscribeOnScheduling() { TestSubscriber ts = new TestSubscriber(); // observeOn is there to make it async and need backpressure incrementingIntegers(c, threads).subscribeOn(Schedulers.computation()).observeOn(Schedulers.computation()).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testSubscribeOnScheduling => Received: " + ts.valueCount() + " Emitted: " + c.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testSubscribeOnScheduling => Received: " + ts.values().size() + " Emitted: " + c.get()); + assertEquals(num, ts.values().size()); assertTrue(c.get() < Flowable.bufferSize() * 4); Thread first = null; for (Thread t : threads) { @@ -365,7 +365,7 @@ public boolean test(Integer i) { } }).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); // emit 10000 that are skipped @@ -374,8 +374,8 @@ public boolean test(Integer i) { // so emitted is at least 10000+1000+num + extra for buffer size/threshold int expected = 10000 + 1000 + Flowable.bufferSize() * 3 + Flowable.bufferSize() / 2; - System.out.println("testTakeFilterSkipChain => Received: " + ts.valueCount() + " Emitted: " + c.get() + " Expected: " + expected); - assertEquals(num, ts.valueCount()); + System.out.println("testTakeFilterSkipChain => Received: " + ts.values().size() + " Emitted: " + c.get() + " Expected: " + expected); + assertEquals(num, ts.values().size()); assertTrue(c.get() < expected); } @@ -498,11 +498,11 @@ public Integer apply(Integer v) { }) .subscribe(ts); - ts.awaitTerminalEvent(); - System.out.println("testFirehoseFailsAsExpected => Received: " + ts.valueCount() + " Emitted: " + c.get()); + ts.awaitDone(5, TimeUnit.SECONDS); + System.out.println("testFirehoseFailsAsExpected => Received: " + ts.values().size() + " Emitted: " + c.get()); // FIXME it is possible slow is not slow enough or the main gets delayed and thus more than one source value is emitted. - int vc = ts.valueCount(); + int vc = ts.values().size(); assertTrue("10 < " + vc, vc <= 10); ts.assertError(MissingBackpressureException.class); @@ -530,7 +530,7 @@ public void testOnBackpressureDrop() { firehose(c).onBackpressureDrop() .observeOn(Schedulers.computation()) .map(SLOW_PASS_THRU).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); List onNextEvents = ts.values(); @@ -570,7 +570,7 @@ public void accept(Integer v) { .map(SLOW_PASS_THRU) .take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); List onNextEvents = ts.values(); @@ -594,7 +594,7 @@ public void testOnBackpressureDropSynchronous() { TestSubscriber ts = new TestSubscriber(); firehose(c).onBackpressureDrop() .map(SLOW_PASS_THRU).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); List onNextEvents = ts.values(); @@ -622,7 +622,7 @@ public void accept(Integer j) { } }) .map(SLOW_PASS_THRU).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); List onNextEvents = ts.values(); @@ -655,10 +655,10 @@ public boolean test(Integer t1) { .observeOn(Schedulers.computation()) .map(SLOW_PASS_THRU).take(num).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - System.out.println("testOnBackpressureBuffer => Received: " + ts.valueCount() + " Emitted: " + c.get()); - assertEquals(num, ts.valueCount()); + System.out.println("testOnBackpressureBuffer => Received: " + ts.values().size() + " Emitted: " + c.get()); + assertEquals(num, ts.values().size()); // it buffers, so we should get the right value sequentially assertEquals(num - 1, ts.values().get(num - 1).intValue()); } diff --git a/src/test/java/io/reactivex/flowable/FlowableCollectTest.java b/src/test/java/io/reactivex/flowable/FlowableCollectTest.java index be419b4f91..17d83081b9 100644 --- a/src/test/java/io/reactivex/flowable/FlowableCollectTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableCollectTest.java @@ -26,6 +26,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public final class FlowableCollectTest { diff --git a/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java b/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java index 812b747750..ca28c1d93f 100644 --- a/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableCovarianceTest.java @@ -23,11 +23,10 @@ import org.junit.Test; import org.reactivestreams.Publisher; -import io.reactivex.Flowable; -import io.reactivex.FlowableTransformer; +import io.reactivex.*; import io.reactivex.flowables.GroupedFlowable; import io.reactivex.functions.*; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; /** * Test super/extends of generics. @@ -67,7 +66,7 @@ public int compare(Media t1, Media t2) { @Test public void testGroupByCompose() { Flowable movies = Flowable.just(new HorrorMovie(), new ActionMovie(), new Movie()); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); movies .groupBy(new Function() { @@ -111,7 +110,7 @@ public String apply(Object v) { ts.assertTerminated(); ts.assertNoErrors(); // System.out.println(ts.getOnNextEvents()); - assertEquals(6, ts.valueCount()); + assertEquals(6, ts.values().size()); } @SuppressWarnings("unused") diff --git a/src/test/java/io/reactivex/flowable/FlowableEventStreamTest.java b/src/test/java/io/reactivex/flowable/FlowableEventStreamTest.java index c0dd902991..7c7f45bedc 100644 --- a/src/test/java/io/reactivex/flowable/FlowableEventStreamTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableEventStreamTest.java @@ -18,7 +18,7 @@ import org.junit.Test; -import io.reactivex.TestHelper; +import io.reactivex.testsupport.TestHelper; public class FlowableEventStreamTest { @Test diff --git a/src/test/java/io/reactivex/flowable/FlowableFuseableTest.java b/src/test/java/io/reactivex/flowable/FlowableFuseableTest.java index f9594a6220..878b258e49 100644 --- a/src/test/java/io/reactivex/flowable/FlowableFuseableTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableFuseableTest.java @@ -17,8 +17,8 @@ import org.junit.Test; import io.reactivex.Flowable; -import io.reactivex.internal.fuseable.*; -import io.reactivex.subscribers.SubscriberFusion; +import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.testsupport.TestHelper; public class FlowableFuseableTest { @@ -26,8 +26,8 @@ public class FlowableFuseableTest { public void syncRange() { Flowable.range(1, 10) - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertFusionMode(QueueFuseable.SYNC) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -37,8 +37,8 @@ public void syncRange() { public void syncArray() { Flowable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertFusionMode(QueueFuseable.SYNC) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -48,8 +48,8 @@ public void syncArray() { public void syncIterable() { Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertFusionMode(QueueFuseable.SYNC) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -59,9 +59,9 @@ public void syncIterable() { public void syncRangeHidden() { Flowable.range(1, 10).hide() - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertNotFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertNotFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -71,9 +71,9 @@ public void syncRangeHidden() { public void syncArrayHidden() { Flowable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) .hide() - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertNotFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertNotFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -83,9 +83,9 @@ public void syncArrayHidden() { public void syncIterableHidden() { Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .hide() - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertNotFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertNotFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); diff --git a/src/test/java/io/reactivex/flowable/FlowableNullTests.java b/src/test/java/io/reactivex/flowable/FlowableNullTests.java index 0a2c8c7a95..eb98758a25 100644 --- a/src/test/java/io/reactivex/flowable/FlowableNullTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableNullTests.java @@ -29,6 +29,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; /** * Verifies the operators handle null values properly by emitting/throwing NullPointerExceptions. diff --git a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java index d0a0e1a88e..99a4ecb7b5 100644 --- a/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java +++ b/src/test/java/io/reactivex/flowable/FlowableSubscriberTest.java @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableSubscriberTest { diff --git a/src/test/java/io/reactivex/flowable/FlowableTests.java b/src/test/java/io/reactivex/flowable/FlowableTests.java index 749c83771c..f5221585f4 100644 --- a/src/test/java/io/reactivex/flowable/FlowableTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableTests.java @@ -37,6 +37,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableTests { @@ -1052,7 +1053,7 @@ public void accept(List booleans) { @Test public void testCompose() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.just(1, 2, 3).compose(new FlowableTransformer() { @Override public Publisher apply(Flowable t1) { diff --git a/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java b/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java index 8d249e6c23..0126f3f97a 100644 --- a/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableThrottleLastTests.java @@ -21,9 +21,9 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.TestHelper; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class FlowableThrottleLastTests { diff --git a/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java b/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java index 339d7f4316..a06d1a4061 100644 --- a/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java +++ b/src/test/java/io/reactivex/flowable/FlowableThrottleWithTimeoutTests.java @@ -24,6 +24,7 @@ import io.reactivex.*; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class FlowableThrottleWithTimeoutTests { diff --git a/src/test/java/io/reactivex/internal/disposables/ArrayCompositeDisposableTest.java b/src/test/java/io/reactivex/internal/disposables/ArrayCompositeDisposableTest.java index 81fb4de489..fcd2b59d86 100644 --- a/src/test/java/io/reactivex/internal/disposables/ArrayCompositeDisposableTest.java +++ b/src/test/java/io/reactivex/internal/disposables/ArrayCompositeDisposableTest.java @@ -17,8 +17,8 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; +import io.reactivex.testsupport.TestHelper; public class ArrayCompositeDisposableTest { diff --git a/src/test/java/io/reactivex/internal/disposables/CancellableDisposableTest.java b/src/test/java/io/reactivex/internal/disposables/CancellableDisposableTest.java index 41e3997243..face72ed53 100644 --- a/src/test/java/io/reactivex/internal/disposables/CancellableDisposableTest.java +++ b/src/test/java/io/reactivex/internal/disposables/CancellableDisposableTest.java @@ -20,10 +20,10 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Cancellable; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class CancellableDisposableTest { diff --git a/src/test/java/io/reactivex/internal/disposables/DisposableHelperTest.java b/src/test/java/io/reactivex/internal/disposables/DisposableHelperTest.java index b219e44dd1..8f25db16ae 100644 --- a/src/test/java/io/reactivex/internal/disposables/DisposableHelperTest.java +++ b/src/test/java/io/reactivex/internal/disposables/DisposableHelperTest.java @@ -20,9 +20,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableHelperTest { @Test diff --git a/src/test/java/io/reactivex/internal/disposables/EmptyDisposableTest.java b/src/test/java/io/reactivex/internal/disposables/EmptyDisposableTest.java index d373560413..6b1daf47f7 100644 --- a/src/test/java/io/reactivex/internal/disposables/EmptyDisposableTest.java +++ b/src/test/java/io/reactivex/internal/disposables/EmptyDisposableTest.java @@ -17,8 +17,8 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.fuseable.*; +import io.reactivex.testsupport.TestHelper; public class EmptyDisposableTest { diff --git a/src/test/java/io/reactivex/internal/disposables/ListCompositeDisposableTest.java b/src/test/java/io/reactivex/internal/disposables/ListCompositeDisposableTest.java index 4d3ed24708..e83dcb7ef2 100644 --- a/src/test/java/io/reactivex/internal/disposables/ListCompositeDisposableTest.java +++ b/src/test/java/io/reactivex/internal/disposables/ListCompositeDisposableTest.java @@ -19,9 +19,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; +import io.reactivex.testsupport.TestHelper; public class ListCompositeDisposableTest { diff --git a/src/test/java/io/reactivex/internal/functions/FunctionsTest.java b/src/test/java/io/reactivex/internal/functions/FunctionsTest.java index e2a473fa44..6f3213566e 100644 --- a/src/test/java/io/reactivex/internal/functions/FunctionsTest.java +++ b/src/test/java/io/reactivex/internal/functions/FunctionsTest.java @@ -20,12 +20,12 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions.*; import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class FunctionsTest { @Test diff --git a/src/test/java/io/reactivex/internal/functions/ObjectHelperTest.java b/src/test/java/io/reactivex/internal/functions/ObjectHelperTest.java index 898900d34f..da5f576913 100644 --- a/src/test/java/io/reactivex/internal/functions/ObjectHelperTest.java +++ b/src/test/java/io/reactivex/internal/functions/ObjectHelperTest.java @@ -15,8 +15,9 @@ import org.junit.Test; +import io.reactivex.testsupport.TestHelper; + import static org.junit.Assert.*; -import io.reactivex.TestHelper; public class ObjectHelperTest { diff --git a/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java b/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java index 797ae8e07a..eba4babcfa 100644 --- a/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/BasicFuseableObserverTest.java @@ -13,17 +13,18 @@ package io.reactivex.internal.observers; -import io.reactivex.annotations.Nullable; import org.junit.Test; +import io.reactivex.annotations.Nullable; import io.reactivex.disposables.Disposables; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestObserverEx; public class BasicFuseableObserverTest { @Test(expected = UnsupportedOperationException.class) public void offer() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); BasicFuseableObserver o = new BasicFuseableObserver(to) { @Nullable @Override diff --git a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java index 7d2640b71c..a92271ee2f 100644 --- a/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/DeferredScalarObserverTest.java @@ -19,12 +19,13 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class DeferredScalarObserverTest { @@ -106,7 +107,7 @@ public void dispose() { assertFalse(d.isDisposed()); - to.cancel(); + to.dispose(); assertTrue(d.isDisposed()); @@ -117,7 +118,7 @@ public void dispose() { public void fused() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); TakeFirst source = new TakeFirst(to); @@ -125,8 +126,8 @@ public void fused() { source.onSubscribe(d); - to.assertOf(ObserverFusion.assertFuseable()); - to.assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)); + to.assertFuseable(); + to.assertFusionMode(QueueFuseable.ASYNC); source.onNext(1); source.onNext(1); @@ -147,7 +148,7 @@ public void fused() { public void fusedReject() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); TakeFirst source = new TakeFirst(to); @@ -155,8 +156,8 @@ public void fusedReject() { source.onSubscribe(d); - to.assertOf(ObserverFusion.assertFuseable()); - to.assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)); + to.assertFuseable(); + to.assertFusionMode(QueueFuseable.NONE); source.onNext(1); source.onNext(1); @@ -192,7 +193,7 @@ public void onNext(Integer value) { public void nonfusedTerminateMore() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + TestObserverEx to = new TestObserverEx(QueueFuseable.NONE); TakeLast source = new TakeLast(to); @@ -217,7 +218,7 @@ public void nonfusedTerminateMore() { public void nonfusedError() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + TestObserverEx to = new TestObserverEx(QueueFuseable.NONE); TakeLast source = new TakeLast(to); @@ -242,7 +243,7 @@ public void nonfusedError() { public void fusedTerminateMore() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); TakeLast source = new TakeLast(to); @@ -267,7 +268,7 @@ public void fusedTerminateMore() { public void fusedError() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); TakeLast source = new TakeLast(to); @@ -290,7 +291,7 @@ public void fusedError() { @Test public void disposed() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + TestObserverEx to = new TestObserverEx(QueueFuseable.NONE); TakeLast source = new TakeLast(to); @@ -298,7 +299,7 @@ public void disposed() { source.onSubscribe(d); - to.cancel(); + to.dispose(); source.onNext(1); source.onComplete(); @@ -345,7 +346,7 @@ public void onComplete() { @Test public void fusedEmpty() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); TakeLast source = new TakeLast(to); @@ -360,7 +361,7 @@ public void fusedEmpty() { @Test public void nonfusedEmpty() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + TestObserverEx to = new TestObserverEx(QueueFuseable.NONE); TakeLast source = new TakeLast(to); @@ -464,7 +465,7 @@ public void onComplete() { @Test public void offerThrow() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.NONE); + TestObserverEx to = new TestObserverEx(QueueFuseable.NONE); TakeLast source = new TakeLast(to); diff --git a/src/test/java/io/reactivex/internal/observers/DisposableLambdaObserverTest.java b/src/test/java/io/reactivex/internal/observers/DisposableLambdaObserverTest.java index c152f15b37..49f0d10da2 100644 --- a/src/test/java/io/reactivex/internal/observers/DisposableLambdaObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/DisposableLambdaObserverTest.java @@ -19,13 +19,13 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableLambdaObserverTest { diff --git a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java index 7ee71945bc..761015a26d 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureObserverTest.java @@ -21,7 +21,6 @@ import org.junit.*; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.internal.functions.Functions; @@ -29,6 +28,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class FutureObserverTest { FutureObserver fo; diff --git a/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java b/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java index 9cafad4569..2e44b97cc5 100644 --- a/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/FutureSingleObserverTest.java @@ -26,6 +26,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class FutureSingleObserverTest { diff --git a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java index 26c6e30bea..69a272da5e 100644 --- a/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/LambdaObserverTest.java @@ -23,12 +23,12 @@ import io.reactivex.Observable; import io.reactivex.Observer; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class LambdaObserverTest { diff --git a/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java b/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java index 1f9fffd356..b12b84a6b5 100644 --- a/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java +++ b/src/test/java/io/reactivex/internal/observers/QueueDrainObserverTest.java @@ -19,6 +19,7 @@ import io.reactivex.disposables.*; import io.reactivex.internal.queue.SpscArrayQueue; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestHelper; public class QueueDrainObserverTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java index f4a8a084b8..7d37862574 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAmbTest.java @@ -32,6 +32,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class CompletableAmbTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java index 34b9c82436..956134c0da 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenCompletableabTest.java @@ -23,6 +23,7 @@ import io.reactivex.functions.Action; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; import static org.junit.Assert.*; @@ -45,7 +46,7 @@ public void andThenCompletableCompleteComplete() { public void andThenCompletableCompleteError() { Completable.complete() .andThen(Completable.error(new TestException("test"))) - .test() + .to(TestHelper.testConsumer()) .assertNotComplete() .assertNoValues() .assertError(TestException.class) @@ -66,7 +67,7 @@ public void andThenCompletableCompleteNever() { public void andThenCompletableErrorComplete() { Completable.error(new TestException("bla")) .andThen(Completable.complete()) - .test() + .to(TestHelper.testConsumer()) .assertNotComplete() .assertNoValues() .assertError(TestException.class) @@ -77,7 +78,7 @@ public void andThenCompletableErrorComplete() { public void andThenCompletableErrorNever() { Completable.error(new TestException("bla")) .andThen(Completable.never()) - .test() + .to(TestHelper.testConsumer()) .assertNotComplete() .assertNoValues() .assertError(TestException.class) @@ -88,7 +89,7 @@ public void andThenCompletableErrorNever() { public void andThenCompletableErrorError() { Completable.error(new TestException("error1")) .andThen(Completable.error(new TestException("error2"))) - .test() + .to(TestHelper.testConsumer()) .assertNotComplete() .assertNoValues() .assertError(TestException.class) @@ -116,7 +117,7 @@ public void andThenFirstCancels() { Completable.fromRunnable(new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }) .andThen(Completable.complete()) @@ -133,7 +134,7 @@ public void andThenSecondCancels() { .andThen(Completable.fromRunnable(new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } })) .subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java index c873d5472d..228cf4d2c3 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableAndThenTest.java @@ -16,6 +16,7 @@ import org.junit.Test; import io.reactivex.*; +import io.reactivex.testsupport.TestHelper; public class CompletableAndThenTest { @Test(expected = NullPointerException.class) @@ -36,7 +37,7 @@ public void andThenMaybeCompleteValue() { public void andThenMaybeCompleteError() { Completable.complete() .andThen(Maybe.error(new RuntimeException("test"))) - .test() + .to(TestHelper.testConsumer()) .assertNotComplete() .assertNoValues() .assertError(RuntimeException.class) @@ -57,7 +58,7 @@ public void andThenMaybeCompleteEmpty() { public void andThenMaybeError() { Completable.error(new RuntimeException("bla")) .andThen(Maybe.empty()) - .test() + .to(TestHelper.testConsumer()) .assertNotComplete() .assertNoValues() .assertError(RuntimeException.class) diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableCacheTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableCacheTest.java index c32ea2c9ba..95522e9bbf 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableCacheTest.java @@ -24,6 +24,7 @@ import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableCacheTest implements Consumer, Action { @@ -91,7 +92,7 @@ public void crossDispose() { @Override public void onComplete() { super.onComplete(); - to1.cancel(); + to1.dispose(); } }; @@ -116,7 +117,7 @@ public void crossDisposeOnError() { @Override public void onError(Throwable ex) { super.onError(ex); - to1.cancel(); + to1.dispose(); } }; @@ -143,17 +144,17 @@ public void dispose() { assertTrue(ps.hasObservers()); - to1.cancel(); + to1.dispose(); assertTrue(ps.hasObservers()); TestObserver to2 = c.test(); TestObserver to3 = c.test(); - to3.cancel(); + to3.dispose(); TestObserver to4 = c.test(true); - to3.cancel(); + to3.dispose(); ps.onComplete(); @@ -213,7 +214,7 @@ public void subscribeDisposeRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; Runnable r2 = new Runnable() { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java index 47c21fff85..6351988b15 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableConcatTest.java @@ -30,6 +30,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class CompletableConcatTest { @@ -172,7 +173,7 @@ public void arrayFirstCancels() { @Override protected void subscribeActual(CompletableObserver observer) { observer.onSubscribe(Disposables.empty()); - to.cancel(); + to.dispose(); observer.onComplete(); } }, Completable.complete()) @@ -196,7 +197,7 @@ public void iterableFirstCancels() { @Override protected void subscribeActual(CompletableObserver observer) { observer.onSubscribe(Disposables.empty()); - to.cancel(); + to.dispose(); observer.onComplete(); } }, Completable.complete())) @@ -226,7 +227,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -255,7 +256,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java index 33f50adc5b..3ca72ec8f0 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableCreateTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Cancellable; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class CompletableCreateTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java index be72ce0ad4..f3d66c5b9c 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDelayTest.java @@ -20,14 +20,13 @@ import org.junit.Test; -import io.reactivex.CompletableSource; -import io.reactivex.TestHelper; -import io.reactivex.Completable; +import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class CompletableDelayTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDetachTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDetachTest.java index 850365b2fc..fd9cea35be 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDetachTest.java @@ -26,6 +26,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class CompletableDetachTest { @@ -77,7 +78,7 @@ protected void subscribeActual(CompletableObserver observer) { d = null; - to.cancel(); + to.dispose(); System.gc(); Thread.sleep(200); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDisposeOnTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDisposeOnTest.java index a2f359edee..c4ee5dd623 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDisposeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDisposeOnTest.java @@ -27,6 +27,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableDisposeOnTest { @@ -39,7 +40,7 @@ public void cancelDelayed() { ps.ignoreElements() .unsubscribeOn(scheduler) .test() - .cancel(); + .dispose(); assertTrue(ps.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoFinallyTest.java index ad32e03612..96d58a36d3 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoFinallyTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableDoFinallyTest implements Action { @@ -82,7 +83,7 @@ public void run() throws Exception { }) .test() .assertResult() - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java index 5d38ba126f..86e955fc4f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableDoOnTest.java @@ -13,18 +13,19 @@ package io.reactivex.internal.operators.completable; +import static org.junit.Assert.*; + import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.Assert.*; -import org.junit.*; +import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class CompletableDoOnTest { @@ -42,13 +43,13 @@ public void accept(Throwable e) throws Exception { @Test public void errorAcceptThrows() { - TestObserver to = Completable.error(new TestException("Outer")).doOnEvent(new Consumer() { + TestObserverEx to = Completable.error(new TestException("Outer")).doOnEvent(new Consumer() { @Override public void accept(Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -97,7 +98,7 @@ public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(bs.isDisposed()); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java index b0d551a64e..09127a0a3a 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromCallableTest.java @@ -29,6 +29,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class CompletableFromCallableTest { @Test(expected = NullPointerException.class) @@ -151,7 +152,7 @@ public String answer(InvocationOnMock invocation) throws Throwable { observerLatch.await(); // Unsubscribing before emission - outer.cancel(); + outer.dispose(); // Emitting result funcLatch.countDown(); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromPublisherTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromPublisherTest.java index 03db0c5fe0..526bae5f74 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableFromPublisherTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableFromPublisherTest.java @@ -17,6 +17,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class CompletableFromPublisherTest { @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableHideTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableHideTest.java index 739b1bb92f..4a04787c35 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableHideTest.java @@ -13,13 +13,13 @@ package io.reactivex.internal.operators.completable; -import io.reactivex.Completable; -import io.reactivex.CompletableSource; -import io.reactivex.TestHelper; +import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.CompletableSubject; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java index da78bc0bcf..b5c7255041 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableLiftTest.java @@ -20,6 +20,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class CompletableLiftTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java index aec11e5a61..f4f728adb5 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableMaterializeTest.java @@ -19,6 +19,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.subjects.CompletableSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableMaterializeTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeIterableTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeIterableTest.java index fb1b4c709a..c0fdec6a2b 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeIterableTest.java @@ -22,6 +22,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableMergeIterableTest { @@ -74,7 +75,7 @@ public Iterator iterator() { return new Iterator() { @Override public boolean hasNext() { - to.cancel(); + to.dispose(); return true; } @@ -109,7 +110,7 @@ public boolean hasNext() { @Override public Completable next() { - to.cancel(); + to.dispose(); return Completable.complete(); } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java index 588dda88f9..1331467bf1 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableMergeTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.*; public class CompletableMergeTest { @Test @@ -49,7 +50,7 @@ public void cancelAfterFirst() { protected void subscribeActual(CompletableObserver observer) { observer.onSubscribe(Disposables.empty()); observer.onComplete(); - to.cancel(); + to.dispose(); } }, Completable.complete()) .subscribe(to); @@ -66,7 +67,7 @@ public void cancelAfterFirstDelayError() { protected void subscribeActual(CompletableObserver observer) { observer.onSubscribe(Disposables.empty()); observer.onComplete(); - to.cancel(); + to.dispose(); } }, Completable.complete()) .subscribe(to); @@ -149,7 +150,7 @@ public void disposePropagates() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); @@ -197,12 +198,12 @@ public void mainErrorInnerErrorRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestObserver to = Completable.merge(pp1.map(new Function() { + TestObserverEx to = Completable.merge(pp1.map(new Function() { @Override public Completable apply(Integer v) throws Exception { return pp2.ignoreElements(); } - })).test(); + })).to(TestHelper.testConsumer()); pp1.onNext(1); @@ -250,12 +251,12 @@ public void mainErrorInnerErrorDelayedRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestObserver to = Completable.mergeDelayError(pp1.map(new Function() { + TestObserverEx to = Completable.mergeDelayError(pp1.map(new Function() { @Override public Completable apply(Integer v) throws Exception { return pp2.ignoreElements(); } - })).test(); + })).to(TestHelper.testConsumer()); pp1.onNext(1); @@ -392,7 +393,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("Second")); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -414,7 +415,7 @@ protected void subscribeActual(CompletableObserver observer) { o[0] = observer; } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); o[0].onError(new TestException("Second")); @@ -501,7 +502,7 @@ public Iterator iterator() { return new Iterator() { @Override public boolean hasNext() { - to.cancel(); + to.dispose(); return true; } @@ -537,7 +538,7 @@ public boolean hasNext() { @Override public Completable next() { - to.cancel(); + to.dispose(); return Completable.complete(); } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableObserveOnTest.java index af85ebb8d3..45acb2464c 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableObserveOnTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class CompletableObserveOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletablePeekTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletablePeekTest.java index 3db576fbba..a915e5a5ec 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletablePeekTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletablePeekTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.CompletableSubject; +import io.reactivex.testsupport.TestHelper; public class CompletablePeekTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java index 1633954fbf..b03423d2b8 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableResumeNextTest.java @@ -19,6 +19,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; +import io.reactivex.testsupport.TestHelper; public class CompletableResumeNextTest { @@ -26,7 +27,7 @@ public class CompletableResumeNextTest { public void resumeWithError() { Completable.error(new TestException()) .onErrorResumeNext(Functions.justFunction(Completable.error(new TestException("second")))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "second"); } diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeOnTest.java index cfbc1e6a00..9c18afbe17 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableSubscribeOnTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableSubscribeOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java index abf64f32f0..1b90be2207 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableTakeUntilTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.CompletableSubject; +import io.reactivex.testsupport.TestHelper; public class CompletableTakeUntilTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java index a0de2b25aa..094dd459bf 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableTimeoutTest.java @@ -22,7 +22,7 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Completable; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; @@ -31,6 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class CompletableTimeoutTest { @@ -39,7 +40,7 @@ public void timeoutException() throws Exception { Completable.never() .timeout(100, TimeUnit.MILLISECONDS, Schedulers.io()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertFailureAndMessage(TimeoutException.class, timeoutMessage(100, TimeUnit.MILLISECONDS)); } @@ -118,8 +119,9 @@ public void errorTimeoutRace() { final PublishSubject ps = PublishSubject.create(); - TestObserver to = ps.ignoreElements() - .timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()).test(); + TestObserverEx to = ps.ignoreElements() + .timeout(1, TimeUnit.MILLISECONDS, scheduler, Completable.complete()) + .to(TestHelper.testConsumer()); final TestException ex = new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableTimerTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableTimerTest.java index 6bd5afd62b..5081dcb8fd 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableTimerTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Action; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class CompletableTimerTest { @@ -53,7 +54,7 @@ public void run() throws Exception { Thread.sleep(500); - to.cancel(); + to.dispose(); Thread.sleep(500); diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableToFlowableTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableToFlowableTest.java index 54661a96db..96b5b5040f 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableToFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableToFlowableTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class CompletableToFlowableTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableToObservableTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableToObservableTest.java index b1cda25ef8..3141aee55e 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableToObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableToObservableTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.operators.completable.CompletableToObservable.ObserverCompletableObserver; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestHelper; public class CompletableToObservableTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java index 518e81c3a9..40dea73a75 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableUnsafeTest.java @@ -22,6 +22,7 @@ import io.reactivex.*; import io.reactivex.disposables.Disposables; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class CompletableUnsafeTest { diff --git a/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java b/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java index af53d63301..5a66d52eaa 100644 --- a/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/completable/CompletableUsingTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class CompletableUsingTest { @@ -193,7 +194,7 @@ public void accept(Object d) throws Exception { @Test public void supplierAndDisposerCrashEager() { - TestObserver to = Completable.using(new Supplier() { + TestObserverEx to = Completable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -209,7 +210,7 @@ public void accept(Object d) throws Exception { throw new TestException("Disposer"); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List list = TestHelper.compositeList(to.errors().get(0)); @@ -238,7 +239,7 @@ public void accept(Object d) throws Exception { throw new TestException("Disposer"); } }, false) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Main"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Disposer"); @@ -251,7 +252,7 @@ public void accept(Object d) throws Exception { public void dispose() { final int[] call = {0 }; - TestObserver to = Completable.using(new Supplier() { + TestObserverEx to = Completable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -267,9 +268,9 @@ public void accept(Object d) throws Exception { call[0]++; } }, false) - .test(); + .to(TestHelper.testConsumer()); - to.cancel(); + to.dispose(); assertEquals(1, call[0]); } @@ -296,7 +297,7 @@ public void accept(Object d) throws Exception { }, false) .test(); - to.cancel(); + to.dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -370,7 +371,7 @@ public void accept(Object d) throws Exception { @Test public void errorDisposerCrash() { - TestObserver to = Completable.using(new Supplier() { + TestObserverEx to = Completable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -386,7 +387,7 @@ public void accept(Object d) throws Exception { throw new TestException("Disposer"); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List list = TestHelper.compositeList(to.errors().get(0)); @@ -442,7 +443,7 @@ public void successDisposeRace() { final PublishSubject ps = PublishSubject.create(); - final TestObserver to = Completable.using(new Supplier() { + final TestObserverEx to = Completable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -457,14 +458,14 @@ public CompletableSource apply(Object v) throws Exception { public void accept(Object d) throws Exception { } }, true) - .test(); + .to(TestHelper.testConsumer()); ps.onNext(1); Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -509,7 +510,7 @@ public void accept(Object d) throws Exception { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -554,7 +555,7 @@ public void accept(Object d) throws Exception { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java index 92dcd3dd02..03e41ca7f8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableLatestTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class BlockingFlowableLatestTest { @Test(timeout = 1000) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java index 26e6eb5716..da82596c95 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableMostRecentTest.java @@ -24,6 +24,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.processors.*; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class BlockingFlowableMostRecentTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java index 32ee150cf3..086a74ee19 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/BlockingFlowableNextTest.java @@ -30,6 +30,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class BlockingFlowableNextTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java index e859766ca8..0593f20e97 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAllTest.java @@ -32,6 +32,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableAllTest { @@ -162,7 +163,7 @@ public boolean test(Object t1) { @Test public void testBackpressureIfOneRequestedOneShouldBeDelivered() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Flowable.empty().all(new Predicate() { @Override @@ -180,7 +181,7 @@ public boolean test(Object t) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final IllegalArgumentException ex = new IllegalArgumentException(); @@ -339,7 +340,7 @@ public boolean test(Object t1) { @Test public void testBackpressureIfOneRequestedOneShouldBeDeliveredFlowable() { - TestSubscriber ts = new TestSubscriber(1L); + TestSubscriberEx ts = new TestSubscriberEx(1L); Flowable.empty().all(new Predicate() { @Override @@ -359,7 +360,7 @@ public boolean test(Object t) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessageFlowable() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final IllegalArgumentException ex = new IllegalArgumentException(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java index 5b5941fbf4..4d17759b4e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAmbTest.java @@ -35,7 +35,8 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableAmbTest { @@ -232,7 +233,7 @@ public void testBackpressure() { .delay(1, TimeUnit.MICROSECONDS) // make it a slightly slow consumer .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } @@ -257,7 +258,7 @@ public void accept(Subscription s) { TestSubscriber ts = new TestSubscriber(); Flowable.ambArray(f1, f2).subscribe(ts); ts.request(1); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(2, count.get()); } @@ -278,7 +279,7 @@ public void testSecondaryRequestsPropagatedToChildren() throws InterruptedExcept // this request should suffice to emit all ts.request(20); //ensure stream does not hang - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } @@ -335,8 +336,8 @@ public void testMultipleUse() { amb.subscribe(ts1); amb.subscribe(ts2); - ts1.awaitTerminalEvent(); - ts2.awaitTerminalEvent(); + ts1.awaitDone(5, TimeUnit.SECONDS); + ts2.awaitDone(5, TimeUnit.SECONDS); ts1.assertValue(0L); ts1.assertComplete(); @@ -455,7 +456,7 @@ public void ambManyError() throws Exception { Flowable obs = (Flowable)m.invoke(null, (Object[])ps); - TestSubscriber ts = TestSubscriber.create(); + TestSubscriberEx ts = new TestSubscriberEx(); obs.subscribe(ts); @@ -569,7 +570,7 @@ public void onNextRace() { final PublishProcessor pp2 = PublishProcessor.create(); @SuppressWarnings("unchecked") - TestSubscriber ts = Flowable.ambArray(pp1, pp2).test(); + TestSubscriberEx ts = Flowable.ambArray(pp1, pp2).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -673,7 +674,7 @@ public Flowable apply(Integer v) throws Exception { return Flowable.never(); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); Flowable.amb(new CrashingMappedIterable>(100, 1, 100, new Function>() { @@ -682,7 +683,7 @@ public Flowable apply(Integer v) throws Exception { return Flowable.never(); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); Flowable.amb(new CrashingMappedIterable>(100, 100, 1, new Function>() { @@ -691,7 +692,7 @@ public Flowable apply(Integer v) throws Exception { return Flowable.never(); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java index 76d4b034b7..e60d8a03b1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAnyTest.java @@ -32,6 +32,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableAnyTest { @@ -257,7 +258,7 @@ public boolean test(Integer t) { @Test public void testBackpressureIfOneRequestedOneShouldBeDelivered() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Flowable.just(1).any(new Predicate() { @Override public boolean test(Integer v) { @@ -273,7 +274,7 @@ public boolean test(Integer v) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final IllegalArgumentException ex = new IllegalArgumentException(); Flowable.just("Boo!").any(new Predicate() { @@ -523,7 +524,7 @@ public boolean test(Integer t) { @Test public void testBackpressureIfOneRequestedOneShouldBeDeliveredFlowable() { - TestSubscriber ts = new TestSubscriber(1L); + TestSubscriberEx ts = new TestSubscriberEx(1L); Flowable.just(1).any(new Predicate() { @Override public boolean test(Integer v) { @@ -539,7 +540,7 @@ public boolean test(Integer v) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessageFlowable() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final IllegalArgumentException ex = new IllegalArgumentException(); Flowable.just("Boo!").any(new Predicate() { @@ -628,7 +629,7 @@ protected void subscribeActual(Subscriber subscriber) { } } .any(Functions.alwaysTrue()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java index a297911040..5a383d3c3c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableAsObservableTest.java @@ -24,6 +24,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class FlowableAsObservableTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java index 636d7bcd28..138a1b0b10 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBlockingTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableBlockingTest { @@ -466,7 +467,7 @@ public void utilityClass() { @Test public void disposeUpFront() { TestSubscriber ts = new TestSubscriber(); - ts.dispose(); + ts.cancel(); Flowable.just(1).blockingSubscribe(ts); ts.assertEmpty(); @@ -482,7 +483,7 @@ public void delayed() throws Exception { @SuppressWarnings("unchecked") @Override public void run() { - ts.dispose(); + ts.cancel(); s[0].onNext(1); } }, 200, TimeUnit.MILLISECONDS); @@ -495,7 +496,7 @@ protected void subscribeActual(Subscriber subscriber) { } }.blockingSubscribe(ts); - while (!ts.isDisposed()) { + while (!ts.isCancelled()) { Thread.sleep(100); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java index 21c25202d4..3b7e55c819 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableBufferTest.java @@ -39,6 +39,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableBufferTest { @@ -364,7 +365,7 @@ public void accept(List pv) { inOrder.verify(subscriber, times(5)).onNext(Arrays. asList()); - ts.dispose(); + ts.cancel(); scheduler.advanceTimeBy(999, TimeUnit.MILLISECONDS); @@ -1445,7 +1446,7 @@ public Collection get() throws Exception { assertTrue(pp.hasSubscribers()); - ts.dispose(); + ts.cancel(); assertFalse(pp.hasSubscribers()); } @@ -2137,7 +2138,7 @@ public Publisher apply(Long a) { return Flowable.just(a).delay(100, TimeUnit.MILLISECONDS); } }) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .awaitDone(3, TimeUnit.SECONDS) .assertComplete(); @@ -2160,7 +2161,7 @@ public Publisher apply(Long a) { return Flowable.just(a).delay(200, TimeUnit.MILLISECONDS); } }) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .awaitDone(3, TimeUnit.SECONDS) .assertComplete(); @@ -2560,7 +2561,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("second")); } })) - .test() + .to(TestHelper.>testConsumer()) .assertError(TestException.class) .assertErrorMessage("first") .assertNotComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java index 328c28b374..7b56cc7781 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCacheTest.java @@ -23,13 +23,14 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableCacheTest { @Test @@ -38,7 +39,7 @@ public void testColdReplayNoBackpressure() { assertFalse("Source is connected!", source.isConnected()); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.subscribe(ts); @@ -78,7 +79,7 @@ public void testColdReplayBackpressure() { assertEquals((Integer)i, onNextEvents.get(i)); } - ts.dispose(); + ts.cancel(); assertFalse("Subscribers retained!", source.hasSubscribers()); } @@ -165,7 +166,7 @@ public void testAsync() { cached.observeOn(Schedulers.computation()).subscribe(ts1); - ts1.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts1.awaitDone(2, TimeUnit.SECONDS); ts1.assertNoErrors(); ts1.assertComplete(); assertEquals(10000, ts1.values().size()); @@ -173,7 +174,7 @@ public void testAsync() { TestSubscriber ts2 = new TestSubscriber(); cached.observeOn(Schedulers.computation()).subscribe(ts2); - ts2.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts2.awaitDone(2, TimeUnit.SECONDS); ts2.assertNoErrors(); ts2.assertComplete(); assertEquals(10000, ts2.values().size()); @@ -202,7 +203,7 @@ public void testAsyncComeAndGo() { } int j = 0; for (TestSubscriber ts : list) { - ts.awaitTerminalEvent(3, TimeUnit.SECONDS); + ts.awaitDone(3, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertComplete(); @@ -233,7 +234,7 @@ public void subscribe(Subscriber t) { TestSubscriber ts = new TestSubscriber(); firehose.cache().observeOn(Schedulers.computation()).takeLast(100).subscribe(ts); - ts.awaitTerminalEvent(3, TimeUnit.SECONDS); + ts.awaitDone(3, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertComplete(); @@ -323,7 +324,7 @@ public void subscribeEmitRace() { cache.test(); - final TestSubscriber ts = new TestSubscriber(); + final TestSubscriberEx ts = new TestSubscriberEx(); Runnable r1 = new Runnable() { @Override @@ -461,8 +462,8 @@ public void subscribeSubscribeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final Flowable cache = Flowable.range(1, 500).cache(); - final TestSubscriber ts1 = new TestSubscriber(); - final TestSubscriber ts2 = new TestSubscriber(); + final TestSubscriberEx ts1 = new TestSubscriberEx(); + final TestSubscriberEx ts2 = new TestSubscriberEx(); Runnable r1 = new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java index 4506f67afe..95ad8b554f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCastTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableCastTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java index 4443a71759..b9067a8f1e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCombineLatestTest.java @@ -36,6 +36,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableCombineLatestTest { @@ -761,7 +762,7 @@ public void testBackpressure() { .observeOn(Schedulers.computation()) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); List events = ts.values(); assertEquals("two2", events.get(0)); @@ -1271,12 +1272,12 @@ public void onErrorRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriber ts = Flowable.combineLatest(pp1, pp2, new BiFunction() { + TestSubscriberEx ts = Flowable.combineLatest(pp1, pp2, new BiFunction() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a; } - }).test(); + }).to(TestHelper.testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); @@ -1296,7 +1297,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.errorCount() != 0) { + if (ts.errors().size() != 0) { if (ts.errors().get(0) instanceof CompositeException) { ts.assertSubscribed() .assertNotComplete() @@ -1512,7 +1513,7 @@ public void run() throws Exception { testScheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - testObserver.awaitTerminalEvent(); + testObserver.awaitDone(5, TimeUnit.SECONDS); assertTrue(errors.toString(), errors.isEmpty()); } finally { @@ -1556,7 +1557,7 @@ public Integer apply(Integer t1, Integer t2) throws Exception { @Test public void fusedNullCheck() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.combineLatest(Flowable.just(1), Flowable.just(2), new BiFunction() { @Override @@ -1567,7 +1568,7 @@ public Integer apply(Integer t1, Integer t2) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFusionMode(QueueFuseable.ASYNC) .assertFailureAndMessage(NullPointerException.class, "The combiner returned a null value"); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java index 7d343c1f3d..d4477cf7e7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatDelayErrorTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; public class FlowableConcatDelayErrorTest { @@ -231,7 +232,7 @@ public void concatDelayErrorFlowable() { @Test public void concatDelayErrorFlowableError() { - TestSubscriber ts = TestSubscriber.create(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.concatDelayError( withError(Flowable.just(withError(Flowable.just(1)), withError(Flowable.just(2))))) @@ -268,7 +269,7 @@ public void concatDelayErrorIterable() { @SuppressWarnings("unchecked") @Test public void concatDelayErrorIterableError() { - TestSubscriber ts = TestSubscriber.create(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.concatDelayError( Arrays.asList(withError(Flowable.just(1)), withError(Flowable.just(2)))) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java index 11f12fb4a3..1040346702 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapEagerTest.java @@ -23,7 +23,7 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,6 +32,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableConcatMapEagerTest { @@ -157,13 +158,13 @@ public void mainErrorsDelayBoundary() { PublishProcessor main = PublishProcessor.create(); final PublishProcessor inner = PublishProcessor.create(); - TestSubscriber ts = main.concatMapEagerDelayError( + TestSubscriberEx ts = main.concatMapEagerDelayError( new Function>() { @Override public Publisher apply(Integer t) { return inner; } - }, false).test(); + }, false).to(TestHelper.testConsumer()); main.onNext(1); @@ -186,13 +187,13 @@ public void mainErrorsDelayEnd() { PublishProcessor main = PublishProcessor.create(); final PublishProcessor inner = PublishProcessor.create(); - TestSubscriber ts = main.concatMapEagerDelayError( + TestSubscriberEx ts = main.concatMapEagerDelayError( new Function>() { @Override public Publisher apply(Integer t) { return inner; } - }, true).test(); + }, true).to(TestHelper.testConsumer()); main.onNext(1); main.onNext(2); @@ -216,13 +217,13 @@ public void mainErrorsImmediate() { PublishProcessor main = PublishProcessor.create(); final PublishProcessor inner = PublishProcessor.create(); - TestSubscriber ts = main.concatMapEager( + TestSubscriberEx ts = main.concatMapEager( new Function>() { @Override public Publisher apply(Integer t) { return inner; } - }).test(); + }).to(TestHelper.testConsumer()); main.onNext(1); main.onNext(2); @@ -861,12 +862,12 @@ public void innerOuterRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriber ts = pp1.concatMapEager(new Function>() { + TestSubscriberEx ts = pp1.concatMapEager(new Function>() { @Override public Flowable apply(Integer v) throws Exception { return pp2; } - }).test(); + }).to(TestHelper.testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); @@ -1078,7 +1079,7 @@ protected void subscribeActual(Subscriber s) { } } .concatMapEager(Functions.justFunction(Flowable.just(1))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First", 1); sub[0].onError(new TestException("Second")); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java index eba09e564f..b6110fddca 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatMapTest.java @@ -27,6 +27,7 @@ import io.reactivex.internal.operators.flowable.FlowableConcatMap.WeakScalarSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableConcatMapTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java index 772f559733..d6451daaf6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatTest.java @@ -36,6 +36,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableConcatTest { @@ -415,7 +416,7 @@ public void testConcatUnsubscribe() { //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext once. callOnce.await(); // Unsubcribe - ts.dispose(); + ts.cancel(); //Unblock the observable to continue. okToContinue.countDown(); w1.t.join(); @@ -459,7 +460,7 @@ public void testConcatUnsubscribeConcurrent() { //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext exactly once. callOnce.await(); //"four" from w2 has been processed by onNext() - ts.dispose(); + ts.cancel(); //"five" and "six" will NOT be processed by onNext() //Unblock the observable to continue. okToContinue.countDown(); @@ -679,9 +680,9 @@ public void testInnerBackpressureWithAlignedBoundaries() { .observeOn(Schedulers.computation()) // observeOn has a backpressured RxRingBuffer .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.values().size()); } /* @@ -698,9 +699,9 @@ public void testInnerBackpressureWithoutAlignedBoundaries() { .observeOn(Schedulers.computation()) // observeOn has a backpressured RxRingBuffer .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals((Flowable.bufferSize() * 4) + 20, ts.valueCount()); + assertEquals((Flowable.bufferSize() * 4) + 20, ts.values().size()); } // https://github.com/ReactiveX/RxJava/issues/1818 @@ -718,9 +719,9 @@ public void subscribe(Subscriber s) { }); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.concat(f, f).subscribe(ts); - ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + ts.awaitDone(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertNoErrors(); ts.assertValues("hello", "hello"); @@ -814,7 +815,7 @@ public void concatMapRangeAsyncLoopIssue2876() { if (i % 1000 == 0) { System.out.println("concatMapRangeAsyncLoop > " + i); } - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(0, 1000) .concatMap(new Function>() { @Override @@ -824,10 +825,10 @@ public Flowable apply(Integer t) { }) .observeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + ts.awaitDone(2500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertNoErrors(); - assertEquals(1000, ts.valueCount()); + assertEquals(1000, ts.values().size()); assertEquals((Integer)999, ts.values().get(999)); } } @@ -843,7 +844,7 @@ public void arrayDelayError() { Flowable.empty() }; - TestSubscriber ts = Flowable.concatArrayDelayError(sources).test(); + TestSubscriberEx ts = Flowable.concatArrayDelayError(sources).to(TestHelper.testConsumer()); ts.assertFailure(CompositeException.class, 1, 2, 3, 4); @@ -1324,7 +1325,7 @@ public Publisher apply(Flowable f) throws Exception { public void immediateInnerNextOuterError() { final PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = new TestSubscriber() { + final TestSubscriberEx ts = new TestSubscriberEx() { @Override public void onNext(Integer t) { super.onNext(t); @@ -1348,7 +1349,7 @@ public void onNext(Integer t) { public void immediateInnerNextOuterError2() { final PublishProcessor pp = PublishProcessor.create(); - final TestSubscriber ts = new TestSubscriber() { + final TestSubscriberEx ts = new TestSubscriberEx() { @Override public void onNext(Integer t) { super.onNext(t); @@ -1398,7 +1399,7 @@ public Object apply(Flowable f) throws Exception { public void badInnerSource() { @SuppressWarnings("rawtypes") final Subscriber[] ts0 = { null }; - TestSubscriber ts = Flowable.just(1).hide().concatMap(Functions.justFunction(new Flowable() { + TestSubscriberEx ts = Flowable.just(1).hide().concatMap(Functions.justFunction(new Flowable() { @Override protected void subscribeActual(Subscriber s) { ts0[0] = s; @@ -1406,7 +1407,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("First")); } })) - .test(); + .to(TestHelper.testConsumer()); ts.assertFailureAndMessage(TestException.class, "First"); @@ -1424,7 +1425,7 @@ protected void subscribeActual(Subscriber s) { public void badInnerSourceDelayError() { @SuppressWarnings("rawtypes") final Subscriber[] ts0 = { null }; - TestSubscriber ts = Flowable.just(1).hide().concatMapDelayError(Functions.justFunction(new Flowable() { + TestSubscriberEx ts = Flowable.just(1).hide().concatMapDelayError(Functions.justFunction(new Flowable() { @Override protected void subscribeActual(Subscriber s) { ts0[0] = s; @@ -1432,7 +1433,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("First")); } })) - .test(); + .to(TestHelper.testConsumer()); ts.assertFailureAndMessage(TestException.class, "First"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java index 681f9d91f3..b1afdb7e89 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableConcatWithCompletableTest.java @@ -27,6 +27,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.CompletableSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableConcatWithCompletableTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java index 998569148d..5c1e7f281a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCountTest.java @@ -17,6 +17,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class FlowableCountTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java index 899f145ca2..f989c91d8d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableCreateTest.java @@ -16,9 +16,7 @@ import static org.junit.Assert.*; import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import org.junit.Test; import org.reactivestreams.*; @@ -29,7 +27,7 @@ import io.reactivex.functions.Cancellable; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableCreateTest { @@ -702,8 +700,9 @@ public void run() { TestHelper.race(r1, r2); } }, m) - .test() - .assertSubscribed().assertNotComplete() + .to(TestHelper.testConsumer()) + .assertSubscribed() + .assertNotComplete() .assertError(TestException.class); } } @@ -917,15 +916,18 @@ public void run() { } }, m) .take(TestHelper.RACE_DEFAULT_LOOPS) - .test() - .assertSubscribed().assertValueCount(TestHelper.RACE_DEFAULT_LOOPS).assertComplete().assertNoErrors(); + .to(TestHelper.testConsumer()) + .assertSubscribed() + .assertValueCount(TestHelper.RACE_DEFAULT_LOOPS) + .assertComplete() + .assertNoErrors(); } } @Test public void serializedConcurrentOnNextOnComplete() { for (BackpressureStrategy m : BackpressureStrategy.values()) { - TestSubscriber ts = Flowable.create(new FlowableOnSubscribe() { + TestSubscriberEx ts = Flowable.create(new FlowableOnSubscribe() { @Override public void subscribe(FlowableEmitter e) throws Exception { final FlowableEmitter f = e.serialize(); @@ -952,11 +954,12 @@ public void run() { TestHelper.race(r1, r2); } }, m) - .test() - .assertSubscribed().assertComplete() + .to(TestHelper.testConsumer()) + .assertSubscribed() + .assertComplete() .assertNoErrors(); - int c = ts.valueCount(); + int c = ts.values().size(); assertTrue("" + c, c >= 100); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java index 8df7c9c193..45f71cab5d 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDebounceTest.java @@ -36,6 +36,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableDebounceTest { @@ -288,7 +289,7 @@ public Flowable apply(Integer t1) { @Test public void debounceWithTimeBackpressure() throws InterruptedException { TestScheduler scheduler = new TestScheduler(); - TestSubscriber subscriber = new TestSubscriber(); + TestSubscriberEx subscriber = new TestSubscriberEx(); Flowable.merge( Flowable.just(1), Flowable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler) @@ -308,7 +309,7 @@ public void debounceDefaultScheduler() throws Exception { Flowable.range(1, 1000).debounce(1, TimeUnit.SECONDS).subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValue(1000); ts.assertNoErrors(); ts.assertComplete(); @@ -438,7 +439,7 @@ public Flowable apply(Integer o) throws Exception { .subscribeWith(ts) .assertEmpty(); - assertTrue(ts.isDisposed()); + assertTrue(ts.isCancelled()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java index 4c75d500e8..19da222eb9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDefaultIfEmptyTest.java @@ -13,14 +13,16 @@ package io.reactivex.internal.operators.flowable; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import org.junit.*; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.DefaultSubscriber; +import io.reactivex.testsupport.*; public class FlowableDefaultIfEmptyTest { @@ -84,7 +86,7 @@ public void onComplete() { @Test public void testBackpressureEmpty() { - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); Flowable.empty().defaultIfEmpty(1).subscribe(ts); ts.assertNoValues(); ts.assertNotTerminated(); @@ -96,7 +98,7 @@ public void testBackpressureEmpty() { @Test public void testBackpressureNonEmpty() { - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); Flowable.just(1, 2, 3).defaultIfEmpty(1).subscribe(ts); ts.assertNoValues(); ts.assertNotTerminated(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java index 2b16044e76..31a0193b42 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDeferTest.java @@ -22,6 +22,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Supplier; +import io.reactivex.testsupport.TestHelper; @SuppressWarnings("unchecked") public class FlowableDeferTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java index e61c3f7905..fb513140e5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelaySubscriptionOtherTest.java @@ -24,6 +24,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableDelaySubscriptionOtherTest { @Test @@ -255,7 +256,7 @@ public void unsubscriptionPropagatesBeforeSubscribe() { Assert.assertFalse("source subscribed?", source.hasSubscribers()); Assert.assertTrue("other not subscribed?", other.hasSubscribers()); - ts.dispose(); + ts.cancel(); Assert.assertFalse("source subscribed?", source.hasSubscribers()); Assert.assertFalse("other still subscribed?", other.hasSubscribers()); @@ -278,7 +279,7 @@ public void unsubscriptionPropagatesAfterSubscribe() { Assert.assertTrue("source not subscribed?", source.hasSubscribers()); Assert.assertFalse("other still subscribed?", other.hasSubscribers()); - ts.dispose(); + ts.cancel(); Assert.assertFalse("source subscribed?", source.hasSubscribers()); Assert.assertFalse("other still subscribed?", other.hasSubscribers()); @@ -340,7 +341,7 @@ public void subscribe(FlowableEmitter emitter) throws Exception { .delaySubscription(100, TimeUnit.MILLISECONDS, s) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValue(false); } } finally { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java index 47d15ed3d4..bc9b2eb169 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDelayTest.java @@ -32,6 +32,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableDelayTest { private Subscriber subscriber; @@ -220,7 +221,7 @@ public void testDelaySubscriptionCancelBeforeTime() { TestSubscriber ts = new TestSubscriber(subscriber); result.subscribe(ts); - ts.dispose(); + ts.cancel(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); verify(subscriber, never()).onNext(any()); @@ -654,9 +655,9 @@ public Integer apply(Integer t) { }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } @Test @@ -683,9 +684,9 @@ public Integer apply(Integer t) { }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } @Test @@ -718,9 +719,9 @@ public Integer apply(Integer t) { }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } @Test @@ -759,9 +760,9 @@ public Integer apply(Integer t) { }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); } @Test @@ -906,7 +907,7 @@ public void testDelaySubscriptionDisposeBeforeTime() { TestSubscriber ts = new TestSubscriber(subscriber); result.subscribe(ts); - ts.dispose(); + ts.cancel(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); verify(subscriber, never()).onNext(any()); @@ -1026,7 +1027,7 @@ public Publisher apply(Integer t) throws Exception { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The itemDelay returned a null Publisher"); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java index 66fd932dcc..abd5628ee8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDematerializeTest.java @@ -27,7 +27,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; @SuppressWarnings("deprecation") public class FlowableDematerializeTest { @@ -142,7 +142,7 @@ public void testCompletePassThru() { Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(subscriber); + TestSubscriberEx ts = new TestSubscriberEx(subscriber); dematerialize.subscribe(ts); System.out.println(ts.errors()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java index 2b5bcea1e6..ceede9a7cf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDetachTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableDetachTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java index a33aa6c219..169ccee21e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctTest.java @@ -31,7 +31,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.UnicastProcessor; -import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableDistinctTest { @@ -142,19 +142,19 @@ public void error() { @Test public void fusedSync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1, 1, 2, 1, 3, 2, 4, 5, 4) .distinct() .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void fusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor us = UnicastProcessor.create(); @@ -164,7 +164,7 @@ public void fusedAsync() { TestHelper.emit(us, 1, 1, 2, 1, 3, 2, 4, 5, 4); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); } @@ -220,7 +220,7 @@ public Collection get() throws Exception { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java index 7c5eb993e1..7bc72514c6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDistinctUntilChangedTest.java @@ -24,15 +24,16 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableDistinctUntilChangedTest { @@ -182,9 +183,9 @@ public boolean test(Integer a, Integer b) { return a.equals(b); } }) - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 2, 4, 1, 2); } @@ -203,9 +204,9 @@ public boolean test(Integer v) { return true; } }) - .to(SubscriberFusion.test(Long.MAX_VALUE, QueueFuseable.ANY, false)) - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testSubscriber(Long.MAX_VALUE, QueueFuseable.ANY, false)) + .assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 2, 4, 1, 2); } @@ -272,7 +273,7 @@ public boolean test(String a, String b) { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1, 2, 2, 3, 3, 4, 5) .distinctUntilChanged(new BiPredicate() { @@ -283,15 +284,15 @@ public boolean test(Integer a, Integer b) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5) ; } @Test public void fusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); @@ -306,8 +307,8 @@ public boolean test(Integer a, Integer b) throws Exception { TestHelper.emit(up, 1, 2, 2, 3, 3, 4, 5); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5) ; } @@ -438,7 +439,7 @@ public boolean test(Integer v) throws Exception { @Test public void conditionalFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1, 2, 1, 3, 3, 4, 3, 5, 5) .distinctUntilChanged() @@ -450,13 +451,13 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(2, 4); } @Test public void conditionalAsyncFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); up @@ -471,7 +472,7 @@ public boolean test(Integer v) throws Exception { TestHelper.emit(up, 1, 2, 1, 3, 3, 4, 3, 5, 5); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(2, 4); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNextTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNextTest.java index 338d0b0f50..51d7c76709 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterNextTest.java @@ -19,13 +19,14 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.processors.UnicastProcessor; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableDoAfterNextTest { @@ -88,13 +89,13 @@ public void empty() { @Test public void syncFused() { - TestSubscriber ts0 = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts0 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5) .doAfterNext(afterNext) .subscribe(ts0); - SubscriberFusion.assertFusion(ts0, QueueFuseable.SYNC) + ts0.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -102,13 +103,13 @@ public void syncFused() { @Test public void asyncFusedRejected() { - TestSubscriber ts0 = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts0 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.range(1, 5) .doAfterNext(afterNext) .subscribe(ts0); - SubscriberFusion.assertFusion(ts0, QueueFuseable.NONE) + ts0.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -116,7 +117,7 @@ public void asyncFusedRejected() { @Test public void asyncFused() { - TestSubscriber ts0 = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts0 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); UnicastProcessor up = UnicastProcessor.create(); @@ -126,7 +127,7 @@ public void asyncFused() { .doAfterNext(afterNext) .subscribe(ts0); - SubscriberFusion.assertFusion(ts0, QueueFuseable.ASYNC) + ts0.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -183,14 +184,14 @@ public void emptyConditional() { @Test public void syncFusedConditional() { - TestSubscriber ts0 = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts0 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5) .doAfterNext(afterNext) .filter(Functions.alwaysTrue()) .subscribe(ts0); - SubscriberFusion.assertFusion(ts0, QueueFuseable.SYNC) + ts0.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -198,14 +199,14 @@ public void syncFusedConditional() { @Test public void asyncFusedRejectedConditional() { - TestSubscriber ts0 = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts0 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.range(1, 5) .doAfterNext(afterNext) .filter(Functions.alwaysTrue()) .subscribe(ts0); - SubscriberFusion.assertFusion(ts0, QueueFuseable.NONE) + ts0.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -213,7 +214,7 @@ public void asyncFusedRejectedConditional() { @Test public void asyncFusedConditional() { - TestSubscriber ts0 = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts0 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); UnicastProcessor up = UnicastProcessor.create(); @@ -224,7 +225,7 @@ public void asyncFusedConditional() { .filter(Functions.alwaysTrue()) .subscribe(ts0); - SubscriberFusion.assertFusion(ts0, QueueFuseable.ASYNC) + ts0.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java index b692c30b6a..2263c16577 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoAfterTerminateTest.java @@ -29,6 +29,7 @@ import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableDoAfterTerminateTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java index 93dd960cf3..7f65c996cb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoFinallyTest.java @@ -27,7 +27,7 @@ import io.reactivex.internal.fuseable.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.UnicastProcessor; -import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableDoFinallyTest implements Action { @@ -97,13 +97,13 @@ public Publisher apply(Flowable f) throws Exception { @Test public void syncFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5) .doFinally(this) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -111,13 +111,13 @@ public void syncFused() { @Test public void syncFusedBoundary() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); Flowable.range(1, 5) .doFinally(this) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -125,7 +125,7 @@ public void syncFusedBoundary() { @Test public void asyncFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); UnicastProcessor up = UnicastProcessor.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -134,7 +134,7 @@ public void asyncFused() { .doFinally(this) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -142,7 +142,7 @@ public void asyncFused() { @Test public void asyncFusedBoundary() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); UnicastProcessor up = UnicastProcessor.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -151,7 +151,7 @@ public void asyncFusedBoundary() { .doFinally(this) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -204,14 +204,14 @@ public void normalTakeConditional() { @Test public void syncFusedConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5) .doFinally(this) .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -219,13 +219,13 @@ public void syncFusedConditional() { @Test public void nonFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5).hide() .doFinally(this) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -233,14 +233,14 @@ public void nonFused() { @Test public void nonFusedConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5).hide() .doFinally(this) .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -248,14 +248,14 @@ public void nonFusedConditional() { @Test public void syncFusedBoundaryConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); Flowable.range(1, 5) .doFinally(this) .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -263,7 +263,7 @@ public void syncFusedBoundaryConditional() { @Test public void asyncFusedConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); UnicastProcessor up = UnicastProcessor.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -273,7 +273,7 @@ public void asyncFusedConditional() { .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -281,7 +281,7 @@ public void asyncFusedConditional() { @Test public void asyncFusedBoundaryConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); UnicastProcessor up = UnicastProcessor.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -291,7 +291,7 @@ public void asyncFusedBoundaryConditional() { .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java index 4a9ac3eca2..232e65acea 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnEachTest.java @@ -33,7 +33,8 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.UnicastProcessor; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableDoOnEachTest { @@ -203,7 +204,7 @@ public void testFatalError() { @Test public void onErrorThrows() { - TestSubscriber ts = TestSubscriber.create(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.error(new TestException()) .doOnError(new Consumer() { @@ -485,7 +486,7 @@ public void run() throws Exception { @Test public void onErrorOnErrorCrashConditional() { - TestSubscriber ts = Flowable.error(new TestException("Outer")) + TestSubscriberEx ts = Flowable.error(new TestException("Outer")) .doOnError(new Consumer() { @Override public void accept(Throwable e) throws Exception { @@ -493,7 +494,7 @@ public void accept(Throwable e) throws Exception { } }) .filter(Functions.alwaysTrue()) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -504,7 +505,7 @@ public void accept(Throwable e) throws Exception { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -523,8 +524,8 @@ public void run() throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -533,7 +534,7 @@ public void run() throws Exception { @Test public void fusedOnErrorCrash() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0 }; @@ -552,8 +553,8 @@ public void run() throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertFailure(TestException.class); assertEquals(0, call[0]); @@ -561,7 +562,7 @@ public void run() throws Exception { @Test public void fusedConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -581,8 +582,8 @@ public void run() throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -591,7 +592,7 @@ public void run() throws Exception { @Test public void fusedOnErrorCrashConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0 }; @@ -611,8 +612,8 @@ public void run() throws Exception { .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertFailure(TestException.class); assertEquals(0, call[0]); @@ -620,7 +621,7 @@ public void run() throws Exception { @Test public void fusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -643,8 +644,8 @@ public void run() throws Exception { TestHelper.emit(up, 1, 2, 3, 4, 5); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -653,7 +654,7 @@ public void run() throws Exception { @Test public void fusedAsyncConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -677,8 +678,8 @@ public void run() throws Exception { TestHelper.emit(up, 1, 2, 3, 4, 5); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -687,7 +688,7 @@ public void run() throws Exception { @Test public void fusedAsyncConditional2() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -711,8 +712,8 @@ public void run() throws Exception { TestHelper.emit(up, 1, 2, 3, 4, 5); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -751,7 +752,7 @@ public void accept(Throwable e) throws Exception { }) .publish(); - TestSubscriber ts = cf.test(); + TestSubscriberEx ts = cf.to(TestHelper.testConsumer()); cf.connect(); ts.assertFailure(CompositeException.class); @@ -787,7 +788,7 @@ public void accept(Throwable e) throws Exception { }) .publish(); - TestSubscriber ts = cf.test(); + TestSubscriberEx ts = cf.to(TestHelper.testConsumer()); cf.connect(); ts.assertFailure(CompositeException.class); @@ -819,7 +820,7 @@ public void accept(Throwable e) throws Exception { }) .publish(); - TestSubscriber ts = cf.test(); + TestSubscriberEx ts = cf.to(TestHelper.testConsumer()); cf.connect(); ts.assertFailure(CompositeException.class); @@ -847,7 +848,7 @@ public void accept(Throwable e) throws Exception { .filter(Functions.alwaysTrue()) .publish(); - TestSubscriber ts = cf.test(); + TestSubscriberEx ts = cf.to(TestHelper.testConsumer()); cf.connect(); ts.assertFailure(CompositeException.class); @@ -880,7 +881,7 @@ public void accept(Throwable e) throws Exception { .filter(Functions.alwaysTrue()) .publish(); - TestSubscriber ts = cf.test(); + TestSubscriberEx ts = cf.to(TestHelper.testConsumer()); cf.connect(); ts.assertFailure(CompositeException.class); @@ -918,7 +919,7 @@ public void accept(Throwable e) throws Exception { .filter(Functions.alwaysTrue()) .publish(); - TestSubscriber ts = cf.test(); + TestSubscriberEx ts = cf.to(TestHelper.testConsumer()); cf.connect(); ts.assertFailure(CompositeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java index 34578bbfee..7a966cadec 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnLifecycleTest.java @@ -26,6 +26,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class FlowableDoOnLifecycleTest { @@ -155,7 +156,7 @@ public void accept(Subscription s) throws Exception { throw new TestException("First"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(bs.isCancelled()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java index de1bd0d57a..2fc2bf1e08 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableDoOnUnsubscribeTest.java @@ -22,7 +22,7 @@ import org.junit.Test; import io.reactivex.Flowable; -import io.reactivex.disposables.Disposable; +import io.reactivex.disposables.*; import io.reactivex.functions.*; import io.reactivex.processors.BehaviorProcessor; import io.reactivex.subscribers.TestSubscriber; @@ -72,7 +72,7 @@ public void run() { for (int i = 0; i < subCount; ++i) { TestSubscriber subscriber = new TestSubscriber(); - subscriptions.add(subscriber); + subscriptions.add(Disposables.fromSubscription(subscriber)); longs.subscribe(subscriber); subscribers.add(subscriber); } @@ -134,7 +134,7 @@ public void run() { for (int i = 0; i < subCount; ++i) { TestSubscriber subscriber = new TestSubscriber(); longs.subscribe(subscriber); - subscriptions.add(subscriber); + subscriptions.add(Disposables.fromSubscription(subscriber)); subscribers.add(subscriber); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java index d5665d6bf3..082fa91352 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableElementAtTest.java @@ -29,6 +29,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class FlowableElementAtTest { @@ -140,7 +141,7 @@ public void elementAtOrErrorInvalidIndex() { public void elementAtOrErrorError() { Flowable.error(new RuntimeException("error")) .elementAtOrError(0) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java index 85093c4576..69a731b6ac 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFilterTest.java @@ -24,7 +24,7 @@ import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,7 +32,8 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableFilterTest { @@ -245,35 +246,35 @@ public void conditionalNone2() { @Test public void conditionalFusedSync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .filter(Functions.alwaysTrue()) .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void conditionalFusedSync2() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .filter(Functions.alwaysFalse()) .filter(Functions.alwaysFalse()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(); } @Test public void conditionalFusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); @@ -289,14 +290,14 @@ public void conditionalFusedAsync() { up.onNext(5); up.onComplete(); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void conditionalFusedNoneAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); @@ -312,14 +313,14 @@ public void conditionalFusedNoneAsync() { up.onNext(5); up.onComplete(); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } @Test public void conditionalFusedNoneAsync2() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); @@ -335,8 +336,8 @@ public void conditionalFusedNoneAsync2() { up.onNext(5); up.onComplete(); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } @@ -415,41 +416,41 @@ public boolean test(Integer v) throws Exception { @Test public void syncFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .filter(Functions.alwaysTrue()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void syncNoneFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .filter(Functions.alwaysFalse()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(); } @Test public void syncNoneFused2() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .filter(Functions.alwaysFalse()) .filter(Functions.alwaysFalse()) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(); } @@ -563,7 +564,7 @@ public Flowable apply(Flowable f) throws Exception { @Test public void fusedSync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .filter(new Predicate() { @@ -574,13 +575,13 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(2, 4); } @Test public void fusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor us = UnicastProcessor.create(); @@ -595,13 +596,13 @@ public boolean test(Integer v) throws Exception { TestHelper.emit(us, 1, 2, 3, 4, 5); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(2, 4); } @Test public void fusedReject() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY | QueueFuseable.BOUNDARY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY | QueueFuseable.BOUNDARY); Flowable.range(1, 5) .filter(new Predicate() { @@ -612,7 +613,7 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(2, 4); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java index 3d4eacd281..138f7b5fad 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFirstTest.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.functions.Predicate; +import io.reactivex.testsupport.TestHelper; public class FlowableFirstTest { @@ -539,7 +540,7 @@ public void firstOrErrorMultipleElements() { public void firstOrErrorError() { Flowable.error(new RuntimeException("error")) .firstOrError() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); @@ -580,7 +581,7 @@ public void firstOrErrorErrorFlowable() { Flowable.error(new RuntimeException("error")) .firstOrError() .toFlowable() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java index 62cee79161..e2e7a31ebc 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapCompletableTest.java @@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit; import org.junit.Test; -import org.reactivestreams.*; +import org.reactivestreams.Subscription; import io.reactivex.*; import io.reactivex.disposables.*; @@ -27,10 +27,11 @@ import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableFlatMapCompletableTest { @@ -134,14 +135,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAllFlowable() { - TestSubscriber ts = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) + TestSubscriberEx ts = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true, Integer.MAX_VALUE).toFlowable() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -153,14 +154,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayInnerErrorAllFlowable() { - TestSubscriber ts = Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true, Integer.MAX_VALUE).toFlowable() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -185,7 +186,7 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void fusedFlowable() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 10) .flatMapCompletable(new Function() { @@ -197,8 +198,8 @@ public CompletableSource apply(Integer v) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } @@ -288,14 +289,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAll() { - TestObserver to = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) + TestObserverEx to = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true, Integer.MAX_VALUE) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -307,14 +308,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayInnerErrorAll() { - TestObserver to = Flowable.range(1, 10) + TestObserverEx to = Flowable.range(1, 10) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true, Integer.MAX_VALUE) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -339,7 +340,7 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 10) .flatMapCompletable(new Function() { @@ -352,8 +353,8 @@ public CompletableSource apply(Integer v) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java index aab0940c46..7a5f84f4fe 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapMaybeTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableFlatMapMaybeTest { @@ -75,36 +76,40 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void normalAsync() { - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { return Maybe.just(v).subscribeOn(Schedulers.computation()); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) + .assertValueCount(10) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void normalAsyncMaxConcurrency() { - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { return Maybe.just(v).subscribeOn(Schedulers.computation()); } }, false, 3) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) + .assertValueCount(10) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -167,14 +172,14 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAll() { - TestSubscriber ts = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) + TestSubscriberEx ts = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { return Maybe.error(new TestException()); } }, true, Integer.MAX_VALUE) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -228,7 +233,7 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void takeAsync() { - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { @@ -236,13 +241,14 @@ public MaybeSource apply(Integer v) throws Exception { } }) .take(2) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(2) - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -298,7 +304,7 @@ public MaybeSource apply(Integer v) throws Exception { } }) .take(500) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) @@ -419,7 +425,7 @@ protected void subscribeActual(Subscriber subscriber) { } } .flatMapMaybe(Functions.justFunction(Maybe.just(2))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -441,7 +447,7 @@ protected void subscribeActual(MaybeObserver observer) { observer.onError(new TestException("Second")); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -529,7 +535,7 @@ protected void subscribeActual(MaybeObserver observer) { assertFalse(((Disposable)observer).isDisposed()); - ts.dispose(); + ts.cancel(); assertTrue(((Disposable)observer).isDisposed()); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java index ac137d6c3d..7b19c38a94 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapSingleTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableFlatMapSingleTest { @@ -62,36 +63,39 @@ public SingleSource apply(Integer v) throws Exception { @Test public void normalAsync() { - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { return Single.just(v).subscribeOn(Schedulers.computation()); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) + .assertValueCount(10) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void normalAsyncMaxConcurrency() { - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { return Single.just(v).subscribeOn(Schedulers.computation()); } }, false, 3) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -154,14 +158,14 @@ public SingleSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAll() { - TestSubscriber ts = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) + TestSubscriberEx ts = Flowable.range(1, 10).concatWith(Flowable.error(new TestException())) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { return Single.error(new TestException()); } }, true, Integer.MAX_VALUE) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -215,7 +219,7 @@ public SingleSource apply(Integer v) throws Exception { @Test public void takeAsync() { - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { @@ -223,13 +227,14 @@ public SingleSource apply(Integer v) throws Exception { } }) .take(2) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(2) - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -275,7 +280,7 @@ public SingleSource apply(Integer v) throws Exception { } }) .take(500) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) @@ -339,7 +344,7 @@ protected void subscribeActual(Subscriber subscriber) { } } .flatMapSingle(Functions.justFunction(Single.just(2))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -361,7 +366,7 @@ protected void subscribeActual(SingleObserver observer) { observer.onError(new TestException("Second")); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -415,7 +420,7 @@ protected void subscribeActual(SingleObserver observer) { assertFalse(((Disposable)observer).isDisposed()); - ts.dispose(); + ts.cancel(); assertTrue(((Disposable)observer).isDisposed()); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java index 96ccd95e44..07941dc45f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlatMapTest.java @@ -24,7 +24,7 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,6 +32,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableFlatMapTest { @Test @@ -346,12 +347,12 @@ public Flowable apply(Integer t1) { source.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); Set expected = new HashSet(Arrays.asList( 10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101 )); - Assert.assertEquals(expected.size(), ts.valueCount()); + Assert.assertEquals(expected.size(), ts.values().size()); Assert.assertTrue(expected.containsAll(ts.values())); } @@ -377,13 +378,13 @@ public Integer apply(Integer t1, Integer t2) { source.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); Set expected = new HashSet(Arrays.asList( 1010, 1011, 2020, 2021, 3030, 3031, 4040, 4041, 5050, 5051, 6060, 6061, 7070, 7071, 8080, 8081, 9090, 9091, 10100, 10101 )); - Assert.assertEquals(expected.size(), ts.valueCount()); + Assert.assertEquals(expected.size(), ts.values().size()); System.out.println("--> testFlatMapSelectorMaxConcurrent: " + ts.values()); Assert.assertTrue(expected.containsAll(ts.values())); } @@ -419,14 +420,14 @@ public void testFlatMapTransformsMaxConcurrentNormal() { Flowable source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber subscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(subscriber); + TestSubscriberEx ts = new TestSubscriberEx(subscriber); Function> just = just(onNext); Function> just2 = just(onError); Supplier> just0 = just0(onComplete); source.flatMap(just, just2, just0, m).subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertTerminated(); @@ -447,7 +448,7 @@ public void flatMapRangeAsyncLoop() { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); } - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(0, 1000) .flatMap(new Function>() { @Override @@ -458,9 +459,9 @@ public Flowable apply(Integer t) { .observeOn(Schedulers.computation()) .subscribe(ts); - ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + ts.awaitDone(2500, TimeUnit.MILLISECONDS); if (ts.completions() == 0) { - System.out.println(ts.valueCount()); + System.out.println(ts.values().size()); } ts.assertTerminated(); ts.assertNoErrors(); @@ -485,7 +486,7 @@ public void flatMapRangeMixedAsyncLoop() { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); } - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(0, 1000) .flatMap(new Function>() { final Random rnd = new Random(); @@ -501,9 +502,9 @@ public Flowable apply(Integer t) { .observeOn(Schedulers.computation()) .subscribe(ts); - ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + ts.awaitDone(2500, TimeUnit.MILLISECONDS); if (ts.completions() == 0) { - System.out.println(ts.valueCount()); + System.out.println(ts.values().size()); } ts.assertTerminated(); ts.assertNoErrors(); @@ -532,7 +533,7 @@ public Flowable apply(Integer t) { } }).subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertComplete(); ts.assertValueCount(1000); @@ -878,7 +879,7 @@ public Object apply(Integer w) throws Exception { @Test public void fusedInnerThrows2() { - TestSubscriber ts = Flowable.range(1, 2).hide() + TestSubscriberEx ts = Flowable.range(1, 2).hide() .flatMap(new Function>() { @Override public Flowable apply(Integer v) throws Exception { @@ -890,7 +891,7 @@ public Integer apply(Integer w) throws Exception { }); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.errorList(ts); @@ -1020,7 +1021,7 @@ public Object apply(Integer v, Object w) throws Exception { return v; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The mapper returned a null Iterable"); } @@ -1038,7 +1039,7 @@ public Object apply(Integer v, Object w) throws Exception { return v; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The mapper returned a null Publisher"); } @@ -1119,7 +1120,7 @@ public void accept(Integer v) throws Exception { assertTrue(pp3.hasSubscribers()); assertTrue(pp4.hasSubscribers()); - ts.dispose(); + ts.cancel(); assertFalse(pp3.hasSubscribers()); assertFalse(pp4.hasSubscribers()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java index f3a7cced77..40dd305947 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFlattenIterableTest.java @@ -32,7 +32,8 @@ import io.reactivex.internal.util.ExceptionHelper; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableFlattenIterableTest { @@ -672,7 +673,7 @@ public void smallPrefetch2() { @Test public void mixedInnerSource() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1, 2, 3) .flatMapIterable(new Function>() { @@ -686,13 +687,13 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 1, 2); } @Test public void mixedInnerSource2() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1, 2, 3) .flatMapIterable(new Function>() { @@ -706,13 +707,13 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2); } @Test public void fusionRejected() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1, 2, 3).hide() .flatMapIterable(new Function>() { @@ -723,7 +724,7 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 1, 2, 1, 2); } @@ -1030,7 +1031,7 @@ public void cancel() { public void onErrorLate() { List errors = TestHelper.trackPluginErrors(); try { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); FlattenIterableSubscriber f = new FlattenIterableSubscriber(ts, Functions.justFunction(Collections.emptyList()), 128); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java index 53905fe305..26f3537b3f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromArrayTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.ScalarSupplier; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableFromArrayTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java index f3239001ee..fe0e76ca2e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromCallableTest.java @@ -34,6 +34,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableFromCallableTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java index a7cc0770e7..a2e3a2b2b1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromIterableTest.java @@ -34,6 +34,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableFromIterableTest { @@ -124,7 +125,7 @@ public void testBackpressureViaRequest() { } Flowable f = Flowable.fromIterable(list); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.assertNoValues(); ts.request(1); @@ -144,7 +145,7 @@ public void testBackpressureViaRequest() { public void testNoBackpressure() { Flowable f = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.assertNoValues(); ts.request(Long.MAX_VALUE); // infinite @@ -632,7 +633,7 @@ public void normalConditionalBackpressured() { public void normalConditionalBackpressured2() { Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)) .filter(Functions.alwaysTrue()) - .test(4L) + .to(TestHelper.testSubscriber(4L)) .assertSubscribed() .assertValues(1, 2, 3, 4) .assertNoErrors() @@ -700,7 +701,7 @@ public void normalConditionalLong() { Flowable.fromIterable(new CrashingIterable(100, 10 * 1000 * 1000, 10 * 1000 * 1000)) .filter(Functions.alwaysTrue()) .take(1000 * 1000) - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(1000 * 1000) .assertNoErrors() @@ -713,7 +714,7 @@ public void normalConditionalLong2() { .filter(Functions.alwaysTrue()) .rebatchRequests(128) .take(1000 * 1000) - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(1000 * 1000) .assertNoErrors() @@ -868,12 +869,12 @@ public void run() { @Test public void fusionRejected() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.fromIterable(Arrays.asList(1, 2, 3)) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3); } @@ -919,14 +920,14 @@ public void onComplete() { @Test public void iteratorThrows() { Flowable.fromIterable(new CrashingIterable(1, 100, 100)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @Test public void hasNext2Throws() { Flowable.fromIterable(new CrashingIterable(100, 2, 100)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromObservableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromObservableTest.java index 748ee2ac2d..94ec9fe837 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromObservableTest.java @@ -17,6 +17,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; +import io.reactivex.testsupport.TestHelper; public class FlowableFromObservableTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java index b2452a65fb..678f3f8923 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableFromSourceTest.java @@ -16,7 +16,7 @@ import java.util.List; import org.junit.*; -import org.reactivestreams.*; +import org.reactivestreams.Subscription; import io.reactivex.*; import io.reactivex.exceptions.*; @@ -24,6 +24,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableFromSourceTest { @@ -31,13 +32,13 @@ public class FlowableFromSourceTest { PublishAsyncEmitterNoCancel sourceNoCancel; - TestSubscriber ts; + TestSubscriberEx ts; @Before public void before() { source = new PublishAsyncEmitter(); sourceNoCancel = new PublishAsyncEmitterNoCancel(); - ts = new TestSubscriber(0L); + ts = new TestSubscriberEx(0L); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGenerateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGenerateTest.java index 2689e7d3dc..d8227499a1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGenerateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGenerateTest.java @@ -25,6 +25,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableGenerateTest { @@ -197,7 +198,7 @@ public void accept(Object s, Emitter e) throws Exception { } }, Functions.emptyConsumer()) .rebatchRequests(1) - .test(5) + .to(TestHelper.testSubscriber(5L)) .assertSubscribed() .assertValues(1, 1, 1, 1, 1) .assertNoErrors() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java index af33f7d357..2901b1e652 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupByTest.java @@ -40,6 +40,7 @@ import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableGroupByTest { @@ -1058,7 +1059,7 @@ public String apply(Integer l) { } }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } @@ -1160,7 +1161,7 @@ public String apply(String v) { TestSubscriber ts = new TestSubscriber(); m.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); System.out.println("ts .get " + ts.values()); ts.assertNoErrors(); assertEquals(ts.values(), @@ -1174,10 +1175,10 @@ public void keySelectorThrows() { Flowable m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); m.subscribe(ts); - ts.awaitTerminalEvent(); - assertEquals(1, ts.errorCount()); + ts.awaitDone(5, TimeUnit.SECONDS); + assertEquals(1, ts.errors().size()); ts.assertNoValues(); } @@ -1186,10 +1187,10 @@ public void valueSelectorThrows() { Flowable source = Flowable.just(0, 1, 2, 3, 4, 5, 6); Flowable m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); m.subscribe(ts); - ts.awaitTerminalEvent(); - assertEquals(1, ts.errorCount()); + ts.awaitDone(5, TimeUnit.SECONDS); + assertEquals(1, ts.errors().size()); ts.assertNoValues(); } @@ -1202,7 +1203,7 @@ public void innerEscapeCompleted() { TestSubscriber ts = new TestSubscriber(); m.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); System.out.println(ts.values()); } @@ -1243,10 +1244,10 @@ public void testError2() { Flowable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); m.subscribe(ts); - ts.awaitTerminalEvent(); - assertEquals(1, ts.errorCount()); + ts.awaitDone(5, TimeUnit.SECONDS); + assertEquals(1, ts.errors().size()); ts.assertValueCount(1); } @@ -1302,7 +1303,7 @@ public void accept(Notification t1) { } }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } @@ -1341,7 +1342,7 @@ public String apply(Integer l) { } }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } @@ -1403,7 +1404,7 @@ public Integer apply(Integer integer) { } }).subscribe(ts); - ts.dispose(); + ts.cancel(); verify(s).cancel(); } @@ -1411,11 +1412,11 @@ public Integer apply(Integer integer) { @Test public void testGroupByShouldPropagateError() { final Throwable e = new RuntimeException("Oops"); - final TestSubscriber inner1 = new TestSubscriber(); - final TestSubscriber inner2 = new TestSubscriber(); + final TestSubscriberEx inner1 = new TestSubscriberEx(); + final TestSubscriberEx inner2 = new TestSubscriberEx(); - final TestSubscriber> outer - = new TestSubscriber>(new DefaultSubscriber>() { + final TestSubscriberEx> outer + = new TestSubscriberEx>(new DefaultSubscriber>() { @Override public void onComplete() { @@ -1602,9 +1603,9 @@ public void accept(GroupedFlowable g) { @Test public void outerInnerFusion() { - final TestSubscriber ts1 = SubscriberFusion.newTest(QueueFuseable.ANY); + final TestSubscriberEx ts1 = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); - final TestSubscriber> ts2 = SubscriberFusion.newTest(QueueFuseable.ANY); + final TestSubscriberEx> ts2 = new TestSubscriberEx>().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 10).groupBy(new Function() { @Override @@ -1626,13 +1627,13 @@ public void accept(GroupedFlowable g) { .subscribe(ts2); ts1 - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFusionMode(QueueFuseable.ASYNC) .assertValues(2, 3, 4, 5, 6, 7, 8, 9, 10, 11) .assertNoErrors() .assertComplete(); ts2 - .assertOf(SubscriberFusion.>assertFusionMode(QueueFuseable.ASYNC)) + .assertFusionMode(QueueFuseable.ASYNC) .assertValueCount(1) .assertNoErrors() .assertComplete(); @@ -1707,7 +1708,7 @@ public void onNext(Integer t) { public void reentrantCompleteCancel() { final PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = new TestSubscriber() { + TestSubscriberEx ts = new TestSubscriberEx() { @Override public void onNext(Integer t) { super.onNext(t); @@ -1737,13 +1738,13 @@ public void delayErrorSimpleComplete() { @Test public void mainFusionRejected() { - TestSubscriber> ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx> ts = new TestSubscriberEx>().setInitialFusionMode(QueueFuseable.SYNC); Flowable.just(1) .groupBy(Functions.justFunction(1)) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertValueCount(1) .assertComplete() .assertNoErrors(); @@ -1796,25 +1797,25 @@ public Publisher apply(GroupedFlowable g) throws Excep @Test public void errorFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.error(new TestException()) .groupBy(Functions.justFunction(1)) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertFailure(TestException.class); } @Test public void errorFusedDelayed() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.error(new TestException()) .groupBy(Functions.justFunction(1), true) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertFailure(TestException.class); } @@ -1869,10 +1870,10 @@ public void mapFactoryExpiryCompletesGroupedFlowable() { final List completed = new CopyOnWriteArrayList(); Function, Map> evictingMapFactory = createEvictingMapFactorySynchronousOnly(1); PublishSubject subject = PublishSubject.create(); - TestSubscriber ts = subject.toFlowable(BackpressureStrategy.BUFFER) + TestSubscriberEx ts = subject.toFlowable(BackpressureStrategy.BUFFER) .groupBy(Functions.identity(), Functions.identity(), true, 16, evictingMapFactory) .flatMap(addCompletedKey(completed)) - .test(); + .to(TestHelper.testConsumer()); subject.onNext(1); subject.onNext(2); subject.onNext(3); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java index da24ccbc0a..f0597a6bd9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableGroupJoinTest.java @@ -33,6 +33,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableGroupJoinTest { @@ -521,7 +522,7 @@ public void innerErrorRace() { List errors = TestHelper.trackPluginErrors(); try { - TestSubscriber> ts = Flowable.just(1) + TestSubscriberEx> ts = Flowable.just(1) .groupJoin( Flowable.just(2).concatWith(Flowable.never()), new Function>() { @@ -543,7 +544,7 @@ public Flowable apply(Integer r, Flowable l) throws Exception } } ) - .test(); + .to(TestHelper.>testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); @@ -593,7 +594,7 @@ public void outerErrorRace() { List errors = TestHelper.trackPluginErrors(); try { - TestSubscriber ts = pp1 + TestSubscriberEx ts = pp1 .groupJoin( pp2, new Function>() { @@ -616,7 +617,7 @@ public Flowable apply(Object r, Flowable l) throws Exception { } ) .flatMap(Functions.>identity()) - .test(); + .to(TestHelper.testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java index af85b261c6..1325baf55e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableHideTest.java @@ -24,6 +24,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class FlowableHideTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java index 6272ab2757..b0f42912e4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIgnoreElementsTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.*; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableIgnoreElementsTest { @@ -60,7 +61,7 @@ public void accept(Integer t) { @Test public void testCompletedOkFlowable() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(1, 10).ignoreElements().toFlowable().subscribe(ts); ts.assertNoErrors(); ts.assertNoValues(); @@ -69,7 +70,7 @@ public void testCompletedOkFlowable() { @Test public void testErrorReceivedFlowable() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); TestException ex = new TestException("boo"); Flowable.error(ex).ignoreElements().toFlowable().subscribe(ts); ts.assertNoValues(); @@ -172,7 +173,7 @@ public void accept(Integer t) { @Test public void testCompletedOk() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Flowable.range(1, 10).ignoreElements().subscribe(to); to.assertNoErrors(); to.assertNoValues(); @@ -181,7 +182,7 @@ public void testCompletedOk() { @Test public void testErrorReceived() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); TestException ex = new TestException("boo"); Flowable.error(ex).ignoreElements().subscribe(to); to.assertNoValues(); @@ -250,13 +251,13 @@ public void cancel() { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.just(1).hide().ignoreElements().toFlowable() .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableInternalHelperTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableInternalHelperTest.java index b2eb9deddd..05a77a7bb3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableInternalHelperTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableInternalHelperTest.java @@ -14,7 +14,7 @@ import org.junit.Test; -import io.reactivex.TestHelper; +import io.reactivex.testsupport.TestHelper; public class FlowableInternalHelperTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalRangeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalRangeTest.java index 881acad749..9ebf1c67a2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalRangeTest.java @@ -25,6 +25,7 @@ import io.reactivex.*; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class FlowableIntervalRangeTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalTest.java index 541de65872..2b1121577a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableIntervalTest.java @@ -21,6 +21,7 @@ import io.reactivex.internal.operators.flowable.FlowableInterval.IntervalSubscriber; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableIntervalTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java index 14a5ec3d59..f42bf9f2a1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableJoinTest.java @@ -24,7 +24,7 @@ import org.mockito.MockitoAnnotations; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableJoinTest { Subscriber subscriber = TestHelper.mockSubscriber(); @@ -401,7 +402,7 @@ public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -417,7 +418,7 @@ public void badEndSource() { @SuppressWarnings("rawtypes") final Subscriber[] o = { null }; - TestSubscriber ts = Flowable.just(1) + TestSubscriberEx ts = Flowable.just(1) .join(Flowable.just(2), Functions.justFunction(Flowable.never()), Functions.justFunction(new Flowable() { @@ -434,7 +435,7 @@ public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test(); + .to(TestHelper.testConsumer()); o[0].onError(new TestException("Second")); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java index 517d727903..8f7df35509 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLastTest.java @@ -24,6 +24,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class FlowableLastTest { @@ -290,7 +291,7 @@ public void lastOrErrorMultipleElements() { public void lastOrErrorError() { Flowable.error(new RuntimeException("error")) .lastOrError() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java index bb28c6c597..f74d4e7d19 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLiftTest.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class FlowableLiftTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLimitTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLimitTest.java index 9150bab4ad..54d5f0fa3c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableLimitTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableLimitTest.java @@ -27,6 +27,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableLimitTest implements LongConsumer, Action { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java index 468ffe2586..78fee99f45 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapNotificationTest.java @@ -16,7 +16,7 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -24,6 +24,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableMapNotificationTest { @Test @@ -179,7 +180,7 @@ public Flowable apply(Flowable f) throws Exception { @Test public void onErrorCrash() { - TestSubscriber ts = Flowable.error(new TestException("Outer")) + TestSubscriberEx ts = Flowable.error(new TestException("Outer")) .flatMap(Functions.justFunction(Flowable.just(1)), new Function>() { @Override @@ -188,7 +189,7 @@ public Publisher apply(Throwable t) throws Exception { } }, Functions.justSupplier(Flowable.just(3))) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertError(ts, 0, TestException.class, "Outer"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java index 9ebc328d56..16a130519e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMapTest.java @@ -23,7 +23,6 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; @@ -33,7 +32,8 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableMapTest { @@ -422,7 +422,7 @@ public boolean test(Integer v) throws Exception { @Test public void mapFilterFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 2) .map(new Function() { @@ -439,14 +439,14 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(2, 3); } @Test public void mapFilterFusedHidden() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 2).hide() .map(new Function() { @@ -463,8 +463,8 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(2, 3); } @@ -500,7 +500,7 @@ public Object apply(Integer v) throws Exception { @Test public void mapFilterMapperCrashFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 2).hide() .map(new Function() { @@ -517,8 +517,8 @@ public boolean test(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertFailure(TestException.class); } @@ -560,7 +560,7 @@ public boolean test(Integer v) throws Exception { @Test public void mapFilterFused2() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); @@ -583,8 +583,8 @@ public boolean test(Integer v) throws Exception { up.onNext(2); up.onComplete(); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(2, 3); } @@ -642,19 +642,19 @@ public Flowable apply(Flowable f) throws Exception { @Test public void fusedSync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .map(Functions.identity()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void fusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor us = UnicastProcessor.create(); @@ -664,19 +664,19 @@ public void fusedAsync() { TestHelper.emit(us, 1, 2, 3, 4, 5); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void fusedReject() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY | QueueFuseable.BOUNDARY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY | QueueFuseable.BOUNDARY); Flowable.range(1, 5) .map(Functions.identity()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java index b35006ebbf..e5cafb7fb1 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMaterializeTest.java @@ -26,6 +26,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableMaterializeTest { @@ -174,7 +175,7 @@ public void testBackpressureWithEmissionThenError() { @Test public void testWithCompletionCausingError() { - TestSubscriber> ts = new TestSubscriber>(); + TestSubscriberEx> ts = new TestSubscriberEx>(); final RuntimeException ex = new RuntimeException("boo"); Flowable.empty().materialize().doOnNext(new Consumer() { @Override @@ -194,7 +195,7 @@ public void testUnsubscribeJustBeforeCompletionNotificationShouldPreventThatNoti Flowable.empty().materialize() .subscribe(ts); ts.assertNoValues(); - ts.dispose(); + ts.cancel(); ts.request(1); ts.assertNoValues(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java index 67129c956b..1bb81174c2 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeDelayErrorTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.lang.reflect.Method; @@ -24,13 +25,13 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.LongConsumer; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableMergeDelayErrorTest { @@ -495,15 +496,15 @@ public void onComplete() { @Test public void testErrorInParentFlowable() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.mergeDelayError( Flowable.just(Flowable.just(1), Flowable.just(2)) .startWith(Flowable. error(new RuntimeException())) ).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertTerminated(); ts.assertValues(1, 2); - assertEquals(1, ts.errorCount()); + assertEquals(1, ts.errors().size()); } @@ -524,11 +525,11 @@ public void subscribe(Subscriber> op) { stringSubscriber = TestHelper.mockSubscriber(); - TestSubscriber ts = new TestSubscriber(stringSubscriber); + TestSubscriberEx ts = new TestSubscriberEx(stringSubscriber); Flowable m = Flowable.mergeDelayError(parentFlowable); m.subscribe(ts); System.out.println("testErrorInParentFlowableDelayed | " + i); - ts.awaitTerminalEvent(2000, TimeUnit.MILLISECONDS); + ts.awaitDone(2000, TimeUnit.MILLISECONDS); ts.assertTerminated(); verify(stringSubscriber, times(2)).onNext("hello"); @@ -574,7 +575,7 @@ public void accept(long t1) { } }), 1); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.subscribe(ts); @@ -631,7 +632,7 @@ public void iterableMaxConcurrent() { @SuppressWarnings("unchecked") @Test public void iterableMaxConcurrentError() { - TestSubscriber ts = TestSubscriber.create(); + TestSubscriberEx ts = new TestSubscriberEx(); PublishProcessor pp1 = PublishProcessor.create(); PublishProcessor pp2 = PublishProcessor.create(); @@ -707,7 +708,7 @@ public void mergeManyError() throws Exception { Method m = Flowable.class.getMethod("mergeDelayError", clazz); - TestSubscriber ts = TestSubscriber.create(); + TestSubscriberEx ts = new TestSubscriberEx(); ((Flowable)m.invoke(null, (Object[])obs)).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java index ef5dd519ff..9f1f84bc4f 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeMaxConcurrentTest.java @@ -19,14 +19,15 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.*; +import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.internal.schedulers.IoScheduler; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; public class FlowableMergeMaxConcurrentTest { @@ -149,7 +150,7 @@ public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { @Test public void testSimple() { for (int i = 1; i < 100; i++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { @@ -168,7 +169,7 @@ public void testSimple() { @Test public void testSimpleOneLess() { for (int i = 2; i < 100; i++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { @@ -210,7 +211,7 @@ public void testSimpleAsync() { Flowable.merge(sourceList, i).subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertNoErrors(); Set actual = new HashSet(ts.values()); @@ -242,7 +243,7 @@ public void testSimpleOneLessAsync() { Flowable.merge(sourceList, i - 1).subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertNoErrors(); Set actual = new HashSet(ts.values()); @@ -278,7 +279,7 @@ public void onNext(Integer t) { ts.assertValueCount(5); ts.assertNotComplete(); - ts.dispose(); + ts.cancel(); } @Test(timeout = 5000) @@ -293,7 +294,7 @@ public void testTake() throws Exception { Flowable.merge(sourceList, 2).take(5).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertValueCount(5); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java index 010da8bd69..74c1082415 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeTest.java @@ -37,6 +37,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableMergeTest { @@ -204,7 +205,7 @@ public void testMergeArrayWithThreading() { TestSubscriber ts = new TestSubscriber(stringSubscriber); m.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); verify(stringSubscriber, never()).onError(any(Throwable.class)); @@ -357,7 +358,7 @@ public void testError2() { @Test @Ignore("Subscribe should not throw") public void testThrownErrorHandling() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable f1 = Flowable.unsafeCreate(new Publisher() { @Override @@ -368,7 +369,7 @@ public void subscribe(Subscriber s) { }); Flowable.merge(f1, f1).subscribe(ts); - ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + ts.awaitDone(1000, TimeUnit.MILLISECONDS); ts.assertTerminated(); System.out.println("Error: " + ts.errors()); } @@ -443,7 +444,7 @@ public void testUnsubscribeAsFlowablesComplete() { AtomicBoolean os2 = new AtomicBoolean(false); Flowable f2 = createFlowableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.merge(f1, f2).subscribe(ts); // we haven't incremented time so nothing should be received yet @@ -500,7 +501,7 @@ public void testEarlyUnsubscribe() { assertFalse(os2.get()); // early unsubscribe - ts.dispose(); + ts.cancel(); assertTrue(os1.get()); assertTrue(os2.get()); @@ -561,10 +562,10 @@ public void testConcurrency() { for (int i = 0; i < 10; i++) { Flowable merge = Flowable.merge(f.onBackpressureBuffer(), f.onBackpressureBuffer(), f.onBackpressureBuffer()); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); merge.subscribe(ts); - ts.awaitTerminalEvent(3, TimeUnit.SECONDS); + ts.awaitDone(3, TimeUnit.SECONDS); ts.assertTerminated(); ts.assertNoErrors(); ts.assertComplete(); @@ -617,7 +618,7 @@ public void run() { TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertComplete(); List onNextEvents = ts.values(); assertEquals(300, onNextEvents.size()); @@ -664,7 +665,7 @@ public void run() { TestSubscriber ts = new TestSubscriber(); merge.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertComplete(); List onNextEvents = ts.values(); @@ -680,7 +681,7 @@ public void testBackpressureUpstream() throws InterruptedException { final AtomicInteger generated2 = new AtomicInteger(); Flowable f2 = createInfiniteFlowable(generated2).subscribeOn(Schedulers.computation()); - TestSubscriber testSubscriber = new TestSubscriber() { + TestSubscriberEx testSubscriber = new TestSubscriberEx() { @Override public void onNext(Integer t) { System.err.println("testSubscriber received => " + t + " on thread " + Thread.currentThread()); @@ -689,7 +690,7 @@ public void onNext(Integer t) { }; Flowable.merge(f1.take(Flowable.bufferSize() * 2), f2.take(Flowable.bufferSize() * 2)).subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); } @@ -717,7 +718,7 @@ public void testBackpressureUpstream2() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); Flowable f1 = createInfiniteFlowable(generated1).subscribeOn(Schedulers.computation()); - TestSubscriber testSubscriber = new TestSubscriber() { + TestSubscriberEx testSubscriber = new TestSubscriberEx() { @Override public void onNext(Integer t) { super.onNext(t); @@ -725,7 +726,7 @@ public void onNext(Integer t) { }; Flowable.merge(f1.take(Flowable.bufferSize() * 2), Flowable.just(-99)).subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); List onNextEvents = testSubscriber.values(); @@ -754,7 +755,7 @@ public void testBackpressureDownstreamWithConcurrentStreams() throws Interrupted final AtomicInteger generated2 = new AtomicInteger(); Flowable f2 = createInfiniteFlowable(generated2).subscribeOn(Schedulers.computation()); - TestSubscriber testSubscriber = new TestSubscriber() { + TestSubscriberEx testSubscriber = new TestSubscriberEx() { @Override public void onNext(Integer t) { if (t < 100) { @@ -771,7 +772,7 @@ public void onNext(Integer t) { }; Flowable.merge(f1.take(Flowable.bufferSize() * 2), f2.take(Flowable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); } @@ -797,7 +798,7 @@ public Flowable apply(Integer t1) { }); - TestSubscriber testSubscriber = new TestSubscriber() { + TestSubscriberEx testSubscriber = new TestSubscriberEx() { @Override public void onNext(Integer t) { if (t < 100) { @@ -814,7 +815,7 @@ public void onNext(Integer t) { }; Flowable.merge(f1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); } @@ -850,7 +851,7 @@ public Flowable apply(Integer t1) { }); - TestSubscriber testSubscriber = new TestSubscriber() { + TestSubscriberEx testSubscriber = new TestSubscriberEx() { int i; @Override @@ -869,7 +870,7 @@ public void onNext(Integer t) { }; Flowable.merge(f1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); if (testSubscriber.errors().size() > 0) { testSubscriber.errors().get(0).printStackTrace(); } @@ -887,7 +888,7 @@ public void onNext(Integer t) { @Ignore("Null values not permitted") public void mergeWithNullValues() { System.out.println("mergeWithNullValues"); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.merge(Flowable.just(null, "one"), Flowable.just("two", null)).subscribe(ts); ts.assertTerminated(); ts.assertNoErrors(); @@ -928,7 +929,7 @@ public void mergingNullFlowable() { public void merge1AsyncStreamOf1() { TestSubscriber ts = new TestSubscriber(); mergeNAsyncStreamsOfN(1, 1).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1, ts.values().size()); } @@ -937,7 +938,7 @@ public void merge1AsyncStreamOf1() { public void merge1AsyncStreamOf1000() { TestSubscriber ts = new TestSubscriber(); mergeNAsyncStreamsOfN(1, 1000).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1000, ts.values().size()); } @@ -946,7 +947,7 @@ public void merge1AsyncStreamOf1000() { public void merge10AsyncStreamOf1000() { TestSubscriber ts = new TestSubscriber(); mergeNAsyncStreamsOfN(10, 1000).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(10000, ts.values().size()); } @@ -955,7 +956,7 @@ public void merge10AsyncStreamOf1000() { public void merge1000AsyncStreamOf1000() { TestSubscriber ts = new TestSubscriber(); mergeNAsyncStreamsOfN(1000, 1000).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1000000, ts.values().size()); } @@ -964,7 +965,7 @@ public void merge1000AsyncStreamOf1000() { public void merge2000AsyncStreamOf100() { TestSubscriber ts = new TestSubscriber(); mergeNAsyncStreamsOfN(2000, 100).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(200000, ts.values().size()); } @@ -973,7 +974,7 @@ public void merge2000AsyncStreamOf100() { public void merge100AsyncStreamOf1() { TestSubscriber ts = new TestSubscriber(); mergeNAsyncStreamsOfN(100, 1).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(100, ts.values().size()); } @@ -995,7 +996,7 @@ public Flowable apply(Integer i) { public void merge1SyncStreamOf1() { TestSubscriber ts = new TestSubscriber(); mergeNSyncStreamsOfN(1, 1).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1, ts.values().size()); } @@ -1004,7 +1005,7 @@ public void merge1SyncStreamOf1() { public void merge1SyncStreamOf1000000() { TestSubscriber ts = new TestSubscriber(); mergeNSyncStreamsOfN(1, 1000000).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1000000, ts.values().size()); } @@ -1013,7 +1014,7 @@ public void merge1SyncStreamOf1000000() { public void merge1000SyncStreamOf1000() { TestSubscriber ts = new TestSubscriber(); mergeNSyncStreamsOfN(1000, 1000).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1000000, ts.values().size()); } @@ -1022,7 +1023,7 @@ public void merge1000SyncStreamOf1000() { public void merge10000SyncStreamOf10() { TestSubscriber ts = new TestSubscriber(); mergeNSyncStreamsOfN(10000, 10).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(100000, ts.values().size()); } @@ -1031,7 +1032,7 @@ public void merge10000SyncStreamOf10() { public void merge1000000SyncStreamOf1() { TestSubscriber ts = new TestSubscriber(); mergeNSyncStreamsOfN(1000000, 1).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(1000000, ts.values().size()); } @@ -1103,7 +1104,7 @@ public void subscribe(Subscriber s) { }); Flowable.merge(os).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); assertEquals(10000, ts.values().size()); } @@ -1111,7 +1112,7 @@ public void subscribe(Subscriber s) { @Test public void shouldCompleteAfterApplyingBackpressure_NormalPath() { Flowable source = Flowable.mergeDelayError(Flowable.just(Flowable.range(1, 2))); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); source.subscribe(subscriber); subscriber.request(3); // 1, 2, - with request(2) we get the 1 and 2 but not the subscriber.assertValues(1, 2); @@ -1121,7 +1122,7 @@ public void shouldCompleteAfterApplyingBackpressure_NormalPath() { @Test public void shouldCompleteAfterApplyingBackpressure_FastPath() { Flowable source = Flowable.mergeDelayError(Flowable.just(Flowable.just(1))); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); source.subscribe(subscriber); subscriber.request(2); // 1, - should work as per .._NormalPath above subscriber.assertValue(1); @@ -1132,7 +1133,7 @@ public void shouldCompleteAfterApplyingBackpressure_FastPath() { public void shouldNotCompleteIfThereArePendingScalarSynchronousEmissionsWhenTheLastInnerSubscriberCompletes() { TestScheduler scheduler = new TestScheduler(); Flowable source = Flowable.mergeDelayError(Flowable.just(1L), Flowable.timer(1, TimeUnit.SECONDS, scheduler).skip(1)); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); source.subscribe(subscriber); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); subscriber.assertNoValues(); @@ -1149,7 +1150,7 @@ public void shouldNotCompleteIfThereArePendingScalarSynchronousEmissionsWhenTheL public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_NormalPath() { Throwable exception = new Throwable(); Flowable source = Flowable.mergeDelayError(Flowable.range(1, 2), Flowable.error(exception)); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); source.subscribe(subscriber); subscriber.request(3); // 1, 2, subscriber.assertValues(1, 2); @@ -1161,7 +1162,7 @@ public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_No public void delayedErrorsShouldBeEmittedWhenCompleteAfterApplyingBackpressure_FastPath() { Throwable exception = new Throwable(); Flowable source = Flowable.mergeDelayError(Flowable.just(1), Flowable.error(exception)); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); source.subscribe(subscriber); subscriber.request(2); // 1, subscriber.assertValue(1); @@ -1183,7 +1184,7 @@ public void shouldNotCompleteWhileThereAreStillScalarSynchronousEmissionsInTheQu public void shouldNotReceivedDelayedErrorWhileThereAreStillScalarSynchronousEmissionsInTheQueue() { Throwable exception = new Throwable(); Flowable source = Flowable.mergeDelayError(Flowable.just(1), Flowable.just(2), Flowable.error(exception)); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); subscriber.request(1); source.subscribe(subscriber); subscriber.assertValue(1); @@ -1197,7 +1198,7 @@ public void shouldNotReceivedDelayedErrorWhileThereAreStillScalarSynchronousEmis public void shouldNotReceivedDelayedErrorWhileThereAreStillNormalEmissionsInTheQueue() { Throwable exception = new Throwable(); Flowable source = Flowable.mergeDelayError(Flowable.range(1, 2), Flowable.range(3, 2), Flowable.error(exception)); - TestSubscriber subscriber = new TestSubscriber(0L); + TestSubscriberEx subscriber = new TestSubscriberEx(0L); subscriber.request(3); source.subscribe(subscriber); subscriber.assertValues(1, 2, 3); @@ -1339,7 +1340,7 @@ public Flowable apply(Integer t) { }; ; - void runMerge(Function> func, TestSubscriber ts) { + void runMerge(Function> func, TestSubscriberEx ts) { List list = new ArrayList(); for (int i = 0; i < 1000; i++) { list.add(i); @@ -1358,18 +1359,18 @@ void runMerge(Function> func, TestSubscriber @Test public void testFastMergeFullScalar() { - runMerge(toScalar, new TestSubscriber()); + runMerge(toScalar, new TestSubscriberEx()); } @Test public void testFastMergeHiddenScalar() { - runMerge(toHiddenScalar, new TestSubscriber()); + runMerge(toHiddenScalar, new TestSubscriberEx()); } @Test public void testSlowMergeFullScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { - TestSubscriber ts = new TestSubscriber(req) { + TestSubscriberEx ts = new TestSubscriberEx(req) { int remaining = req; @Override @@ -1388,7 +1389,7 @@ public void onNext(Integer t) { @Test public void testSlowMergeHiddenScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { - TestSubscriber ts = new TestSubscriber(req) { + TestSubscriberEx ts = new TestSubscriberEx(req) { int remaining = req; @Override public void onNext(Integer t) { @@ -1640,7 +1641,7 @@ public void mergeErrors() { Flowable source2 = Flowable.error(new TestException("Second")); Flowable.merge(source1, source2) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(errors.toString(), errors.isEmpty()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java index cf5b7917a6..eab8439e0b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithCompletableTest.java @@ -23,6 +23,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.CompletableSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableMergeWithCompletableTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java index c38bf6ae7b..0585a65543 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithMaybeTest.java @@ -30,6 +30,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.MaybeSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableMergeWithMaybeTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java index 2ab0568a7e..180384ff1a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableMergeWithSingleTest.java @@ -30,6 +30,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.SingleSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableMergeWithSingleTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java index ca4bd28986..10377817c9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableObserveOnTest.java @@ -39,6 +39,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableObserveOnTest { @@ -65,11 +66,11 @@ public void testOrdering() throws InterruptedException { Subscriber subscriber = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(subscriber); - TestSubscriber ts = new TestSubscriber(subscriber); + TestSubscriberEx ts = new TestSubscriberEx(subscriber); obs.observeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + ts.awaitDone(1000, TimeUnit.MILLISECONDS); if (ts.errors().size() > 0) { for (Throwable t : ts.errors()) { t.printStackTrace(); @@ -392,7 +393,7 @@ public void testAfterUnsubscribeCalledThenObserverOnNextNeverCalled() { .observeOn(testScheduler) .subscribe(ts); - ts.dispose(); + ts.cancel(); testScheduler.advanceTimeBy(1, TimeUnit.SECONDS); final InOrder inOrder = inOrder(subscriber); @@ -443,7 +444,7 @@ public void onNext(Integer t) { .observeOn(Schedulers.newThread()) .take(3) .subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); System.err.println(testSubscriber.values()); testSubscriber.assertValues(0, 1, 2); // it should be between the take num and requested batch size across the async boundary @@ -489,7 +490,7 @@ public void onNext(Integer t) { .observeOn(Schedulers.newThread()) .take(numForBatches) .subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); System.err.println(testSubscriber.values()); // it should be between the take num and requested batch size across the async boundary System.out.println("Generated: " + generated.get()); @@ -527,7 +528,7 @@ public boolean hasNext() { .observeOn(Schedulers.newThread()) .subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); testSubscriber.assertValues(0, 1, 2, 3, 4, 5, 6); assertEquals(7, generated.get()); } @@ -549,7 +550,7 @@ public void subscribe(Subscriber subscriber) { }); - TestSubscriber testSubscriber = new TestSubscriber(new DefaultSubscriber() { + TestSubscriberEx testSubscriber = new TestSubscriberEx(new DefaultSubscriber() { @Override public void onComplete() { @@ -574,7 +575,7 @@ public void onNext(Integer t) { }); flowable.observeOn(Schedulers.newThread()).subscribe(testSubscriber); - testSubscriber.awaitTerminalEvent(); + testSubscriber.awaitDone(5, TimeUnit.SECONDS); List errors = testSubscriber.errors(); assertEquals(1, errors.size()); System.out.println("Errors: " + errors); @@ -594,7 +595,7 @@ public void onNext(Integer t) { public void testAsyncChild() { TestSubscriber ts = new TestSubscriber(); Flowable.range(0, 100000).observeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } @@ -604,7 +605,7 @@ public void testOnErrorCutsAheadOfOnNext() { final PublishProcessor processor = PublishProcessor.create(); final AtomicLong counter = new AtomicLong(); - TestSubscriber ts = new TestSubscriber(new DefaultSubscriber() { + TestSubscriberEx ts = new TestSubscriberEx(new DefaultSubscriber() { @Override public void onComplete() { @@ -634,7 +635,7 @@ public void onNext(Long t) { counter.incrementAndGet(); } - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertEquals(1, ts.errors().size()); ts.assertError(MissingBackpressureException.class); // assert that the values are sequential, that cutting in didn't allow skipping some but emitting others. @@ -651,7 +652,7 @@ public void onNext(Long t) { */ @Test public void testHotOperatorBackpressure() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.interval(0, 1, TimeUnit.MICROSECONDS) .observeOn(Schedulers.computation()) .map(new Function() { @@ -668,7 +669,7 @@ public String apply(Long t1) { }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); System.out.println("Errors: " + ts.errors()); assertEquals(1, ts.errors().size()); assertEquals(MissingBackpressureException.class, ts.errors().get(0).getClass()); @@ -699,7 +700,7 @@ public void accept(Notification n) { }); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.combineLatest(timer, Flowable. never(), new BiFunction() { @@ -710,7 +711,7 @@ public Long apply(Long t1, Integer t2) { }).take(Flowable.bufferSize() * 2).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertEquals(1, ts.errors().size()); assertEquals(MissingBackpressureException.class, ts.errors().get(0).getClass()); } @@ -840,7 +841,7 @@ public void testErrorDelayedAsync() { source.observeOn(Schedulers.computation(), true).subscribe(ts); - ts.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts.awaitDone(2, TimeUnit.SECONDS); ts.assertValues(1, 2, 3); ts.assertError(TestException.class); ts.assertNotComplete(); @@ -911,7 +912,7 @@ public void bufferSizesWork() { Flowable.range(1, 1000 * 1000).observeOn(Schedulers.computation(), false, i) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValueCount(1000 * 1000); ts.assertComplete(); ts.assertNoErrors(); @@ -1005,7 +1006,7 @@ public void cancelCleanup() { @Test public void conditionalConsumerFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .observeOn(Schedulers.single()) @@ -1018,15 +1019,15 @@ public boolean test(Integer v) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertResult(2, 4); } @Test public void conditionalConsumerFusedReject() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5) .observeOn(Schedulers.single()) @@ -1039,17 +1040,17 @@ public boolean test(Integer v) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + .assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .awaitDone(5, TimeUnit.SECONDS) .assertResult(2, 4); } @Test public void requestOne() throws Exception { - TestSubscriber ts = Flowable.range(1, 5) + TestSubscriberEx ts = Flowable.range(1, 5) .observeOn(Schedulers.single()) - .test(1); + .to(TestHelper.testSubscriber(1L)); Thread.sleep(100); @@ -1058,10 +1059,10 @@ public void requestOne() throws Exception { @Test public void requestOneConditional() throws Exception { - TestSubscriber ts = Flowable.range(1, 5) + TestSubscriberEx ts = Flowable.range(1, 5) .observeOn(Schedulers.single()) .filter(Functions.alwaysTrue()) - .test(1); + .to(TestHelper.testSubscriber(1L)); Thread.sleep(100); @@ -1070,7 +1071,7 @@ public void requestOneConditional() throws Exception { @Test public void conditionalConsumerFusedAsync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor up = UnicastProcessor.create(); @@ -1092,15 +1093,15 @@ public boolean test(Integer v) throws Exception { up.onComplete(); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertResult(2, 4); } @Test public void conditionalConsumerHidden() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5).hide() .observeOn(Schedulers.single()) @@ -1113,15 +1114,15 @@ public boolean test(Integer v) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertResult(2, 4); } @Test public void conditionalConsumerBarrier() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5) .map(Functions.identity()) @@ -1135,8 +1136,8 @@ public boolean test(Integer v) throws Exception { .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertResult(2, 4); } @@ -1234,33 +1235,33 @@ public void inputAsyncFusedErrorDelayed() { @Test public void outputFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 5).hide() .observeOn(Schedulers.single()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5); } @Test public void outputFusedReject() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.range(1, 5).hide() .observeOn(Schedulers.single()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5); } @Test public void inputOutputAsyncFusedError() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor us = UnicastProcessor.create(); @@ -1273,14 +1274,14 @@ public void inputOutputAsyncFusedError() { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); } @Test public void inputOutputAsyncFusedErrorDelayed() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); UnicastProcessor us = UnicastProcessor.create(); @@ -1293,7 +1294,7 @@ public void inputOutputAsyncFusedErrorDelayed() { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); } @@ -1564,7 +1565,7 @@ public boolean test(Integer v) throws Exception { } }) .take(250) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(250) @@ -1711,14 +1712,14 @@ public void request1Conditional() { @Test public void backFusedConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 100).hide() .observeOn(ImmediateThinScheduler.INSTANCE) .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertValueCount(100) .assertComplete() .assertNoErrors(); @@ -1726,21 +1727,21 @@ public void backFusedConditional() { @Test public void backFusedErrorConditional() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.error(new TestException()) .observeOn(ImmediateThinScheduler.INSTANCE) .filter(Functions.alwaysTrue()) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) + ts.assertFusionMode(QueueFuseable.ASYNC) .assertFailure(TestException.class); } @Test public void backFusedCancelConditional() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { - final TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + final TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); final TestScheduler scheduler = new TestScheduler(); @@ -1765,9 +1766,9 @@ public void run() { TestHelper.race(r1, r2); - SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC); + ts.assertFusionMode(QueueFuseable.ASYNC); - if (ts.valueCount() != 0) { + if (ts.values().size() != 0) { ts.assertResult(1); } } @@ -1860,7 +1861,7 @@ public void workerNotDisposedPrematurelyAsyncInNormalOut() { } static final class TestSubscriberFusedCanceling - extends TestSubscriber { + extends TestSubscriberEx { TestSubscriberFusedCanceling() { super(); @@ -1878,7 +1879,7 @@ public void onComplete() { public void workerNotDisposedPrematurelyNormalInAsyncOut() { DisposeTrackingScheduler s = new DisposeTrackingScheduler(); - TestSubscriber ts = new TestSubscriberFusedCanceling(); + TestSubscriberEx ts = new TestSubscriberFusedCanceling(); Flowable.just(1).hide().observeOn(s).subscribe(ts); @@ -1935,7 +1936,7 @@ public void workerNotDisposedPrematurelyAsyncInNormalOutConditional() { public void workerNotDisposedPrematurelyNormalInAsyncOutConditional() { DisposeTrackingScheduler s = new DisposeTrackingScheduler(); - TestSubscriber ts = new TestSubscriberFusedCanceling(); + TestSubscriberEx ts = new TestSubscriberFusedCanceling(); Flowable.just(1).hide().observeOn(s).filter(Functions.alwaysTrue()).subscribe(ts); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java index c52888548d..7fae117dc8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferStrategyTest.java @@ -17,6 +17,7 @@ import static io.reactivex.internal.functions.Functions.EMPTY_ACTION; import static org.junit.Assert.assertEquals; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.Test; @@ -28,6 +29,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableOnBackpressureBufferStrategyTest { @@ -46,7 +48,7 @@ public void run() throws Exception { .subscribe(ts); // we request 10 but only 3 should come from the buffer ts.request(10); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertEquals(bufferSize, ts.values().size()); ts.assertNoErrors(); assertEquals(497, ts.values().get(0).intValue()); @@ -92,7 +94,7 @@ public void run() throws Exception { .subscribe(ts); // we request 10 but only 3 should come from the buffer ts.request(10); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertEquals(bufferSize, ts.values().size()); ts.assertNoErrors(); assertEquals(0, ts.values().get(0).intValue()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java index 84793d3136..8cbf180f12 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureBufferTest.java @@ -28,6 +28,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestSubscriberEx; public class FlowableOnBackpressureBufferTest { @@ -83,7 +84,7 @@ public void onNext(Long t) { l2.await(); assertEquals(150, ts.values().size()); ts.request(350); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertEquals(500, ts.values().size()); ts.assertNoErrors(); assertEquals(0, ts.values().get(0).intValue()); @@ -138,7 +139,7 @@ public void run() { ts.request(50); assertTrue(backpressureCallback.await(500, TimeUnit.MILLISECONDS)); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertError(MissingBackpressureException.class); int size = ts.values().size(); @@ -182,7 +183,7 @@ public void accept(Throwable t) { }) .onBackpressureBuffer(1, THROWS_NON_FATAL) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertFalse(errorOccurred.get()); } @@ -249,23 +250,23 @@ public void delayErrorBuffer() { @Test public void fusedNormal() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 10).onBackpressureBuffer().subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void fusedError() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.error(new TestException()).onBackpressureBuffer().subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertFailure(TestException.class); } @@ -300,11 +301,11 @@ public void emptyDelayError() { @Test public void fusionRejected() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Flowable.never().onBackpressureBuffer().subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertEmpty(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDropTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDropTest.java index daded5f8b7..4940254f49 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDropTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureDropTest.java @@ -15,17 +15,18 @@ import static org.junit.Assert.*; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.*; import java.util.concurrent.atomic.*; import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableOnBackpressureDropTest { @@ -45,7 +46,7 @@ public void testNoBackpressureSupport() { public void testWithObserveOn() throws InterruptedException { TestSubscriber ts = new TestSubscriber(); Flowable.range(0, Flowable.bufferSize() * 10).onBackpressureDrop().observeOn(Schedulers.io()).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); } @Test(timeout = 5000) @@ -84,7 +85,7 @@ public void onNext(Long t) { l2.await(); assertEquals(150, ts.values().size()); ts.request(350); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); assertEquals(500, ts.values().size()); ts.assertNoErrors(); assertEquals(0, ts.values().get(0).intValue()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java index 3be409e862..00336292b0 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureErrorTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class FlowableOnBackpressureErrorTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java index db6b3d9580..eb25ee0689 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnBackpressureLatestTest.java @@ -19,17 +19,18 @@ import org.junit.*; import org.reactivestreams.Publisher; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableOnBackpressureLatestTest { @Test public void testSimple() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(1, 5).onBackpressureLatest().subscribe(ts); @@ -40,7 +41,7 @@ public void testSimple() { @Test public void testSimpleError() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(1, 5).concatWith(Flowable.error(new TestException())) .onBackpressureLatest().subscribe(ts); @@ -64,7 +65,7 @@ public void testSimpleBackpressure() { @Test public void testSynchronousDrop() { PublishProcessor source = PublishProcessor.create(); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); source.onBackpressureLatest().subscribe(ts); @@ -105,7 +106,7 @@ public void testSynchronousDrop() { @Test public void testAsynchronousDrop() throws InterruptedException { - TestSubscriber ts = new TestSubscriber(1L) { + TestSubscriberEx ts = new TestSubscriberEx(1L) { final Random rnd = new Random(); @Override public void onNext(Integer t) { @@ -127,7 +128,7 @@ public void onNext(Integer t) { .observeOn(Schedulers.io()) .subscribe(ts); - ts.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts.awaitDone(2, TimeUnit.SECONDS); ts.assertTerminated(); int n = ts.values().size(); System.out.println("testAsynchronousDrop -> " + n); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java index 140ca333ac..19fb624332 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFlowableTest.java @@ -14,18 +14,22 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; + import org.junit.*; import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableOnErrorResumeNextViaFlowableTest { @@ -139,7 +143,7 @@ public void subscribe(Subscriber t1) { TestSubscriber ts = new TestSubscriber(subscriber, Long.MAX_VALUE); flowable.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); verify(subscriber, Mockito.never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); @@ -213,7 +217,7 @@ public Integer apply(Integer t1) { }) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java index 06f10e835d..aa2fe7bd40 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorResumeNextViaFunctionTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.*; import java.io.IOException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.*; @@ -31,7 +32,8 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableOnErrorResumeNextViaFunctionTest { @@ -152,7 +154,7 @@ public Flowable apply(Throwable t1) { @Test @Ignore("Failed operator may leave the child subscriber in an inconsistent state which prevents further error delivery.") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperator() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.just(1).lift(new FlowableOperator() { @Override @@ -185,7 +187,7 @@ public Flowable apply(Throwable t1) { @Test @Ignore("A crashing operator may leave the downstream in an inconsistent state and not suitable for event delivery") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperatorOnNext() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.just(1).lift(new FlowableOperator() { @Override @@ -264,7 +266,7 @@ public Flowable apply(Throwable t1) { TestSubscriber ts = new TestSubscriber(subscriber, Long.MAX_VALUE); flowable.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); verify(subscriber, Mockito.never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); @@ -343,7 +345,7 @@ public Integer apply(Integer t1) { }) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java index eb2f120e43..3026a05f7b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnErrorReturnTest.java @@ -14,21 +14,24 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableOnErrorReturnTest { @@ -131,7 +134,7 @@ public String apply(Throwable t1) { Subscriber subscriber = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(subscriber, Long.MAX_VALUE); flowable.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); verify(subscriber, Mockito.never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); @@ -172,7 +175,7 @@ public Integer apply(Integer t1) { }) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java index ee1b4e3051..26b677ba0a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableOnExceptionResumeNextViaFlowableTest.java @@ -14,19 +14,23 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; + import org.junit.Test; import org.mockito.Mockito; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableOnExceptionResumeNextViaFlowableTest { @@ -210,7 +214,7 @@ public Integer apply(Integer t1) { }) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java index e744a00aa1..7dba80e92e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishFunctionTest.java @@ -24,7 +24,7 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,6 +32,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowablePublishFunctionTest { @Test @@ -209,7 +210,7 @@ public Flowable apply(Flowable f) { @Test public void overflowMissingBackpressureException() { - TestSubscriber ts = TestSubscriber.create(0); + TestSubscriberEx ts = new TestSubscriberEx(0); PublishProcessor pp = PublishProcessor.create(); @@ -235,7 +236,7 @@ public Flowable apply(Flowable f) { @Test public void overflowMissingBackpressureExceptionDelayed() { - TestSubscriber ts = TestSubscriber.create(0); + TestSubscriberEx ts = new TestSubscriberEx(0); PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java index 4078b5b0b0..1b0d292dca 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishMulticastTest.java @@ -19,13 +19,13 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.fuseable.QueueSubscription; import io.reactivex.internal.operators.flowable.FlowablePublishMulticast.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.UnicastProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowablePublishMulticastTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java index 8bd47e95f5..45daf84086 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowablePublishTest.java @@ -36,6 +36,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowablePublishTest { @@ -130,9 +131,9 @@ public void run() { TestSubscriber ts = new TestSubscriber(); Flowable.merge(fast, slow).subscribe(ts); is.connect(); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.values().size()); } // use case from https://github.com/ReactiveX/RxJava/issues/1732 @@ -163,7 +164,7 @@ public boolean test(Integer i) { } }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertValues(0, 1, 2, 3); assertEquals(5, emitted.get()); @@ -215,7 +216,7 @@ public void run() { final TestSubscriber ts1 = new TestSubscriber() { @Override public void onNext(Integer t) { - if (valueCount() == 2) { + if (values().size() == 2) { source.doOnCancel(new Action() { @Override public void run() { @@ -235,8 +236,8 @@ public void run() { }).take(5) .subscribe(ts1); - ts1.awaitTerminalEvent(); - ts2.awaitTerminalEvent(); + ts1.awaitDone(5, TimeUnit.SECONDS); + ts2.awaitDone(5, TimeUnit.SECONDS); ts1.assertNoErrors(); ts2.assertNoErrors(); @@ -262,7 +263,7 @@ public void testConnectWithNoSubscriber() { cf.subscribe(subscriber); // Emit 1 and 2 scheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS); - // 3.x: Flowable.publish no longer drains the input buffer if there are no subscribers + // 3.x: Flowable.publish no longer drains the input buffer if there are no subscribers subscriber.assertResult(0L, 1L, 2L); } @@ -270,7 +271,7 @@ public void testConnectWithNoSubscriber() { public void testSubscribeAfterDisconnectThenConnect() { ConnectableFlowable source = Flowable.just(1).publish(); - TestSubscriber ts1 = new TestSubscriber(); + TestSubscriberEx ts1 = new TestSubscriberEx(); source.subscribe(ts1); @@ -279,10 +280,10 @@ public void testSubscribeAfterDisconnectThenConnect() { ts1.assertValue(1); ts1.assertNoErrors(); ts1.assertTerminated(); - + source.reset(); - TestSubscriber ts2 = new TestSubscriber(); + TestSubscriberEx ts2 = new TestSubscriberEx(); source.subscribe(ts2); @@ -300,7 +301,7 @@ public void testSubscribeAfterDisconnectThenConnect() { public void testNoSubscriberRetentionOnCompleted() { FlowablePublish source = (FlowablePublish)Flowable.just(1).publish(); - TestSubscriber ts1 = new TestSubscriber(); + TestSubscriberEx ts1 = new TestSubscriberEx(); source.subscribe(ts1); @@ -352,7 +353,7 @@ static boolean checkPublishDisposed(Disposable d) { public void testZeroRequested() { ConnectableFlowable source = Flowable.just(1).publish(); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); source.subscribe(ts); @@ -407,16 +408,16 @@ public void syncFusedObserveOn() { Flowable obs = cf.observeOn(Schedulers.computation()); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { - List> tss = new ArrayList>(); + List> tss = new ArrayList>(); for (int k = 1; k < j; k++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); tss.add(ts); obs.subscribe(ts); } Disposable connection = cf.connect(); - for (TestSubscriber ts : tss) { + for (TestSubscriberEx ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000) @@ -434,16 +435,16 @@ public void syncFusedObserveOn2() { Flowable obs = cf.observeOn(ImmediateThinScheduler.INSTANCE); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { - List> tss = new ArrayList>(); + List> tss = new ArrayList>(); for (int k = 1; k < j; k++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); tss.add(ts); obs.subscribe(ts); } Disposable connection = cf.connect(); - for (TestSubscriber ts : tss) { + for (TestSubscriberEx ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000) @@ -460,16 +461,16 @@ public void asyncFusedObserveOn() { ConnectableFlowable cf = Flowable.range(0, 1000).observeOn(ImmediateThinScheduler.INSTANCE).publish(); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { - List> tss = new ArrayList>(); + List> tss = new ArrayList>(); for (int k = 1; k < j; k++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); tss.add(ts); cf.subscribe(ts); } Disposable connection = cf.connect(); - for (TestSubscriber ts : tss) { + for (TestSubscriberEx ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000) @@ -487,16 +488,16 @@ public void testObserveOn() { Flowable obs = cf.observeOn(Schedulers.computation()); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { - List> tss = new ArrayList>(); + List> tss = new ArrayList>(); for (int k = 1; k < j; k++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); tss.add(ts); obs.subscribe(ts); } Disposable connection = cf.connect(); - for (TestSubscriber ts : tss) { + for (TestSubscriberEx ts : tss) { ts.awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000) @@ -678,7 +679,7 @@ public void noErrorLoss() { ConnectableFlowable cf = Flowable.error(new TestException()).publish(); cf.connect(); - + // 3.x: terminal events are always kept until reset. cf.test() .assertFailure(TestException.class); @@ -1615,7 +1616,7 @@ protected void subscribeActual(Subscriber s) { } .publish(1) .refCount() - .test(0) + .to(TestHelper.testSubscriber(0L)) .assertFailureAndMessage(TestException.class, "one"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "two"); @@ -1672,7 +1673,7 @@ public void onErrorAvailableUntilReset() { ts.assertFailure(TestException.class, 1); } - + @Test public void disposeResets() { PublishProcessor pp = PublishProcessor.create(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java index 470e0e8cc0..0b10b5c97e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeLongTest.java @@ -23,11 +23,12 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableRangeLongTest { @@ -97,7 +98,7 @@ public void testRangeWithOverflow5() { public void testBackpressureViaRequest() { Flowable f = Flowable.rangeLong(1, Flowable.bufferSize()); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.assertNoValues(); ts.request(1); @@ -125,7 +126,7 @@ public void testNoBackpressure() { Flowable f = Flowable.rangeLong(1, list.size()); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.assertNoValues(); ts.request(Long.MAX_VALUE); // infinite @@ -138,7 +139,7 @@ public void testNoBackpressure() { void testWithBackpressureOneByOne(long start) { Flowable source = Flowable.rangeLong(start, 100); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.request(1); source.subscribe(ts); @@ -153,7 +154,7 @@ void testWithBackpressureOneByOne(long start) { void testWithBackpressureAllAtOnce(long start) { Flowable source = Flowable.rangeLong(start, 100); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.request(100); source.subscribe(ts); @@ -183,7 +184,7 @@ public void testWithBackpressureAllAtOnce() { public void testWithBackpressureRequestWayMore() { Flowable source = Flowable.rangeLong(50, 100); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.request(150); source.subscribe(ts); @@ -293,21 +294,21 @@ public void countOne() { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.rangeLong(1, 2).subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1L, 2L); } @Test public void fusedReject() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.rangeLong(1, 2).subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1L, 2L); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java index b0af47585b..70738fa601 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRangeTest.java @@ -23,11 +23,12 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableRangeTest { @@ -97,7 +98,7 @@ public void testRangeWithOverflow5() { public void testBackpressureViaRequest() { Flowable f = Flowable.range(1, Flowable.bufferSize()); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.assertNoValues(); ts.request(1); @@ -125,7 +126,7 @@ public void testNoBackpressure() { Flowable f = Flowable.range(1, list.size()); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.assertNoValues(); ts.request(Long.MAX_VALUE); // infinite @@ -138,7 +139,7 @@ public void testNoBackpressure() { void testWithBackpressureOneByOne(int start) { Flowable source = Flowable.range(start, 100); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.request(1); source.subscribe(ts); @@ -153,7 +154,7 @@ void testWithBackpressureOneByOne(int start) { void testWithBackpressureAllAtOnce(int start) { Flowable source = Flowable.range(start, 100); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.request(100); source.subscribe(ts); @@ -183,7 +184,7 @@ public void testWithBackpressureAllAtOnce() { public void testWithBackpressureRequestWayMore() { Flowable source = Flowable.range(50, 100); - TestSubscriber ts = new TestSubscriber(0L); + TestSubscriberEx ts = new TestSubscriberEx(0L); ts.request(150); source.subscribe(ts); @@ -286,12 +287,12 @@ public void negativeCount() { @Test public void requestWrongFusion() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.range(1, 5) .subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); } @@ -304,21 +305,21 @@ public void countOne() { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Flowable.range(1, 2).subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.SYNC) + ts.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2); } @Test public void fusedReject() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ASYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ASYNC); Flowable.range(1, 2).subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE) + ts.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java index 37d7012065..57c196c78e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceTest.java @@ -32,6 +32,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableReduceTest { Subscriber subscriber; @@ -258,7 +259,7 @@ public Integer apply(Integer a, Integer b) throws Exception { } }) .toFlowable() - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Reducer"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Source"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceWithSingleTest.java index 97793612be..26baa4ced6 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReduceWithSingleTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.BiFunction; import io.reactivex.internal.functions.Functions; +import io.reactivex.testsupport.TestHelper; public class FlowableReduceWithSingleTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java index e2262718e6..6ccde797ae 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRefCountTest.java @@ -40,6 +40,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableRefCountTest { @@ -212,12 +213,12 @@ public void run() { Thread.sleep(50); } catch (InterruptedException e) { } - ts1.dispose(); - ts2.dispose(); + ts1.cancel(); + ts2.cancel(); ts1.assertNoErrors(); ts2.assertNoErrors(); - assertTrue(ts1.valueCount() > 0); - assertTrue(ts2.valueCount() > 0); + assertTrue(ts1.values().size() > 0); + assertTrue(ts2.values().size() > 0); } assertEquals(10, subscribeCount.get()); @@ -247,13 +248,13 @@ public void run() { } }); - TestSubscriber s = new TestSubscriber(); + TestSubscriberEx s = new TestSubscriberEx(); f.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(s); System.out.println("send unsubscribe"); // wait until connected subscribeLatch.await(); // now unsubscribe - s.dispose(); + s.cancel(); System.out.println("DONE sending unsubscribe ... now waiting"); if (!unsubscribeLatch.await(3000, TimeUnit.MILLISECONDS)) { System.out.println("Errors: " + s.errors()); @@ -292,12 +293,12 @@ public void accept(Subscription s) { } }); - TestSubscriber s = new TestSubscriber(); + TestSubscriberEx s = new TestSubscriberEx(); f.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(s); System.out.println("send unsubscribe"); // now immediately unsubscribe while subscribeOn is racing to subscribe - s.dispose(); + s.cancel(); // this generally will mean it won't even subscribe as it is already unsubscribed by the time connect() gets scheduled // give time to the counter to update Thread.sleep(10); @@ -516,8 +517,8 @@ public Integer apply(Integer t1, Integer t2) { }) .publish().refCount(); - TestSubscriber ts1 = new TestSubscriber(); - TestSubscriber ts2 = new TestSubscriber(); + TestSubscriberEx ts1 = new TestSubscriberEx(); + TestSubscriberEx ts2 = new TestSubscriberEx(); combined.subscribe(ts1); combined.subscribe(ts2); @@ -777,11 +778,11 @@ public Object call() throws Exception { .publish() .refCount(); - Disposable d1 = source.test(); - Disposable d2 = source.test(); + TestSubscriber d1 = source.test(); + TestSubscriber d2 = source.test(); - d1.dispose(); - d2.dispose(); + d1.cancel(); + d2.cancel(); d1 = null; d2 = null; @@ -1409,7 +1410,6 @@ public void timeoutResetsSource() { o.connection = rc; o.timeout(rc); - assertTrue(tcf.reset); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java index fd5061d9ed..53e1dede83 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRepeatTest.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; @@ -33,6 +33,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableRepeatTest { @@ -163,7 +164,7 @@ public void testRepeatAndDistinctUnbounded() { .repeat(3) .distinct(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); src.subscribe(ts); @@ -190,7 +191,7 @@ public Flowable apply(Integer x) { }) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertNoValues(); @@ -204,7 +205,7 @@ public void repeatScheduled() { Flowable.just(1).subscribeOn(Schedulers.computation()).repeat(5).subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValues(1, 1, 1, 1, 1); ts.assertNoErrors(); ts.assertComplete(); @@ -481,7 +482,7 @@ public void run() { TestHelper.race(r1, r2); - ts.dispose(); + ts.cancel(); } if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java index 06a9bad237..3324a760c8 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableReplayTest.java @@ -41,6 +41,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableReplayTest { @Test @@ -808,8 +809,8 @@ public void accept(long t) { }); ConnectableFlowable cf = source.replay(); - TestSubscriber ts1 = new TestSubscriber(10L); - TestSubscriber ts2 = new TestSubscriber(90L); + TestSubscriberEx ts1 = new TestSubscriberEx(10L); + TestSubscriberEx ts2 = new TestSubscriberEx(90L); cf.subscribe(ts1); cf.subscribe(ts2); @@ -839,8 +840,8 @@ public void accept(long t) { }); ConnectableFlowable cf = source.replay(50); - TestSubscriber ts1 = new TestSubscriber(10L); - TestSubscriber ts2 = new TestSubscriber(90L); + TestSubscriberEx ts1 = new TestSubscriberEx(10L); + TestSubscriberEx ts2 = new TestSubscriberEx(90L); cf.subscribe(ts1); cf.subscribe(ts2); @@ -862,7 +863,7 @@ public void accept(long t) { public void testColdReplayNoBackpressure() { Flowable source = Flowable.range(0, 1000).replay().autoConnect(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.subscribe(ts); @@ -894,7 +895,7 @@ public void testColdReplayBackpressure() { assertEquals((Integer)i, onNextEvents.get(i)); } - ts.dispose(); + ts.cancel(); } @Test @@ -961,7 +962,7 @@ public void testUnsubscribeSource() throws Throwable { @Test public void testTake() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable cached = Flowable.range(1, 100).replay().autoConnect(); cached.take(10).subscribe(ts); @@ -975,21 +976,21 @@ public void testTake() { public void testAsync() { Flowable source = Flowable.range(1, 10000); for (int i = 0; i < 100; i++) { - TestSubscriber ts1 = new TestSubscriber(); + TestSubscriberEx ts1 = new TestSubscriberEx(); Flowable cached = source.replay().autoConnect(); cached.observeOn(Schedulers.computation()).subscribe(ts1); - ts1.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts1.awaitDone(2, TimeUnit.SECONDS); ts1.assertNoErrors(); ts1.assertTerminated(); assertEquals(10000, ts1.values().size()); - TestSubscriber ts2 = new TestSubscriber(); + TestSubscriberEx ts2 = new TestSubscriberEx(); cached.observeOn(Schedulers.computation()).subscribe(ts2); - ts2.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts2.awaitDone(2, TimeUnit.SECONDS); ts2.assertNoErrors(); ts2.assertTerminated(); assertEquals(10000, ts2.values().size()); @@ -1005,9 +1006,9 @@ public void testAsyncComeAndGo() { Flowable output = cached.observeOn(Schedulers.computation(), false, 1024); - List> list = new ArrayList>(100); + List> list = new ArrayList>(100); for (int i = 0; i < 100; i++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); list.add(ts); output.skip(i * 10).take(10).subscribe(ts); } @@ -1017,8 +1018,8 @@ public void testAsyncComeAndGo() { expected.add((long)(i - 10)); } int j = 0; - for (TestSubscriber ts : list) { - ts.awaitTerminalEvent(3, TimeUnit.SECONDS); + for (TestSubscriberEx ts : list) { + ts.awaitDone(3, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertTerminated(); @@ -1046,10 +1047,10 @@ public void subscribe(Subscriber t) { } }); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); firehose.replay().autoConnect().observeOn(Schedulers.computation()).takeLast(100).subscribe(ts); - ts.awaitTerminalEvent(3, TimeUnit.SECONDS); + ts.awaitDone(3, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertTerminated(); @@ -1062,14 +1063,14 @@ public void testValuesAndThenError() { .concatWith(Flowable.error(new TestException())) .replay().autoConnect(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.subscribe(ts); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); ts.assertNotComplete(); Assert.assertEquals(1, ts.errors().size()); - TestSubscriber ts2 = new TestSubscriber(); + TestSubscriberEx ts2 = new TestSubscriberEx(); source.subscribe(ts2); ts2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); @@ -1125,7 +1126,7 @@ public void accept(long t) { out.subscribe(ts1); out.subscribe(ts2); - ts2.dispose(); + ts2.cancel(); Assert.assertEquals(Arrays.asList(5L, 5L), requests); } @@ -1141,7 +1142,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries() { ts1.assertValues(1, 2); ts1.assertNoErrors(); - ts1.dispose(); + ts1.cancel(); TestSubscriber ts2 = new TestSubscriber(2L); @@ -1149,7 +1150,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries() { ts2.assertValues(2, 3); ts2.assertNoErrors(); - ts2.dispose(); + ts2.cancel(); TestSubscriber ts21 = new TestSubscriber(1L); @@ -1157,7 +1158,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries() { ts21.assertValues(3); ts21.assertNoErrors(); - ts21.dispose(); + ts21.cancel(); TestSubscriber ts22 = new TestSubscriber(1L); @@ -1165,7 +1166,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries() { ts22.assertValues(3); ts22.assertNoErrors(); - ts22.dispose(); + ts22.cancel(); TestSubscriber ts3 = new TestSubscriber(); @@ -1188,7 +1189,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries2() { ts1.assertValues(1, 2); ts1.assertNoErrors(); - ts1.dispose(); + ts1.cancel(); TestSubscriber ts11 = new TestSubscriber(2L); @@ -1196,7 +1197,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries2() { ts11.assertValues(1, 2); ts11.assertNoErrors(); - ts11.dispose(); + ts11.cancel(); TestSubscriber ts2 = new TestSubscriber(3L); @@ -1204,7 +1205,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries2() { ts2.assertValues(1, 2, 3); ts2.assertNoErrors(); - ts2.dispose(); + ts2.cancel(); TestSubscriber ts21 = new TestSubscriber(1L); @@ -1212,7 +1213,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries2() { ts21.assertValues(2); ts21.assertNoErrors(); - ts21.dispose(); + ts21.cancel(); TestSubscriber ts22 = new TestSubscriber(1L); @@ -1220,7 +1221,7 @@ public void testSubscribersComeAndGoAtRequestBoundaries2() { ts22.assertValues(2); ts22.assertNoErrors(); - ts22.dispose(); + ts22.cancel(); TestSubscriber ts3 = new TestSubscriber(); @@ -1432,7 +1433,7 @@ protected void subscribeActual(Subscriber subscriber) { } }.replay() .autoConnect() - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -1484,7 +1485,7 @@ public void unsubscribeOnNextRace() { Runnable r1 = new Runnable() { @Override public void run() { - ts1.dispose(); + ts1.cancel(); } }; @@ -1520,7 +1521,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - ts1.dispose(); + ts1.cancel(); } }; @@ -1750,7 +1751,7 @@ public Publisher apply(Flowable v) throws Exception { return null; } }, Schedulers.trampoline()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The selector returned a null Publisher"); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java index 67ddc66008..dc4302a1c7 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryTest.java @@ -25,7 +25,7 @@ import org.mockito.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; import io.reactivex.flowables.GroupedFlowable; @@ -36,6 +36,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableRetryTest { @@ -90,7 +91,7 @@ public Flowable apply(Tuple t) { }}); } }).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); InOrder inOrder = inOrder(consumer); @@ -155,7 +156,7 @@ public void accept(Throwable e) { }) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); InOrder inOrder = inOrder(subscriber); // should show 3 attempts inOrder.verify(subscriber, times(1 + numRetries)).onNext("beginningEveryTime"); @@ -719,9 +720,9 @@ public void testRetryWithBackpressure() throws InterruptedException { for (int i = 0; i < 400; i++) { Subscriber subscriber = TestHelper.mockSubscriber(); Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numRetries)); - TestSubscriber ts = new TestSubscriber(subscriber); + TestSubscriberEx ts = new TestSubscriberEx(subscriber); origin.retry().observeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); InOrder inOrder = inOrder(subscriber); // should have no errors @@ -762,10 +763,10 @@ public void run() { final AtomicInteger nexts = new AtomicInteger(); try { Flowable origin = Flowable.unsafeCreate(new FuncWithErrors(numRetries)); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); origin.retry() .observeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + ts.awaitDone(2500, TimeUnit.MILLISECONDS); List onNextEvents = new ArrayList(ts.values()); if (onNextEvents.size() != numRetries + 2) { for (Throwable t : ts.errors()) { @@ -1269,7 +1270,7 @@ public void run() { TestHelper.race(r1, r2); - ts.dispose(); + ts.cancel(); } if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java index de31e283a4..5e37c7066e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableRetryWithPredicateTest.java @@ -26,7 +26,7 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; @@ -34,7 +34,8 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableRetryWithPredicateTest { BiPredicate retryTwice = new BiPredicate() { @@ -278,7 +279,7 @@ public void testTimeoutWithRetry() { @Test public void testIssue2826() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final RuntimeException e = new RuntimeException("You shall not pass"); final AtomicInteger c = new AtomicInteger(); Flowable.just(1).map(new Function() { @@ -394,14 +395,14 @@ public boolean test(Integer t1, Throwable t2) { @Test public void predicateThrows() { - TestSubscriber ts = Flowable.error(new TestException("Outer")) + TestSubscriberEx ts = Flowable.error(new TestException("Outer")) .retry(new Predicate() { @Override public boolean test(Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -414,7 +415,7 @@ public boolean test(Throwable e) throws Exception { public void dontRetry() { Flowable.error(new TestException("Outer")) .retry(Functions.alwaysFalse()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Outer"); } @@ -454,14 +455,14 @@ public void run() { @Test public void bipredicateThrows() { - TestSubscriber ts = Flowable.error(new TestException("Outer")) + TestSubscriberEx ts = Flowable.error(new TestException("Outer")) .retry(new BiPredicate() { @Override public boolean test(Integer n, Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java index 74cbcc24c2..46b5291fc4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSampleTest.java @@ -30,6 +30,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableSampleTest { private TestScheduler scheduler; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScalarXMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScalarXMapTest.java index bebfb7178e..7f42671d8c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScalarXMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScalarXMapTest.java @@ -23,6 +23,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableScalarXMapTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java index c36d6f5e4f..69f45ab075 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableScanTest.java @@ -14,17 +14,17 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.atomic.*; import org.junit.*; import org.reactivestreams.*; import io.reactivex.*; -import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.flowable.*; import io.reactivex.flowable.FlowableEventStream.Event; @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableScanTest { @@ -314,7 +315,7 @@ public Integer apply(Integer t1, Integer t2) { } }).take(1); - TestSubscriber subscriber = new TestSubscriber(); + TestSubscriberEx subscriber = new TestSubscriberEx(); f.subscribe(subscriber); subscriber.assertValue(0); subscriber.assertTerminated(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java index fb65114e42..7349918417 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSequenceEqualTest.java @@ -32,6 +32,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableSequenceEqualTest { @@ -320,7 +321,7 @@ public void onNextCancelRace() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -474,7 +475,7 @@ protected void subscribeActual(Subscriber s) { } }, 8) .toFlowable() - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -537,7 +538,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -574,7 +575,7 @@ protected void subscribeActual(Subscriber s) { s.onError(new TestException("Second")); } }, 8) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java index 6094955e83..5366331d68 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSerializeTest.java @@ -25,6 +25,7 @@ import io.reactivex.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.subscribers.DefaultSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableSerializeTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java index 62f662804f..06b0bfa3af 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSingleTest.java @@ -29,6 +29,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableSingleTest { @@ -680,7 +681,7 @@ public void singleOrErrorMultipleElements() { public void singleOrErrorError() { Flowable.error(new RuntimeException("error")) .singleOrError() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java index 11680a0927..3dcae5561b 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTest.java @@ -14,19 +14,22 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.Arrays; +import java.util.concurrent.TimeUnit; import org.junit.*; import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableSkipLastTest { @@ -103,9 +106,9 @@ public void testSkipLastWithBackpressure() { Flowable f = Flowable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10); TestSubscriber ts = new TestSubscriber(); f.observeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals((Flowable.bufferSize()) - 10, ts.valueCount()); + assertEquals((Flowable.bufferSize()) - 10, ts.values().size()); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java index d24a84b4b6..4042b4e003 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipLastTimedTest.java @@ -28,6 +28,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableSkipLastTimedTest { @@ -242,7 +243,7 @@ public void observeOn() { Flowable.range(1, 1000) .skipLast(0, TimeUnit.SECONDS) .observeOn(Schedulers.single(), false, 16) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java index c2f8c2f40f..fca1c9bf5c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.Arrays; @@ -23,9 +24,10 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.functions.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableSkipTest { @@ -153,16 +155,14 @@ public void accept(long n) { ts.request(1); ts.request(1); Thread.sleep(100); - ts.dispose(); - // FIXME not assertable anymore -// ts.assertUnsubscribed(); + ts.cancel(); ts.assertNoErrors(); assertEquals(6, requests.get()); } @Test public void testRequestOverflowDoesNotOccur() { - TestSubscriber ts = new TestSubscriber(Long.MAX_VALUE - 1); + TestSubscriberEx ts = new TestSubscriberEx(Long.MAX_VALUE - 1); Flowable.range(1, 10).skip(5).subscribe(ts); ts.assertTerminated(); ts.assertComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java index 0033cb4559..0d02882e11 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipTimedTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class FlowableSkipTimedTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java index a770b8520b..4d5619b915 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipUntilTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class FlowableSkipUntilTest { Subscriber subscriber; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java index b9574cd8ef..6231dce3cf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSkipWhileTest.java @@ -25,6 +25,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class FlowableSkipWhileTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java index 6b1b24b78e..356b2fa62c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSubscribeOnTest.java @@ -18,18 +18,19 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import io.reactivex.annotations.NonNull; import org.junit.*; import org.reactivestreams.*; import io.reactivex.*; import io.reactivex.Scheduler.Worker; +import io.reactivex.annotations.NonNull; import io.reactivex.disposables.Disposable; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.operators.flowable.FlowableSubscribeOn.SubscribeOnSubscriber; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableSubscribeOnTest { @@ -69,7 +70,7 @@ public void subscribe( // wait for scheduling scheduled.await(); // trigger unsubscribe - ts.dispose(); + ts.cancel(); latch.countDown(); doneLatch.await(); ts.assertNoErrors(); @@ -79,7 +80,7 @@ public void subscribe( @Test @Ignore("Publisher.subscribe can't throw") public void testThrownErrorHandling() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.unsafeCreate(new Publisher() { @Override @@ -88,13 +89,13 @@ public void subscribe(Subscriber s) { } }).subscribeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + ts.awaitDone(1000, TimeUnit.MILLISECONDS); ts.assertTerminated(); } @Test public void testOnError() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.unsafeCreate(new Publisher() { @Override @@ -104,7 +105,7 @@ public void subscribe(Subscriber s) { } }).subscribeOn(Schedulers.computation()).subscribe(ts); - ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + ts.awaitDone(1000, TimeUnit.MILLISECONDS); ts.assertTerminated(); } @@ -183,8 +184,8 @@ public void subscribe(Subscriber sub) { }).subscribeOn(Schedulers.newThread()).take(10).subscribe(ts); - ts.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); - ts.dispose(); + ts.awaitDone(1000, TimeUnit.MILLISECONDS); + ts.cancel(); Thread.sleep(200); // give time for the loop to continue ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); assertEquals(10, count.get()); @@ -193,7 +194,7 @@ public void subscribe(Subscriber sub) { @Test public void testBackpressureReschedulesCorrectly() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(10); - TestSubscriber ts = new TestSubscriber(new DefaultSubscriber() { + TestSubscriberEx ts = new TestSubscriberEx(new DefaultSubscriber() { @Override public void onComplete() { @@ -216,7 +217,7 @@ public void onNext(Integer t) { System.out.println("First schedule: " + t); assertTrue(t.getName().startsWith("Rx")); ts.request(10); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); System.out.println("After reschedule: " + ts.lastThread()); assertEquals(t, ts.lastThread()); } @@ -268,7 +269,7 @@ public void onNext(Integer t) { } }).subscribeOn(Schedulers.newThread()).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } @@ -276,8 +277,10 @@ public void onNext(Integer t) { public void cancelBeforeActualSubscribe() { TestScheduler test = new TestScheduler(); - TestSubscriber ts = Flowable.just(1).hide() - .subscribeOn(test).test(Long.MAX_VALUE, true); + TestSubscriberEx ts = Flowable.just(1) + .hide() + .subscribeOn(test) + .to(TestHelper.testConsumer(true)); test.advanceTimeBy(1, TimeUnit.SECONDS); @@ -346,7 +349,7 @@ public void subscribe(FlowableEmitter s) throws Exception { .assertNoErrors() .assertComplete(); - int c = ts.valueCount(); + int c = ts.values().size(); assertTrue("" + c, c > Flowable.bufferSize()); } @@ -393,7 +396,7 @@ public void subscribe(FlowableEmitter s) throws Exception { .assertNoErrors() .assertComplete(); - int c = ts.valueCount(); + int c = ts.values().size(); assertTrue("" + c, c > Flowable.bufferSize()); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java index f429d8e172..353c764ad3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchIfEmptyTest.java @@ -210,6 +210,6 @@ public void cancel() { ts.assertNotComplete(); ts.assertNoErrors(); ts.assertValueCount(2); - ts.dispose(); + ts.cancel(); } } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java index dc5f2a8313..eb59517695 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableSwitchTest.java @@ -35,6 +35,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableSwitchTest { @@ -449,7 +450,7 @@ public void testBackpressure() { publishCompleted(o2, 50); publishCompleted(o3, 55); - final TestSubscriber testSubscriber = new TestSubscriber(); + final TestSubscriberEx testSubscriber = new TestSubscriberEx(); Flowable.switchOnNext(o).subscribe(new DefaultSubscriber() { private int requested; @@ -524,11 +525,11 @@ public String apply(Long i) { .share() ; - TestSubscriber ts = new TestSubscriber() { + TestSubscriberEx ts = new TestSubscriberEx() { @Override public void onNext(String t) { super.onNext(t); - if (valueCount() == 250) { + if (values().size() == 250) { onComplete(); dispose(); } @@ -536,14 +537,14 @@ public void onNext(String t) { }; src.subscribe(ts); - ts.awaitTerminalEvent(10, TimeUnit.SECONDS); + ts.awaitDone(10, TimeUnit.SECONDS); - System.out.println("> testIssue2654: " + ts.valueCount()); + System.out.println("> testIssue2654: " + ts.values().size()); ts.assertTerminated(); ts.assertNoErrors(); - Assert.assertEquals(250, ts.valueCount()); + Assert.assertEquals(250, ts.values().size()); } @Test(timeout = 10000) @@ -562,7 +563,7 @@ public Flowable apply(Long t) { .subscribe(ts); ts.request(Long.MAX_VALUE - 100); ts.request(1); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); } @Test(timeout = 10000) @@ -578,8 +579,8 @@ public Flowable apply(Long t) { }).take(3)).subscribe(ts); ts.request(Long.MAX_VALUE - 1); ts.request(2); - ts.awaitTerminalEvent(); - assertTrue(ts.valueCount() > 0); + ts.awaitDone(5, TimeUnit.SECONDS); + assertTrue(ts.values().size() > 0); } @Test(timeout = 10000) @@ -598,7 +599,7 @@ public Flowable apply(Long t) { Thread.sleep(250); ts.request(Long.MAX_VALUE - 1); ts.request(Long.MAX_VALUE - 1); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValueCount(7); } @@ -627,8 +628,8 @@ public void accept(long v) { Thread.sleep(250); ts.request(Long.MAX_VALUE - 1); ts.request(Long.MAX_VALUE - 1); - ts.awaitTerminalEvent(); - assertTrue(ts.valueCount() > 0); + ts.awaitDone(5, TimeUnit.SECONDS); + assertTrue(ts.values().size() > 0); System.out.println(requests); assertEquals(5, requests.size()); assertEquals(Long.MAX_VALUE, (long) requests.get(requests.size() - 1)); @@ -638,8 +639,8 @@ public void accept(long v) { public void delayErrors() { PublishProcessor> source = PublishProcessor.create(); - TestSubscriber ts = source.switchMapDelayError(Functions.>identity()) - .test(); + TestSubscriberEx ts = source.switchMapDelayError(Functions.>identity()) + .to(TestHelper.testConsumer()); ts.assertNoValues() .assertNoErrors() @@ -1182,9 +1183,9 @@ public void fusedBoundary() { String thread = Thread.currentThread().getName(); Flowable.range(1, 10000) - .switchMap(new Function>() { + .switchMap(new Function>() { @Override - public Flowable apply(Integer v) + public Flowable apply(Integer v) throws Exception { return Flowable.just(2).hide() .observeOn(Schedulers.single()) @@ -1196,7 +1197,7 @@ public Object apply(Integer w) throws Exception { }); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertNever(thread) .assertNoErrors() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java index 5a94904936..9e43f4b481 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastOneTest.java @@ -20,16 +20,17 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.DefaultSubscriber; +import io.reactivex.testsupport.*; public class FlowableTakeLastOneTest { @Test public void testLastOfManyReturnsLast() { - TestSubscriber s = new TestSubscriber(); + TestSubscriberEx s = new TestSubscriberEx(); Flowable.range(1, 10).takeLast(1).subscribe(s); s.assertValue(10); s.assertNoErrors(); @@ -40,7 +41,7 @@ public void testLastOfManyReturnsLast() { @Test public void testLastOfEmptyReturnsEmpty() { - TestSubscriber s = new TestSubscriber(); + TestSubscriberEx s = new TestSubscriberEx(); Flowable.empty().takeLast(1).subscribe(s); s.assertNoValues(); s.assertNoErrors(); @@ -51,7 +52,7 @@ public void testLastOfEmptyReturnsEmpty() { @Test public void testLastOfOneReturnsLast() { - TestSubscriber s = new TestSubscriber(); + TestSubscriberEx s = new TestSubscriberEx(); Flowable.just(1).takeLast(1).subscribe(s); s.assertValue(1); s.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java index b0d1af43c7..e76bf9d3bf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTest.java @@ -14,21 +14,23 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.*; import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableTakeLastTest { @@ -114,7 +116,7 @@ public void testBackpressure1() { Flowable.range(1, 100000).takeLast(1) .observeOn(Schedulers.newThread()) .map(newSlowProcessor()).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertValue(100000); } @@ -124,9 +126,9 @@ public void testBackpressure2() { TestSubscriber ts = new TestSubscriber(); Flowable.range(1, 100000).takeLast(Flowable.bufferSize() * 4) .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 4, ts.values().size()); } private Function newSlowProcessor() { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java index 4864cac7f6..0904b13144 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeLastTimedTest.java @@ -27,6 +27,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableTakeLastTimedTest { @@ -281,7 +282,7 @@ public void observeOn() { .takeLast(1, TimeUnit.DAYS) .take(500) .observeOn(Schedulers.single(), true, 1) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java index 91d4d4ea8b..fc9eaf38db 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTest.java @@ -33,6 +33,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableTakeTest { @@ -300,7 +301,7 @@ public void testTakeObserveOn() { INFINITE_OBSERVABLE.onBackpressureDrop() .observeOn(Schedulers.newThread()).take(1).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); verify(subscriber).onNext(1L); @@ -407,7 +408,7 @@ public void accept(long n) { ts.request(1); ts.request(1); ts.request(1); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertComplete(); ts.assertNoErrors(); assertEquals(3, requests.get()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java index db1132e86c..4f702e6e48 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeTimedTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class FlowableTakeTimedTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java index acba2b1294..bf2d3b2282 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilPredicateTest.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -29,6 +29,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; ; public class FlowableTakeUntilPredicateTest { @@ -158,7 +159,7 @@ public boolean test(Integer v) { @Test public void testErrorIncludesLastValueAsCause() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final TestException e = new TestException("Forced failure"); Predicate predicate = new Predicate() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java index b254ecdf8d..819ce98dba 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeUntilTest.java @@ -19,11 +19,12 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableTakeUntilTest { @@ -189,7 +190,7 @@ public void testUntilFires() { PublishProcessor source = PublishProcessor.create(); PublishProcessor until = PublishProcessor.create(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.takeUntil(until).subscribe(ts); @@ -215,7 +216,7 @@ public void testMainCompletes() { PublishProcessor source = PublishProcessor.create(); PublishProcessor until = PublishProcessor.create(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.takeUntil(until).subscribe(ts); @@ -239,7 +240,7 @@ public void testDownstreamUnsubscribes() { PublishProcessor source = PublishProcessor.create(); PublishProcessor until = PublishProcessor.create(); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); source.takeUntil(until).take(1).subscribe(ts); @@ -417,7 +418,7 @@ public void untilPublisherDispose() { assertTrue("Main no subscribers?", main.hasSubscribers()); assertTrue("Other no subscribers?", other.hasSubscribers()); - ts.dispose(); + ts.cancel(); assertFalse("Main has subscribers?", main.hasSubscribers()); assertFalse("Other has subscribers?", other.hasSubscribers()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java index 97eac27982..b6b95a19d5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTakeWhileTest.java @@ -22,7 +22,7 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -30,6 +30,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableTakeWhileTest { @@ -268,7 +269,7 @@ public boolean test(Integer t1) { @Test public void testErrorCauseIncludesLastValue() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.just("abc").takeWhile(new Predicate() { @Override public boolean test(String t1) { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java index 2e5fd020e7..9434e25035 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleFirstTest.java @@ -29,6 +29,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class FlowableThrottleFirstTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java index 3f24c56585..a22d1e2a31 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableThrottleLatestTest.java @@ -26,6 +26,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableThrottleLatestTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java index 1dc6369aba..876da46b51 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeIntervalTest.java @@ -27,6 +27,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableTimeIntervalTest { diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java index 7e4b97c899..421b86a3ad 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutTests.java @@ -26,13 +26,14 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableTimeoutTests { private PublishProcessor underlyingSubject; @@ -78,12 +79,12 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { verify(subscriber).onNext("Two"); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); verify(subscriber, never()).onError(any(Throwable.class)); - ts.dispose(); + ts.cancel(); } @Test public void shouldTimeoutIfOnNextNotWithinTimeout() { - TestSubscriber subscriber = new TestSubscriber(); + TestSubscriberEx subscriber = new TestSubscriberEx(); withTimeout.subscribe(subscriber); @@ -93,7 +94,7 @@ public void shouldTimeoutIfOnNextNotWithinTimeout() { @Test public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { - TestSubscriber subscriber = new TestSubscriber(); + TestSubscriberEx subscriber = new TestSubscriberEx(); TestSubscriber ts = new TestSubscriber(subscriber); withTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); @@ -101,7 +102,7 @@ public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { subscriber.assertValue("One"); testScheduler.advanceTimeBy(TIMEOUT + 1, TimeUnit.SECONDS); subscriber.assertFailureAndMessage(TimeoutException.class, timeoutMessage(TIMEOUT, TIME_UNIT), "One"); - ts.dispose(); + ts.cancel(); } @Test @@ -114,7 +115,7 @@ public void shouldCompleteIfUnderlyingComletes() { testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); verify(subscriber).onComplete(); verify(subscriber, never()).onError(any(Throwable.class)); - ts.dispose(); + ts.cancel(); } @Test @@ -126,7 +127,7 @@ public void shouldErrorIfUnderlyingErrors() { underlyingSubject.onError(new UnsupportedOperationException()); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); verify(subscriber).onError(any(UnsupportedOperationException.class)); - ts.dispose(); + ts.cancel(); } @Test @@ -149,7 +150,7 @@ public void shouldSwitchToOtherIfOnNextNotWithinTimeout() { inOrder.verify(subscriber, times(1)).onNext("c"); inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - ts.dispose(); + ts.cancel(); } @Test @@ -172,7 +173,7 @@ public void shouldSwitchToOtherIfOnErrorNotWithinTimeout() { inOrder.verify(subscriber, times(1)).onNext("c"); inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - ts.dispose(); + ts.cancel(); } @Test @@ -195,7 +196,7 @@ public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() { inOrder.verify(subscriber, times(1)).onNext("c"); inOrder.verify(subscriber, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); - ts.dispose(); + ts.cancel(); } @Test @@ -214,7 +215,7 @@ public void shouldSwitchToOtherAndCanBeUnsubscribedIfOnNextNotWithinTimeout() { other.onNext("a"); other.onNext("b"); - ts.dispose(); + ts.cancel(); // The following messages should not be delivered. other.onNext("c"); @@ -234,7 +235,7 @@ public void shouldTimeoutIfSynchronizedFlowableEmitFirstOnNextNotWithinTimeout() final CountDownLatch exit = new CountDownLatch(1); final CountDownLatch timeoutSetuped = new CountDownLatch(1); - final TestSubscriber subscriber = new TestSubscriber(); + final TestSubscriberEx subscriber = new TestSubscriberEx(); new Thread(new Runnable() { @@ -283,7 +284,7 @@ public void subscribe(Subscriber subscriber) { TestScheduler testScheduler = new TestScheduler(); Flowable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - TestSubscriber subscriber = new TestSubscriber(); + TestSubscriberEx subscriber = new TestSubscriberEx(); observableWithTimeout.subscribe(subscriber); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); @@ -366,7 +367,7 @@ public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() { assertTrue(processor.hasSubscribers()); - subscriber.dispose(); + subscriber.cancel(); assertFalse(processor.hasSubscribers()); } @@ -520,7 +521,7 @@ public void onNextOnTimeoutRace() { final PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp.timeout(1, TimeUnit.SECONDS, sch).test(); + TestSubscriberEx ts = pp.timeout(1, TimeUnit.SECONDS, sch).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -538,8 +539,8 @@ public void run() { TestHelper.race(r1, r2); - if (ts.valueCount() != 0) { - if (ts.errorCount() != 0) { + if (ts.values().size() != 0) { + if (ts.errors().size() != 0) { ts.assertFailure(TimeoutException.class, 1); ts.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS)); } else { @@ -559,7 +560,7 @@ public void onNextOnTimeoutRaceFallback() { final PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp.timeout(1, TimeUnit.SECONDS, sch, Flowable.just(2)).test(); + TestSubscriberEx ts = pp.timeout(1, TimeUnit.SECONDS, sch, Flowable.just(2)).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -578,7 +579,7 @@ public void run() { TestHelper.race(r1, r2); if (ts.isTerminated()) { - int c = ts.valueCount(); + int c = ts.values().size(); if (c == 1) { int v = ts.values().get(0); assertTrue("" + v, v == 1 || v == 2); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java index 9622afc5db..75c6802825 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimeoutWithSelectorTest.java @@ -27,7 +27,7 @@ import org.mockito.stubbing.Answer; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; @@ -37,6 +37,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableTimeoutWithSelectorTest { @Test(timeout = 2000) @@ -431,7 +432,7 @@ public void badInnerSource() { try { PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp + TestSubscriberEx ts = pp .timeout(Functions.justFunction(new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { @@ -442,7 +443,7 @@ protected void subscribeActual(Subscriber subscriber) { subscriber.onComplete(); } })) - .test(); + .to(TestHelper.testConsumer()); pp.onNext(1); @@ -460,7 +461,7 @@ public void badInnerSourceOther() { try { PublishProcessor pp = PublishProcessor.create(); - TestSubscriber ts = pp + TestSubscriberEx ts = pp .timeout(Functions.justFunction(new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { @@ -471,7 +472,7 @@ protected void subscribeActual(Subscriber subscriber) { subscriber.onComplete(); } }), Flowable.just(2)) - .test(); + .to(TestHelper.testConsumer()); pp.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java index e5b9c61de4..ad72c8d052 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimerTest.java @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableTimerTest { @Mock @@ -79,7 +80,7 @@ public void testTimerPeriodically() { scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); ts.assertValues(0L, 1L, 2L, 3L); - ts.dispose(); + ts.cancel(); scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); ts.assertValues(0L, 1L, 2L, 3L); @@ -103,7 +104,7 @@ public void testInterval() { ts.assertNoErrors(); ts.assertNotComplete(); - ts.dispose(); + ts.cancel(); scheduler.advanceTimeTo(4, TimeUnit.SECONDS); ts.assertValues(0L, 1L); @@ -134,8 +135,8 @@ public void testWithMultipleSubscribersStartingAtSameTime() { ts2.assertNoErrors(); ts2.assertNotComplete(); - ts1.dispose(); - ts2.dispose(); + ts1.cancel(); + ts2.cancel(); scheduler.advanceTimeTo(4, TimeUnit.SECONDS); @@ -176,8 +177,8 @@ public void testWithMultipleStaggeredSubscribers() { ts2.assertValues(0L, 1L); - ts1.dispose(); - ts2.dispose(); + ts1.cancel(); + ts2.cancel(); ts1.assertValues(0L, 1L, 2L, 3L); ts1.assertNoErrors(); @@ -216,8 +217,8 @@ public void testWithMultipleStaggeredSubscribersAndPublish() { ts2.assertValues(2L, 3L); - ts1.dispose(); - ts2.dispose(); + ts1.cancel(); + ts2.cancel(); ts1.assertValues(0L, 1L, 2L, 3L); ts1.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java index 295f4d3a2b..2cb19f1e26 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableTimestampTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableTimestampTest { Subscriber subscriber; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToCompletableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToCompletableTest.java index acda9f3094..9441c56276 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToCompletableTest.java @@ -24,6 +24,7 @@ import io.reactivex.*; import io.reactivex.functions.Action; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; public class FlowableToCompletableTest { @@ -72,7 +73,7 @@ public void testEmptyObservable() { @Test public void testNeverObservable() { - TestSubscriber subscriber = TestSubscriber.create(); + TestSubscriberEx subscriber = new TestSubscriberEx(); Completable cmp = Flowable.never().ignoreElements(); cmp.toFlowable().subscribe(subscriber); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java index 2fb5920d57..6049350cc5 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToFutureTest.java @@ -24,6 +24,7 @@ import io.reactivex.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class FlowableToFutureTest { @@ -40,7 +41,7 @@ public void testSuccess() throws Exception { Flowable.fromFuture(future).subscribe(ts); - ts.dispose(); + ts.cancel(); verify(subscriber, times(1)).onNext(value); verify(subscriber, times(1)).onComplete(); @@ -82,7 +83,7 @@ public void testFailure() throws Exception { Flowable.fromFuture(future).subscribe(ts); - ts.dispose(); + ts.cancel(); verify(subscriber, never()).onNext(null); verify(subscriber, never()).onComplete(); @@ -100,7 +101,7 @@ public void testCancelledBeforeSubscribe() throws Exception { Subscriber subscriber = TestHelper.mockSubscriber(); TestSubscriber ts = new TestSubscriber(subscriber); - ts.dispose(); + ts.cancel(); Flowable.fromFuture(future).subscribe(ts); @@ -152,7 +153,7 @@ public Object get(long timeout, TimeUnit unit) throws InterruptedException, Exec Thread.sleep(100); - ts.dispose(); + ts.cancel(); ts.assertNoErrors(); ts.assertNoValues(); @@ -236,7 +237,7 @@ public void run() { task.run(); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValue(1); ts.assertNoErrors(); ts.assertComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java index 69aff310a1..7e4274ff2c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToListTest.java @@ -30,6 +30,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableToListTest { @@ -139,7 +140,7 @@ public void testAsyncRequestedFlowable() { Flowable> sorted = source.toList().toFlowable(); final CyclicBarrier cb = new CyclicBarrier(2); - final TestSubscriber> ts = new TestSubscriber>(0L); + final TestSubscriberEx> ts = new TestSubscriberEx>(0L); sorted.subscribe(ts); w.schedule(new Runnable() { @@ -152,7 +153,7 @@ public void run() { source.onNext(1); await(cb); source.onComplete(); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertTerminated(); ts.assertNoErrors(); ts.assertValue(Arrays.asList(1)); @@ -271,7 +272,7 @@ public void testAsyncRequested() { Single> sorted = source.toList(); final CyclicBarrier cb = new CyclicBarrier(2); - final TestObserver> to = new TestObserver>(); + final TestObserverEx> to = new TestObserverEx>(); sorted.subscribe(to); w.schedule(new Runnable() { @@ -284,7 +285,7 @@ public void run() { source.onNext(1); await(cb); source.onComplete(); - to.awaitTerminalEvent(1, TimeUnit.SECONDS); + to.awaitDone(1, TimeUnit.SECONDS); to.assertTerminated(); to.assertNoErrors(); to.assertValue(Arrays.asList(1)); @@ -364,7 +365,7 @@ public Collection get() throws Exception { } }) .toFlowable() - .test() + .to(TestHelper.>testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } @@ -393,7 +394,7 @@ public Collection get() throws Exception { return null; } }) - .test() + .to(TestHelper.>testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } @@ -413,7 +414,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -468,7 +469,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.valueCount() != 0) { + if (ts.values().size() != 0) { ts.assertValue(Arrays.asList(1)) .assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java index ab8cff04ed..0dcd1e4020 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMapTest.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class FlowableToMapTest { Subscriber objectSubscriber; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java index a45e2dfa65..b095e83d81 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToMultimapTest.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class FlowableToMultimapTest { Subscriber objectSubscriber; diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java index 173da4830d..3578d423f9 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableToSortedListTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.flowable; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; @@ -28,6 +29,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableToSortedListTest { @@ -107,7 +109,7 @@ public void testAsyncRequestedFlowable() { Flowable> sorted = source.toSortedList().toFlowable(); final CyclicBarrier cb = new CyclicBarrier(2); - final TestSubscriber> ts = new TestSubscriber>(0L); + final TestSubscriberEx> ts = new TestSubscriberEx>(0L); sorted.subscribe(ts); w.schedule(new Runnable() { @Override @@ -119,7 +121,7 @@ public void run() { source.onNext(1); await(cb); source.onComplete(); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertTerminated(); ts.assertNoErrors(); ts.assertValue(Arrays.asList(1)); @@ -242,7 +244,7 @@ public void testAsyncRequested() { Single> sorted = source.toSortedList(); final CyclicBarrier cb = new CyclicBarrier(2); - final TestObserver> to = new TestObserver>(); + final TestObserverEx> to = new TestObserverEx>(); sorted.subscribe(to); w.schedule(new Runnable() { @Override @@ -254,7 +256,7 @@ public void run() { source.onNext(1); await(cb); source.onComplete(); - to.awaitTerminalEvent(1, TimeUnit.SECONDS); + to.awaitDone(1, TimeUnit.SECONDS); to.assertTerminated(); to.assertNoErrors(); to.assertValue(Arrays.asList(1)); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java index cd6f22ea56..f1067481a4 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUnsubscribeOnTest.java @@ -19,17 +19,17 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; -import io.reactivex.annotations.NonNull; import org.junit.Test; import org.reactivestreams.*; import io.reactivex.*; +import io.reactivex.annotations.NonNull; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableUnsubscribeOnTest { @@ -54,13 +54,13 @@ public void subscribe(Subscriber t1) { } }); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); w.subscribeOn(uiEventLoop).observeOn(Schedulers.computation()) .unsubscribeOn(uiEventLoop) .take(2) .subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); Thread unsubscribeThread = subscription.getThread(); @@ -103,13 +103,13 @@ public void subscribe(Subscriber t1) { } }); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); w.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.computation()) .unsubscribeOn(uiEventLoop) .take(2) .subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); Thread unsubscribeThread = subscription.getThread(); @@ -201,7 +201,7 @@ public void takeHalf() { int elements = 1024; Flowable.range(0, elements * 2).unsubscribeOn(Schedulers.single()) .take(elements) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertValueCount(elements) .assertComplete() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java index 5c7c0b1724..4a3df2737a 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableUsingTest.java @@ -23,7 +23,7 @@ import org.mockito.InOrder; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; @@ -31,6 +31,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableUsingTest { @@ -523,7 +524,7 @@ public Flowable apply(Object v) throws Exception { @Test public void supplierDisposerCrash() { - TestSubscriber ts = Flowable.using(new Supplier() { + TestSubscriberEx ts = Flowable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -539,7 +540,7 @@ public void accept(Object e) throws Exception { throw new TestException("Second"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -550,7 +551,7 @@ public void accept(Object e) throws Exception { @Test public void eagerOnErrorDisposerCrash() { - TestSubscriber ts = Flowable.using(new Supplier() { + TestSubscriberEx ts = Flowable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -566,7 +567,7 @@ public void accept(Object e) throws Exception { throw new TestException("Second"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -593,7 +594,7 @@ public void accept(Object e) throws Exception { throw new TestException("Second"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Second"); } @@ -631,7 +632,7 @@ public void sourceSupplierReturnsNull() { Flowable.using(Functions.justSupplier(1), Functions.justFunction((Publisher)null), Functions.emptyConsumer()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The sourceSupplier returned a null Publisher") ; } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java index 1719eff6dc..f3a4fc4ec3 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithFlowableTest.java @@ -18,13 +18,13 @@ import static org.mockito.Mockito.*; import java.util.*; -import java.util.concurrent.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.*; import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableWindowWithFlowableTest { @@ -370,7 +371,7 @@ public Flowable get() { assertTrue(source.hasSubscribers()); assertTrue(boundary.hasSubscribers()); - ts.dispose(); + ts.cancel(); assertTrue(source.hasSubscribers()); @@ -473,10 +474,10 @@ public void boundaryDispose2() { @Test public void boundaryOnError() { - TestSubscriber ts = Flowable.error(new TestException()) + TestSubscriberEx ts = Flowable.error(new TestException()) .window(Flowable.never()) .flatMap(Functions.>identity(), true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -776,7 +777,7 @@ public void mainAndBoundaryBothError() { try { final AtomicReference> ref = new AtomicReference>(); - TestSubscriber> ts = Flowable.error(new TestException("main")) + TestSubscriberEx> ts = Flowable.error(new TestException("main")) .window(new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { @@ -784,7 +785,7 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } }) - .test(); + .to(TestHelper.>testConsumer()); ts .assertValueCount(1) @@ -810,7 +811,7 @@ public void mainCompleteBoundaryErrorRace() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestSubscriber> ts = new Flowable() { + TestSubscriberEx> ts = new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { subscriber.onSubscribe(new BooleanSubscription()); @@ -824,7 +825,7 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } }) - .test(); + .to(TestHelper.>testConsumer()); Runnable r1 = new Runnable() { @Override @@ -903,7 +904,7 @@ public void takeOneAnotherBoundary() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestSubscriber> ts = new Flowable() { + TestSubscriberEx> ts = new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { subscriber.onSubscribe(new BooleanSubscription()); @@ -917,7 +918,7 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } }) - .test(); + .to(TestHelper.>testConsumer()); ts.assertValueCount(1) .assertNotTerminated() @@ -1082,7 +1083,7 @@ public void supplierMainAndBoundaryBothError() { try { final AtomicReference> ref = new AtomicReference>(); - TestSubscriber> ts = Flowable.error(new TestException("main")) + TestSubscriberEx> ts = Flowable.error(new TestException("main")) .window(Functions.justSupplier(new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { @@ -1090,7 +1091,7 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } })) - .test(); + .to(TestHelper.>testConsumer()); ts .assertValueCount(1) @@ -1116,7 +1117,7 @@ public void supplierMainCompleteBoundaryErrorRace() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestSubscriber> ts = new Flowable() { + TestSubscriberEx> ts = new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { subscriber.onSubscribe(new BooleanSubscription()); @@ -1130,7 +1131,7 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } })) - .test(); + .to(TestHelper.>testConsumer()); Runnable r1 = new Runnable() { @Override @@ -1209,7 +1210,7 @@ public void supplierTakeOneAnotherBoundary() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestSubscriber> ts = new Flowable() { + TestSubscriberEx> ts = new Flowable() { @Override protected void subscribeActual(Subscriber subscriber) { subscriber.onSubscribe(new BooleanSubscription()); @@ -1223,7 +1224,7 @@ protected void subscribeActual(Subscriber subscriber) { ref.set(subscriber); } })) - .test(); + .to(TestHelper.>testConsumer()); ts.assertValueCount(1) .assertNotTerminated() diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java index b6fb51f6d2..2ee9ca2652 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithSizeTest.java @@ -24,13 +24,14 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableWindowWithSizeTest { @@ -106,7 +107,8 @@ public void testSkipAndCountWindowsWithGaps() { @Test public void testWindowUnsubscribeNonOverlapping() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); + final AtomicInteger count = new AtomicInteger(); Flowable.merge(Flowable.range(1, 10000).doOnNext(new Consumer() { @@ -115,8 +117,10 @@ public void accept(Integer t1) { count.incrementAndGet(); } - }).window(5).take(2)).subscribe(ts); - ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + }).window(5).take(2)) + .subscribe(ts); + + ts.awaitDone(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // System.out.println(ts.getOnNextEvents()); @@ -125,7 +129,7 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeNonOverlappingAsyncSource() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final AtomicInteger count = new AtomicInteger(); Flowable.merge(Flowable.range(1, 100000) .doOnNext(new Consumer() { @@ -140,7 +144,7 @@ public void accept(Integer t1) { .window(5) .take(2)) .subscribe(ts); - ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + ts.awaitDone(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // make sure we don't emit all values ... the unsubscribe should propagate @@ -149,7 +153,7 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeOverlapping() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final AtomicInteger count = new AtomicInteger(); Flowable.merge(Flowable.range(1, 10000).doOnNext(new Consumer() { @@ -159,7 +163,7 @@ public void accept(Integer t1) { } }).window(5, 4).take(2)).subscribe(ts); - ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + ts.awaitDone(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); // System.out.println(ts.getOnNextEvents()); ts.assertValues(1, 2, 3, 4, 5, 5, 6, 7, 8, 9); @@ -168,7 +172,7 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeOverlappingAsyncSource() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final AtomicInteger count = new AtomicInteger(); Flowable.merge(Flowable.range(1, 100000) .doOnNext(new Consumer() { @@ -183,7 +187,7 @@ public void accept(Integer t1) { .window(5, 4) .take(2), 128) .subscribe(ts); - ts.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + ts.awaitDone(500, TimeUnit.MILLISECONDS); ts.assertTerminated(); ts.assertValues(1, 2, 3, 4, 5, 5, 6, 7, 8, 9); // make sure we don't emit all values ... the unsubscribe should propagate @@ -289,7 +293,7 @@ public Flowable apply(Flowable w) { } }).subscribe(ts); - ts.awaitTerminalEvent(2, TimeUnit.SECONDS); + ts.awaitDone(2, TimeUnit.SECONDS); ts.assertComplete(); ts.assertValueCount(22); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java index 965d278a23..10f4c854fb 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithStartEndFlowableTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableWindowWithStartEndFlowableTest { @@ -253,7 +254,7 @@ public Flowable apply(Integer t) { assertTrue(open.hasSubscribers()); assertTrue(close.hasSubscribers()); - ts.dispose(); + ts.cancel(); // Disposing the outer sequence stops the opening of new windows assertFalse(open.hasSubscribers()); @@ -455,11 +456,11 @@ public Flowable apply(Integer v) throws Exception { return flowableDisposed(closeDisposed); } }) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .assertNoErrors() .assertNotComplete() - .dispose(); + .cancel(); assertTrue(mainDisposed.get()); assertTrue(openDisposed.get()); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java index 157faae1a5..6012e4fbdf 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWindowWithTimeTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class FlowableWindowWithTimeTest { @@ -217,9 +218,9 @@ public void accept(Integer pv) { }) .subscribe(ts); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertComplete(); - Assert.assertTrue(ts.valueCount() != 0); + Assert.assertTrue(ts.values().size() != 0); } @Test @@ -549,7 +550,7 @@ public void restartTimer() { public void exactBoundaryError() { Flowable.error(new TestException()) .window(1, TimeUnit.DAYS, Schedulers.single(), 2, true) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .assertError(TestException.class) .assertNotComplete(); @@ -568,7 +569,7 @@ public void run() throws Exception { .window(1, TimeUnit.MILLISECONDS, Schedulers.single(), 2, true) .flatMap(Functions.>identity()) .take(500) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java index 070176bdb0..f64710fa1e 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableWithLatestFromTest.java @@ -23,7 +23,7 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableWithLatestFromTest { static final BiFunction COMBINER = new BiFunction() { @@ -89,7 +90,7 @@ public void testEmptySource() { Flowable result = source.withLatestFrom(other, COMBINER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -115,7 +116,7 @@ public void testEmptyOther() { Flowable result = source.withLatestFrom(other, COMBINER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -151,7 +152,7 @@ public void testUnsubscription() { other.onNext(1); source.onNext(1); - ts.dispose(); + ts.cancel(); ts.assertValue((1 << 8) + 1); ts.assertNoErrors(); @@ -168,7 +169,7 @@ public void testSourceThrows() { Flowable result = source.withLatestFrom(other, COMBINER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -196,7 +197,7 @@ public void testOtherThrows() { Flowable result = source.withLatestFrom(other, COMBINER); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -224,7 +225,7 @@ public void testFunctionThrows() { Flowable result = source.withLatestFrom(other, COMBINER_ERROR); - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -297,7 +298,7 @@ public void testBackpressure() { (6 << 8) + 1, (7 << 8) + 1 ); - ts.dispose(); + ts.cancel(); assertFalse("Other has observers!", other.hasSubscribers()); @@ -619,7 +620,7 @@ public Object apply(Object[] a) throws Exception { return a; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -654,7 +655,7 @@ public Object apply(Integer a, Integer b, Integer c) throws Exception { return a; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -681,7 +682,7 @@ public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -721,7 +722,7 @@ public Object apply(Object[] o) throws Exception { public void zeroOtherCombinerReturnsNull() { Flowable.just(1) .withLatestFrom(new Flowable[0], Functions.justFunction(null)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The combiner returned a null value"); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java index 6c46093017..8ba7223b5c 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipCompletionTest.java @@ -22,6 +22,7 @@ import io.reactivex.*; import io.reactivex.functions.BiFunction; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; /** * Systematically tests that when zipping an infinite and a finite Observable, diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java index a86de18f52..33d56c9997 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipIterableTest.java @@ -31,6 +31,7 @@ import io.reactivex.internal.util.CrashingIterable; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class FlowableZipIterableTest { BiFunction concat2Strings; @@ -396,7 +397,7 @@ public Object apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } diff --git a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java index 12f81c33e0..074fe84399 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/FlowableZipTest.java @@ -36,6 +36,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.*; public class FlowableZipTest { BiFunction concat2Strings; @@ -363,7 +364,7 @@ public void testAggregatorUnsubscribe() { verify(subscriber, never()).onComplete(); verify(subscriber, times(1)).onNext("helloworld"); - ts.dispose(); + ts.cancel(); r1.onNext("hello"); r2.onNext("again"); @@ -799,10 +800,10 @@ public String apply(Integer a, Integer b) { TestSubscriber ts = new TestSubscriber(); os.subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(5, ts.valueCount()); + assertEquals(5, ts.values().size()); assertEquals("1-1", ts.values().get(0)); assertEquals("2-2", ts.values().get(1)); assertEquals("5-5", ts.values().get(4)); @@ -973,7 +974,7 @@ public Object apply(final Object[] args) { TestSubscriber ts = new TestSubscriber(); f.subscribe(ts); - ts.awaitTerminalEvent(200, TimeUnit.MILLISECONDS); + ts.awaitDone(200, TimeUnit.MILLISECONDS); ts.assertNoValues(); } @@ -1015,9 +1016,9 @@ public String apply(Integer t1, Integer t2) { }).take(Flowable.bufferSize() * 2).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); } @@ -1039,9 +1040,9 @@ public String apply(Integer t1, Integer t2) { }).take(Flowable.bufferSize() * 2).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); } @@ -1063,9 +1064,9 @@ public String apply(Integer t1, Integer t2) { }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); assertTrue(generatedA.get() < (Flowable.bufferSize() * 3)); assertTrue(generatedB.get() < (Flowable.bufferSize() * 3)); @@ -1088,9 +1089,9 @@ public String apply(Integer t1, Integer t2) { }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); assertTrue(generatedA.get() < (Flowable.bufferSize() * 4)); assertTrue(generatedB.get() < (Flowable.bufferSize() * 4)); @@ -1113,9 +1114,9 @@ public String apply(Integer t1, Integer t2) { }).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, ts.valueCount()); + assertEquals(Flowable.bufferSize() * 2, ts.values().size()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); assertTrue(generatedA.get() < (Flowable.bufferSize() * 4)); assertTrue(generatedB.get() < (Flowable.bufferSize() * 4)); @@ -1234,7 +1235,7 @@ public Integer apply(Integer t1, Integer t2) { } }); - TestSubscriber ts = new TestSubscriber() { + TestSubscriberEx ts = new TestSubscriberEx() { @Override public void onNext(Integer t) { super.onNext(t); @@ -1285,7 +1286,7 @@ public Integer apply(Integer t1, Integer t2) { } }).subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); + ts.awaitDone(1, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertValue(11); } @@ -1397,13 +1398,13 @@ public void zip2DelayError() { Flowable error2 = Flowable.error(new TestException("Two")); Flowable source2 = Flowable.range(1, 2).concatWith(error2); - TestSubscriber ts = Flowable.zip(source1, source2, new BiFunction() { + TestSubscriberEx ts = Flowable.zip(source1, source2, new BiFunction() { @Override public Object apply(Integer a, Integer b) throws Exception { return "" + a + b; } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class, "11", "22"); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -1420,13 +1421,13 @@ public void zip2DelayErrorPrefetch() { Flowable error2 = Flowable.error(new TestException("Two")); Flowable source2 = Flowable.range(1, 2).concatWith(error2); - TestSubscriber ts = Flowable.zip(source1, source2, new BiFunction() { + TestSubscriberEx ts = Flowable.zip(source1, source2, new BiFunction() { @Override public Object apply(Integer a, Integer b) throws Exception { return "" + a + b; } }, true, 1) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class, "11", "22"); List errors = TestHelper.compositeList(ts.errors().get(0)); @@ -1637,7 +1638,7 @@ public void multiError() { @SuppressWarnings("rawtypes") final Subscriber[] sub = { null }; - TestSubscriber ts = Flowable.zip(pp, new Flowable() { + TestSubscriberEx ts = Flowable.zip(pp, new Flowable() { @Override protected void subscribeActual(Subscriber s) { sub[0] = s; @@ -1648,7 +1649,7 @@ public Object apply(Object a, Object b) throws Exception { return a; } }) - .test(); + .to(TestHelper.testConsumer()); pp.onError(new TestException("First")); @@ -1668,13 +1669,13 @@ public void singleErrorDelayed() { PublishProcessor pp1 = PublishProcessor.create(); PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriber ts = Flowable.zip(pp1, pp2, new BiFunction() { + TestSubscriberEx ts = Flowable.zip(pp1, pp2, new BiFunction() { @Override public Object apply(Object a, Object b) throws Exception { return a; } }, true) - .test(); + .to(TestHelper.testConsumer()); pp1.onError(new TestException("First")); pp2.onComplete(); @@ -1688,13 +1689,13 @@ public void singleErrorDelayedBackpressured() { PublishProcessor pp1 = PublishProcessor.create(); PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriber ts = Flowable.zip(pp1, pp2, new BiFunction() { + TestSubscriberEx ts = Flowable.zip(pp1, pp2, new BiFunction() { @Override public Object apply(Object a, Object b) throws Exception { return a; } }) - .test(0L); + .to(TestHelper.testSubscriber(0L)); pp1.onError(new TestException("First")); pp2.onComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java b/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java index 1f29136e00..dfb62e8770 100644 --- a/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java +++ b/src/test/java/io/reactivex/internal/operators/flowable/NotificationLiteTest.java @@ -17,11 +17,11 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.internal.util.NotificationLite; +import io.reactivex.testsupport.TestHelper; public class NotificationLiteTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java index a701a279ab..a39896004c 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeAmbTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class MaybeAmbTest { @@ -131,7 +132,7 @@ protected void subscribeActual( }, Maybe.never()) .test(); - to.cancel(); + to.dispose(); to.assertResult(1); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java index bae05a46b4..58178dec6d 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCacheTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class MaybeCacheTest { @@ -251,14 +252,14 @@ public void removeRemoveRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; Runnable r2 = new Runnable() { @Override public void run() { - to2.cancel(); + to2.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserverTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserverTest.java index e810f63e74..8c8d4b7763 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserverTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCallbackObserverTest.java @@ -13,12 +13,13 @@ package io.reactivex.internal.operators.maybe; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java index fb14e27a19..4ff3f1a0de 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatArrayTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class MaybeConcatArrayTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatIterableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatIterableTest.java index 1ae2ac56bb..8829d83f72 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeConcatIterableTest.java @@ -25,6 +25,7 @@ import io.reactivex.internal.util.CrashingMappedIterable; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class MaybeConcatIterableTest { @@ -45,7 +46,7 @@ public Iterator> iterator() { throw new TestException("iterator()"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -95,7 +96,7 @@ public Maybe apply(Integer v) throws Exception { return Maybe.just(1); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -107,7 +108,7 @@ public Maybe apply(Integer v) throws Exception { return Maybe.just(1); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java index 60f319f873..3ffd1d0e7f 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeContainsTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeContainsTest { @@ -54,7 +55,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCountTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCountTest.java index 3a0d29ab9c..04808f76e1 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCountTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeCountTest { @@ -49,7 +50,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCreateTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCreateTest.java index 1e114a2ac3..f711ed9f05 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeCreateTest.java @@ -24,6 +24,7 @@ import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class MaybeCreateTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java index 4719ac8977..b1723f0f70 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayOtherTest.java @@ -26,6 +26,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.*; public class MaybeDelayOtherTest { @@ -69,8 +70,8 @@ public void justWithOnComplete() { public void justWithOnError() { PublishProcessor pp = PublishProcessor.create(); - TestObserver to = Maybe.just(1) - .delay(pp).test(); + TestObserverEx to = Maybe.just(1) + .delay(pp).to(TestHelper.testConsumer()); to.assertEmpty(); @@ -123,8 +124,8 @@ public void emptyWithOnComplete() { public void emptyWithOnError() { PublishProcessor pp = PublishProcessor.create(); - TestObserver to = Maybe.empty() - .delay(pp).test(); + TestObserverEx to = Maybe.empty() + .delay(pp).to(TestHelper.testConsumer()); to.assertEmpty(); @@ -141,8 +142,8 @@ public void emptyWithOnError() { public void errorWithOnNext() { PublishProcessor pp = PublishProcessor.create(); - TestObserver to = Maybe.error(new TestException("Main")) - .delay(pp).test(); + TestObserverEx to = Maybe.error(new TestException("Main")) + .delay(pp).to(TestHelper.testConsumer()); to.assertEmpty(); @@ -159,8 +160,8 @@ public void errorWithOnNext() { public void errorWithOnComplete() { PublishProcessor pp = PublishProcessor.create(); - TestObserver to = Maybe.error(new TestException("Main")) - .delay(pp).test(); + TestObserverEx to = Maybe.error(new TestException("Main")) + .delay(pp).to(TestHelper.testConsumer()); to.assertEmpty(); @@ -177,8 +178,8 @@ public void errorWithOnComplete() { public void errorWithOnError() { PublishProcessor pp = PublishProcessor.create(); - TestObserver to = Maybe.error(new TestException("Main")) - .delay(pp).test(); + TestObserverEx to = Maybe.error(new TestException("Main")) + .delay(pp).to(TestHelper.testConsumer()); to.assertEmpty(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java index e1f7886cb3..c146abd252 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelaySubscriptionTest.java @@ -29,6 +29,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class MaybeDelaySubscriptionTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayTest.java index c6b9fdbd4c..d71b6573c8 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDelayTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.TestScheduler; +import io.reactivex.testsupport.TestHelper; public class MaybeDelayTest { @@ -69,7 +70,7 @@ public void disposeDuringDelay() { TestObserver to = Maybe.just(1).delay(100, TimeUnit.MILLISECONDS, scheduler) .test(); - to.cancel(); + to.dispose(); scheduler.advanceTimeBy(1, TimeUnit.SECONDS); @@ -84,7 +85,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDetachTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDetachTest.java index d1a28f2c47..4cc1746e8a 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDetachTest.java @@ -26,6 +26,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeDetachTest { @@ -77,7 +78,7 @@ protected void subscribeActual(MaybeObserver observer) { d = null; - to.cancel(); + to.dispose(); System.gc(); Thread.sleep(200); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccessTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccessTest.java index 31e046c41f..7ac8714d45 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccessTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoAfterSuccessTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class MaybeDoAfterSuccessTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoFinallyTest.java index bdfeee055b..e966d3f102 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoFinallyTest.java @@ -25,6 +25,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class MaybeDoFinallyTest implements Action { @@ -132,7 +133,7 @@ public void run() throws Exception { }) .test() .assertResult(1) - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -154,7 +155,7 @@ public void run() throws Exception { .filter(Functions.alwaysTrue()) .test() .assertResult(1) - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java index 19389db622..e4d718d32c 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnEventTest.java @@ -25,6 +25,7 @@ import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class MaybeDoOnEventTest { @@ -74,7 +75,7 @@ public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(bs.isDisposed()); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java index 0e90e57731..b4edc5e2c4 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeDoOnTerminateTest.java @@ -13,18 +13,17 @@ package io.reactivex.internal.operators.maybe; -import io.reactivex.Maybe; -import io.reactivex.TestHelper; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Action; -import io.reactivex.observers.TestObserver; -import org.junit.Test; +import static org.junit.Assert.assertTrue; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.Assert.assertTrue; +import org.junit.Test; + +import io.reactivex.Maybe; +import io.reactivex.exceptions.*; +import io.reactivex.functions.Action; +import io.reactivex.testsupport.*; public class MaybeDoOnTerminateTest { @@ -92,14 +91,14 @@ public void run() { @Test public void doOnTerminateErrorCrash() { - TestObserver to = Maybe.error(new TestException("Outer")) + TestObserverEx to = Maybe.error(new TestException("Outer")) .doOnTerminate(new Action() { @Override public void run() { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeEqualTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeEqualTest.java index a816e06faa..893e10e28d 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeEqualTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.BiPredicate; +import io.reactivex.testsupport.TestHelper; public class MaybeEqualTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFilterSingleTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFilterSingleTest.java index 6886734105..272a46c771 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFilterSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFilterSingleTest.java @@ -20,6 +20,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class MaybeFilterSingleTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelectorTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelectorTest.java index f817bfa839..a01c747af2 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapBiSelectorTest.java @@ -22,6 +22,7 @@ import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeFlatMapBiSelectorTest { @@ -220,7 +221,7 @@ public void mapperCancels() { .flatMap(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { - to.cancel(); + to.dispose(); return Maybe.just(2); } }, new BiFunction() { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletableTest.java index a3e8492ba4..e0d546c3c8 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapCompletableTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class MaybeFlatMapCompletableTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java index 450129d175..faa315d1dd 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableFlowableTest.java @@ -28,7 +28,8 @@ import io.reactivex.internal.util.CrashingIterable; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class MaybeFlatMapIterableFlowableTest { @@ -121,7 +122,7 @@ public Iterable apply(Integer v) throws Exception { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Maybe.just(1).flattenAsFlowable(new Function>() { @Override @@ -131,15 +132,15 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2); ; } @Test public void fusedNoSync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Maybe.just(1).flattenAsFlowable(new Function>() { @Override @@ -149,8 +150,8 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2); ; } @@ -164,7 +165,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(1, 100, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -177,7 +178,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 1, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -190,7 +191,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -203,7 +204,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -220,7 +221,7 @@ public Iterable apply(Object v) throws Exception { }) .hide() .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -240,7 +241,7 @@ public Iterable apply(Object v) throws Exception { } }) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -261,7 +262,7 @@ public Iterable apply(Object v) throws Exception { }) .take(500 * 1000) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) @@ -282,7 +283,7 @@ public Iterable apply(Object v) throws Exception { }) .observeOn(Schedulers.single()) .take(500 * 1000) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) @@ -338,7 +339,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -351,7 +352,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -364,7 +365,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test(2L) + .to(TestHelper.testSubscriber(2L)) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -377,7 +378,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test(2L) + .to(TestHelper.testSubscriber(2L)) .assertFailureAndMessage(TestException.class, "next()"); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservableTest.java index c4648d8331..e58eeb6902 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapIterableObservableTest.java @@ -27,8 +27,8 @@ import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.*; import io.reactivex.internal.util.CrashingIterable; -import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class MaybeFlatMapIterableObservableTest { @@ -99,7 +99,7 @@ public Iterable apply(Integer v) throws Exception { @Test public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Maybe.just(1).flattenAsObservable(new Function>() { @Override @@ -109,15 +109,15 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2); ; } @Test public void fusedNoSync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Maybe.just(1).flattenAsObservable(new Function>() { @Override @@ -127,9 +127,9 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)) - .assertResult(1, 2); + to.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) + .assertResult(1, 2) ; } @@ -142,7 +142,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(1, 100, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -155,7 +155,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 1, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -168,7 +168,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -181,7 +181,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -223,7 +223,7 @@ public Iterable apply(Object v) throws Exception { }) .hide() .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -243,7 +243,7 @@ public Iterable apply(Object v) throws Exception { } }) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -264,7 +264,7 @@ public Iterable apply(Object v) throws Exception { }) .take(500 * 1000) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) @@ -285,7 +285,7 @@ public Iterable apply(Object v) throws Exception { }) .observeOn(Schedulers.single()) .take(500 * 1000) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotificationTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotificationTest.java index 99427f91b9..350e8620e8 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotificationTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapNotificationTest.java @@ -21,7 +21,7 @@ import io.reactivex.exceptions.*; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class MaybeFlatMapNotificationTest { @@ -56,11 +56,11 @@ public void onSuccessNull() { @Test public void onErrorNull() { - TestObserver to = Maybe.error(new TestException()) + TestObserverEx to = Maybe.error(new TestException()) .flatMap(Functions.justFunction(Maybe.just(1)), Functions.justFunction((Maybe)null), Functions.justSupplier(Maybe.just(1))) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List ce = TestHelper.compositeList(to.errors().get(0)); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElementTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElementTest.java index f607308853..8f7c025529 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElementTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleElementTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class MaybeFlatMapSingleElementTest { @Test(expected = NullPointerException.class) @@ -63,7 +64,7 @@ public void flatMapSingleElementValueNull() { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(NullPointerException.class) .assertErrorMessage("The mapper returned a null SingleSource"); @@ -76,7 +77,7 @@ public void flatMapSingleElementValueErrorThrown() { throw new RuntimeException("something went terribly wrong!"); } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("something went terribly wrong!"); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleTest.java index 719b735269..2cb88bbd0e 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlatMapSingleTest.java @@ -20,6 +20,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class MaybeFlatMapSingleTest { @Test(expected = NullPointerException.class) @@ -65,7 +66,7 @@ public void flatMapSingleValueNull() { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(NullPointerException.class) .assertErrorMessage("The mapper returned a null SingleSource"); @@ -78,7 +79,7 @@ public void flatMapSingleValueErrorThrown() { throw new RuntimeException("something went terribly wrong!"); } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("something went terribly wrong!"); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlattenTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlattenTest.java index 40db818c41..32ff003d22 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlattenTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFlattenTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class MaybeFlattenTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromActionTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromActionTest.java index 02a289c084..3750621548 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromActionTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromActionTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class MaybeFromActionTest { @Test(expected = NullPointerException.class) @@ -142,7 +143,7 @@ public void run() throws Exception { assertTrue(cdl1.await(5, TimeUnit.SECONDS)); - to.cancel(); + to.dispose(); int timeout = 10; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java index c4ec8c267d..cc1b7b4f19 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCallableTest.java @@ -31,6 +31,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class MaybeFromCallableTest { @Test(expected = NullPointerException.class) @@ -151,7 +152,7 @@ public Integer call() throws Exception { assertTrue(cdl1.await(5, TimeUnit.SECONDS)); - to.cancel(); + to.dispose(); int timeout = 10; @@ -205,7 +206,7 @@ public String answer(InvocationOnMock invocation) throws Throwable { observerLatch.await(); // Unsubscribing before emission - outer.cancel(); + outer.dispose(); // Emitting result funcLatch.countDown(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java index 3086eb6c57..4b97a24993 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromCompletableTest.java @@ -17,6 +17,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamCompletableSource; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; import static org.junit.Assert.*; import org.junit.Test; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromFutureTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromFutureTest.java index d08b93a50a..d3874db3d0 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromFutureTest.java @@ -71,7 +71,7 @@ public void cancelWhileRunning() { FutureTask ft = new FutureTask(new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }, null); @@ -91,7 +91,7 @@ public void cancelAndCrashWhileRunning() { FutureTask ft = new FutureTask(new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); throw new TestException(); } }, null); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromRunnableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromRunnableTest.java index 3236c5f45f..c214d061e1 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromRunnableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromRunnableTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class MaybeFromRunnableTest { @Test(expected = NullPointerException.class) @@ -145,7 +146,7 @@ public void run() { assertTrue(cdl1.await(5, TimeUnit.SECONDS)); - to.cancel(); + to.dispose(); int timeout = 10; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromSingleTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromSingleTest.java index 19e9f8ec18..ed1e90b795 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeFromSingleTest.java @@ -21,6 +21,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamSingleSource; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeFromSingleTest { @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeHideTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeHideTest.java index c1b30e5b1b..59dbaff594 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeHideTest.java @@ -22,6 +22,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.ScalarSupplier; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeHideTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementTest.java index b57c2bdb5d..0df16c1493 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeIgnoreElementTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeIgnoreElementTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java index 3602d44aa0..3ead1d728b 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeIsEmptyTest.java @@ -20,6 +20,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeIsEmptyTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMapTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMapTest.java index 393c170e1b..59f8fc61fe 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMapTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; +import io.reactivex.testsupport.TestHelper; public class MaybeMapTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java index f429ecddf2..d9684f97bb 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMaterializeTest.java @@ -19,6 +19,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.subjects.MaybeSubject; +import io.reactivex.testsupport.TestHelper; public class MaybeMaterializeTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java index 38ce04fdf0..91d00272a4 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeArrayTest.java @@ -27,33 +27,34 @@ import io.reactivex.internal.operators.maybe.MaybeMergeArray.MergeMaybeObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class MaybeMergeArrayTest { @SuppressWarnings("unchecked") @Test public void normal() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Maybe.mergeArray(Maybe.just(1), Maybe.just(2)) .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + .assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2); } @SuppressWarnings("unchecked") @Test public void fusedPollMixed() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Maybe.mergeArray(Maybe.just(1), Maybe.empty(), Maybe.just(2)) .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2); } @@ -119,13 +120,13 @@ public void firstErrors() { @SuppressWarnings("unchecked") @Test public void errorFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Maybe.mergeArray(Maybe.error(new TestException()), Maybe.just(2)) .subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertFailure(TestException.class); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeTest.java index 176ae9c793..9855a15a7b 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeMergeTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class MaybeMergeTest { @@ -93,7 +94,7 @@ public Integer call() throws Exception { count.set(0); Maybe.mergeDelayError( Flowable.fromArray(sources), 1) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertFailureAndMessage(TestException.class, "2", 0, 0); } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeOfTypeTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeOfTypeTest.java index 814a0c8e16..985bf395f9 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeOfTypeTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeOfTypeTest.java @@ -20,6 +20,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeOfTypeTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeOnErrorXTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeOnErrorXTest.java index 1a300e27c3..5349eaed5e 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeOnErrorXTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeOnErrorXTest.java @@ -22,6 +22,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeOnErrorXTest { @@ -75,7 +76,7 @@ public Object apply(Throwable v) throws Exception { throw new IOException(); } }) - .test(), TestException.class, IOException.class); + .to(TestHelper.testConsumer()), TestException.class, IOException.class); } @SuppressWarnings("unchecked") @@ -88,7 +89,7 @@ public boolean test(Throwable v) throws Exception { throw new IOException(); } }) - .test(), TestException.class, IOException.class); + .to(TestHelper.testConsumer()), TestException.class, IOException.class); } @Test @@ -125,7 +126,7 @@ public Maybe apply(Throwable v) throws Exception { throw new IOException(); } }) - .test(), TestException.class, IOException.class); + .to(TestHelper.testConsumer()), TestException.class, IOException.class); } @Test @@ -209,7 +210,7 @@ public MaybeSource apply(Maybe v) throws Exception { public void onErrorNextIsAlsoError() { Maybe.error(new TestException("Main")) .onErrorResumeNext(Maybe.error(new TestException("Secondary"))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Secondary"); } } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybePeekTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybePeekTest.java index ee3a793efa..4c4fefb851 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybePeekTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybePeekTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.*; public class MaybePeekTest { @@ -52,7 +53,7 @@ public void doubleError() { final Throwable[] err = { null }; try { - TestObserver to = new Maybe() { + TestObserverEx to = new Maybe() { @Override protected void subscribeActual(MaybeObserver observer) { observer.onSubscribe(Disposables.empty()); @@ -66,7 +67,7 @@ public void accept(Throwable e) throws Exception { err[0] = e; } }) - .test(); + .to(TestHelper.testConsumer()); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -106,14 +107,14 @@ public void run() throws Exception { @Test public void doOnErrorThrows() { - TestObserver to = Maybe.error(new TestException("Main")) + TestObserverEx to = Maybe.error(new TestException("Main")) .doOnError(new Consumer() { @Override public void accept(Object t) throws Exception { throw new TestException("Inner"); } }) - .test(); + .to(TestHelper.testConsumer()); to.assertFailure(CompositeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOnTest.java index 52733deb42..0911ab398d 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSubscribeOnTest.java @@ -17,6 +17,7 @@ import io.reactivex.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class MaybeSubscribeOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java index 2c242fc1a5..ebd9295f7e 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptySingleTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeSwitchIfEmptySingleTest { @@ -56,7 +57,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -95,7 +96,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java index 142943ba67..25c8d2565b 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeSwitchIfEmptyTest.java @@ -22,6 +22,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeSwitchIfEmptyTest { @@ -71,7 +72,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -110,7 +111,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisherTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisherTest.java index 28bc00a1a2..b40791b435 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisherTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilPublisherTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeTakeUntilPublisherTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilTest.java index 8cd569869c..8d6230b96c 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTakeUntilTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.MaybeSubject; +import io.reactivex.testsupport.TestHelper; public class MaybeTakeUntilTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisherTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisherTest.java index 763af24904..13b3a80169 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisherTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutPublisherTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.*; public class MaybeTimeoutPublisherTest { @@ -194,7 +195,7 @@ public void onCompleteRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestObserver to = pp1.singleElement().timeout(pp2).test(); + TestObserverEx to = pp1.singleElement().timeout(pp2).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -213,7 +214,7 @@ public void run() { to.assertSubscribed().assertNoValues(); - if (to.errorCount() != 0) { + if (to.errors().size() != 0) { to.assertError(TimeoutException.class).assertNotComplete(); } else { to.assertNoErrors().assertComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutTest.java index eaa5ef25f6..04523dff65 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimeoutTest.java @@ -25,6 +25,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class MaybeTimeoutTest { @@ -314,7 +315,7 @@ public void onCompleteRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestObserver to = pp1.singleElement().timeout(pp2.singleElement()).test(); + TestObserverEx to = pp1.singleElement().timeout(pp2.singleElement()).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -333,7 +334,7 @@ public void run() { to.assertSubscribed().assertNoValues(); - if (to.errorCount() != 0) { + if (to.errors().size() != 0) { to.assertError(TimeoutException.class).assertNotComplete(); } else { to.assertNoErrors().assertComplete(); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimerTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimerTest.java index 05d33d7175..24d334b672 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeTimerTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class MaybeTimerTest { @@ -54,7 +55,7 @@ public Long apply(Long v) throws Exception { Thread.sleep(500); - to.cancel(); + to.dispose(); Thread.sleep(500); diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToCompletableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToCompletableTest.java index 6a5fe98c52..d40624528b 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToCompletableTest.java @@ -19,6 +19,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; +import io.reactivex.testsupport.TestHelper; public class MaybeToCompletableTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToFlowableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToFlowableTest.java index 506b542178..76c9ca4bd4 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToFlowableTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; +import io.reactivex.testsupport.TestHelper; public class MaybeToFlowableTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToObservableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToObservableTest.java index 8bec422c2f..89c8d13804 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToObservableTest.java @@ -19,6 +19,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; +import io.reactivex.testsupport.TestHelper; public class MaybeToObservableTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToSingleTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToSingleTest.java index f76c59a543..a406c7bac3 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeToSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeToSingleTest.java @@ -20,6 +20,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.HasUpstreamMaybeSource; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeToSingleTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOnTest.java index 813fb2c25d..7d664f990a 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUnsubscribeOnTest.java @@ -25,6 +25,7 @@ import io.reactivex.functions.*; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class MaybeUnsubscribeOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java index a4557d415b..bfa2e89703 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeUsingTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class MaybeUsingTest { @@ -192,7 +193,7 @@ public void accept(Object d) throws Exception { @Test public void supplierAndDisposerCrashEager() { - TestObserver to = Maybe.using(new Supplier() { + TestObserverEx to = Maybe.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -208,7 +209,7 @@ public void accept(Object d) throws Exception { throw new TestException("Disposer"); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List list = TestHelper.compositeList(to.errors().get(0)); @@ -237,7 +238,7 @@ public void accept(Object d) throws Exception { throw new TestException("Disposer"); } }, false) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Main"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Disposer"); @@ -268,7 +269,7 @@ public void accept(Object d) throws Exception { }, false) .test(); - to.cancel(); + to.dispose(); assertEquals(1, call[0]); } @@ -295,7 +296,7 @@ public void accept(Object d) throws Exception { }, false) .test(); - to.cancel(); + to.dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -369,7 +370,7 @@ public void accept(Object d) throws Exception { @Test public void errorDisposerCrash() { - TestObserver to = Maybe.using(new Supplier() { + TestObserverEx to = Maybe.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -385,7 +386,7 @@ public void accept(Object d) throws Exception { throw new TestException("Disposer"); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List list = TestHelper.compositeList(to.errors().get(0)); @@ -463,7 +464,7 @@ public void accept(Object d) throws Exception { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -506,7 +507,7 @@ public void accept(Object d) throws Exception { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -548,7 +549,7 @@ public void accept(Object d) throws Exception { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java index 8d07b6be3a..df29d02cf9 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipArrayTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeZipArrayTest { @@ -66,7 +67,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -166,7 +167,7 @@ public Object apply(Object[] v) { @Test public void singleSourceZipperReturnsNull() { Maybe.zipArray(Functions.justFunction(null), Maybe.just(1)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The zipper returned a null value"); } } diff --git a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipIterableTest.java index 87cf95d328..c316268473 100644 --- a/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/maybe/MaybeZipIterableTest.java @@ -19,7 +19,7 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Maybe; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class MaybeZipIterableTest { @@ -63,7 +64,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -161,7 +162,7 @@ public Maybe apply(Integer v) throws Exception { return Maybe.just(v); } }), addString) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -173,7 +174,7 @@ public Maybe apply(Integer v) throws Exception { return Maybe.just(v); } }), addString) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -185,7 +186,7 @@ public Maybe apply(Integer v) throws Exception { return Maybe.just(v); } }), addString) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -217,7 +218,7 @@ public Object apply(Object[] v) { @Test public void singleSourceZipperReturnsNull() { Maybe.zipArray(Functions.justFunction(null), Maybe.just(1)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The zipper returned a null value"); } } diff --git a/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java index 8493f9a15e..d10d78b135 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenObservableTest.java @@ -21,6 +21,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class CompletableAndThenObservableTest { @@ -35,7 +36,7 @@ public void cancelMain() { assertTrue(cs.hasObservers()); assertFalse(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(cs.hasObservers()); assertFalse(ps.hasObservers()); @@ -57,7 +58,7 @@ public void cancelOther() { assertFalse(cs.hasObservers()); assertTrue(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(cs.hasObservers()); assertFalse(ps.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenPublisherTest.java b/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenPublisherTest.java index 5f27eeeecf..0d397d0a3e 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenPublisherTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/CompletableAndThenPublisherTest.java @@ -23,6 +23,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.CompletableSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class CompletableAndThenPublisherTest { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletableTest.java index ef0e291581..258b1b9cbc 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapCompletableTest.java @@ -30,6 +30,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.CompletableSubject; +import io.reactivex.testsupport.*; public class FlowableConcatMapCompletableTest { @@ -83,7 +84,7 @@ public void innerError() { @Test public void innerErrorDelayed() { - Flowable.range(1, 5) + TestObserverEx to = Flowable.range(1, 5) .concatMapCompletableDelayError( new Function() { @Override @@ -92,14 +93,11 @@ public CompletableSource apply(Integer v) throws Exception { } } ) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - assertEquals(5, ((CompositeException)to.errors().get(0)).getExceptions().size()); - } - }); + ; + + assertEquals(5, ((CompositeException)to.errors().get(0)).getExceptions().size()); } @Test @@ -360,7 +358,7 @@ public void run() { @Override public void run() { cs.onComplete(); - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java index 5e6ef2c82b..cceed98137 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapMaybeTest.java @@ -35,6 +35,7 @@ import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.MaybeSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableConcatMapMaybeTest { @@ -125,7 +126,7 @@ public MaybeSource apply(Integer v) @Test public void mixedLong() { - Flowable.range(1, 1024) + TestSubscriberEx ts = Flowable.range(1, 1024) .concatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) @@ -136,19 +137,16 @@ public MaybeSource apply(Integer v) return Maybe.empty().subscribeOn(Schedulers.computation()); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertValueCount(512) .assertNoErrors() .assertComplete() - .assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - for (int i = 0; i < 512; i ++) { - ts.assertValueAt(i, (i + 1) * 2); - } - } - }); + ; + + for (int i = 0; i < 512; i ++) { + ts.assertValueAt(i, (i + 1) * 2); + } } @Test @@ -295,7 +293,7 @@ public void innerErrorAfterMainError() { final AtomicReference> obs = new AtomicReference>(); - TestSubscriber ts = pp.concatMapMaybe( + TestSubscriberEx ts = pp.concatMapMaybe( new Function>() { @Override public MaybeSource apply(Integer v) @@ -310,7 +308,7 @@ protected void subscribeActual( }; } } - ).test(); + ).to(TestHelper.testConsumer()); pp.onNext(1); @@ -327,7 +325,7 @@ protected void subscribeActual( @Test public void delayAllErrors() { - Flowable.range(1, 5) + TestSubscriberEx ts = Flowable.range(1, 5) .concatMapMaybeDelayError(new Function>() { @Override public MaybeSource apply(Integer v) @@ -335,15 +333,12 @@ public MaybeSource apply(Integer v) return Maybe.error(new TestException()); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - CompositeException ce = (CompositeException)ts.errors().get(0); - assertEquals(5, ce.getExceptions().size()); - } - }); + ; + + CompositeException ce = (CompositeException)ts.errors().get(0); + assertEquals(5, ce.getExceptions().size()); } @Test @@ -415,7 +410,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - ts.dispose(); + ts.cancel(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java index 6f07102918..2de949ff40 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableConcatMapSingleTest.java @@ -24,7 +24,7 @@ import io.reactivex.*; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.*; -import io.reactivex.functions.*; +import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.operators.mixed.FlowableConcatMapSingle.ConcatMapSingleSubscriber; import io.reactivex.internal.subscriptions.BooleanSubscription; @@ -33,6 +33,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.SingleSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableConcatMapSingleTest { @@ -210,7 +211,7 @@ public void innerErrorAfterMainError() { final AtomicReference> obs = new AtomicReference>(); - TestSubscriber ts = pp.concatMapSingle( + TestSubscriberEx ts = pp.concatMapSingle( new Function>() { @Override public SingleSource apply(Integer v) @@ -225,7 +226,7 @@ protected void subscribeActual( }; } } - ).test(); + ).to(TestHelper.testConsumer()); pp.onNext(1); @@ -242,7 +243,7 @@ protected void subscribeActual( @Test public void delayAllErrors() { - Flowable.range(1, 5) + TestSubscriberEx ts = Flowable.range(1, 5) .concatMapSingleDelayError(new Function>() { @Override public SingleSource apply(Integer v) @@ -250,15 +251,12 @@ public SingleSource apply(Integer v) return Single.error(new TestException()); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - CompositeException ce = (CompositeException)ts.errors().get(0); - assertEquals(5, ce.getExceptions().size()); - } - }); + ; + + CompositeException ce = (CompositeException)ts.errors().get(0); + assertEquals(5, ce.getExceptions().size()); } @Test @@ -330,7 +328,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - ts.dispose(); + ts.cancel(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletableTest.java index 5bd6196fad..c309197fc0 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapCompletableTest.java @@ -29,6 +29,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.CompletableSubject; +import io.reactivex.testsupport.TestHelper; public class FlowableSwitchMapCompletableTest { @@ -178,7 +179,7 @@ public void mapperCancels() { Flowable.range(1, 5).switchMapCompletable(new Function() { @Override public CompletableSource apply(Integer f) throws Exception { - to.cancel(); + to.dispose(); return Completable.complete(); } }) @@ -321,7 +322,7 @@ protected void subscribeActual(Subscriber s) { } } .switchMapCompletable(Functions.justFunction(Completable.error(new TestException("inner")))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "main"); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java index 58188a34eb..72aa7c6016 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapMaybeTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.MaybeSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableSwitchMapMaybeTest { @@ -390,7 +391,7 @@ public MaybeSource apply(Integer v) return Maybe.error(new TestException("inner")); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); @@ -405,7 +406,7 @@ public void innerErrorAfterTermination() { try { final AtomicReference> moRef = new AtomicReference>(); - TestSubscriber ts = new Flowable() { + TestSubscriberEx ts = new Flowable() { @Override protected void subscribeActual(Subscriber s) { s.onSubscribe(new BooleanSubscription()); @@ -427,7 +428,7 @@ protected void subscribeActual( }; } }) - .test(); + .to(TestHelper.testConsumer()); ts.assertFailureAndMessage(TestException.class, "outer"); @@ -489,7 +490,7 @@ public void nextInnerErrorRace() { final MaybeSubject ms = MaybeSubject.create(); - final TestSubscriber ts = pp.switchMapMaybeDelayError(new Function>() { + final TestSubscriberEx ts = pp.switchMapMaybeDelayError(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { @@ -498,7 +499,7 @@ public MaybeSource apply(Integer v) } return Maybe.never(); } - }).test(); + }).to(TestHelper.testConsumer()); pp.onNext(1); @@ -518,7 +519,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.errorCount() != 0) { + if (ts.errors().size() != 0) { assertTrue(errors.isEmpty()); ts.assertFailure(TestException.class); } else if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java index 803e9bf013..506deb8517 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/FlowableSwitchMapSingleTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.SingleSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class FlowableSwitchMapSingleTest { @@ -338,7 +339,7 @@ public SingleSource apply(Integer v) return Single.error(new TestException("inner")); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); @@ -353,7 +354,7 @@ public void innerErrorAfterTermination() { try { final AtomicReference> moRef = new AtomicReference>(); - TestSubscriber ts = new Flowable() { + TestSubscriberEx ts = new Flowable() { @Override protected void subscribeActual(Subscriber s) { s.onSubscribe(new BooleanSubscription()); @@ -375,7 +376,7 @@ protected void subscribeActual( }; } }) - .test(); + .to(TestHelper.testConsumer()); ts.assertFailureAndMessage(TestException.class, "outer"); @@ -436,7 +437,7 @@ public void nextInnerErrorRace() { final SingleSubject ms = SingleSubject.create(); - final TestSubscriber ts = pp.switchMapSingleDelayError(new Function>() { + final TestSubscriberEx ts = pp.switchMapSingleDelayError(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { @@ -445,7 +446,7 @@ public SingleSource apply(Integer v) } return Single.never(); } - }).test(); + }).to(TestHelper.testConsumer()); pp.onNext(1); @@ -465,7 +466,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.errorCount() != 0) { + if (ts.errors().size() != 0) { assertTrue(errors.isEmpty()); ts.assertFailure(TestException.class); } else if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservableTest.java index 50ca4ffa01..31a326fd68 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapObservableTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class MaybeFlatMapObservableTest { @@ -37,7 +38,7 @@ public void cancelMain() { assertTrue(ms.hasObservers()); assertFalse(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ms.hasObservers()); assertFalse(ps.hasObservers()); @@ -59,7 +60,7 @@ public void cancelOther() { assertFalse(ms.hasObservers()); assertTrue(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ms.hasObservers()); assertFalse(ps.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapPublisherTest.java b/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapPublisherTest.java index d784a9e1fc..60a703502a 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapPublisherTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/MaybeFlatMapPublisherTest.java @@ -25,6 +25,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.MaybeSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class MaybeFlatMapPublisherTest { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletableTest.java index 6f4ff458ab..50c7ea3233 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapCompletableTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableConcatMapCompletableTest { @@ -81,7 +82,7 @@ public void innerError() { @Test public void innerErrorDelayed() { - Observable.range(1, 5) + TestObserverEx to = Observable.range(1, 5) .concatMapCompletableDelayError( new Function() { @Override @@ -90,14 +91,11 @@ public CompletableSource apply(Integer v) throws Exception { } } ) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - assertEquals(5, ((CompositeException)to.errors().get(0)).getExceptions().size()); - } - }); + ; + + assertEquals(5, ((CompositeException)to.errors().get(0)).getExceptions().size()); } @Test @@ -345,7 +343,7 @@ public void run() { @Override public void run() { cs.onComplete(); - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java index b02992e9fc..888c225885 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapMaybeTest.java @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableConcatMapMaybeTest { @@ -98,7 +99,7 @@ public MaybeSource apply(Integer v) @Test public void mixedLong() { - Observable.range(1, 1024) + TestObserverEx to = Observable.range(1, 1024) .concatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) @@ -109,19 +110,16 @@ public MaybeSource apply(Integer v) return Maybe.empty().subscribeOn(Schedulers.computation()); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertValueCount(512) .assertNoErrors() .assertComplete() - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - for (int i = 0; i < 512; i ++) { - to.assertValueAt(i, (i + 1) * 2); - } - } - }); + ; + + for (int i = 0; i < 512; i ++) { + to.assertValueAt(i, (i + 1) * 2); + } } @Test @@ -231,7 +229,7 @@ public MaybeSource apply(Integer v) .assertValues(1, 2, 3, 4, 5) .assertNoErrors() .assertNotComplete() - .cancel(); + .dispose(); } @Test @@ -249,7 +247,7 @@ protected void subscribeActual(Observer observer) { .concatMapMaybe( Functions.justFunction(Maybe.error(new TestException("inner"))), 1 ) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); @@ -266,7 +264,7 @@ public void innerErrorAfterMainError() { final AtomicReference> obs = new AtomicReference>(); - TestObserver to = ps.concatMapMaybe( + TestObserverEx to = ps.concatMapMaybe( new Function>() { @Override public MaybeSource apply(Integer v) @@ -281,7 +279,7 @@ protected void subscribeActual( }; } } - ).test(); + ).to(TestHelper.testConsumer()); ps.onNext(1); @@ -298,7 +296,7 @@ protected void subscribeActual( @Test public void delayAllErrors() { - Observable.range(1, 5) + TestObserverEx to = Observable.range(1, 5) .concatMapMaybeDelayError(new Function>() { @Override public MaybeSource apply(Integer v) @@ -306,15 +304,12 @@ public MaybeSource apply(Integer v) return Maybe.error(new TestException()); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - CompositeException ce = (CompositeException)to.errors().get(0); - assertEquals(5, ce.getExceptions().size()); - } - }); + ; + + CompositeException ce = (CompositeException)to.errors().get(0); + assertEquals(5, ce.getExceptions().size()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java index cdd5326368..e22530053e 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableConcatMapSingleTest.java @@ -30,6 +30,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableConcatMapSingleTest { @@ -146,7 +147,7 @@ public SingleSource apply(Integer v) .assertValues(1, 2, 3, 4, 5) .assertNoErrors() .assertNotComplete() - .cancel(); + .dispose(); } @Test @@ -164,7 +165,7 @@ protected void subscribeActual(Observer observer) { .concatMapSingle( Functions.justFunction(Single.error(new TestException("inner"))), 1 ) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); @@ -181,7 +182,7 @@ public void innerErrorAfterMainError() { final AtomicReference> obs = new AtomicReference>(); - TestObserver to = ps.concatMapSingle( + TestObserverEx to = ps.concatMapSingle( new Function>() { @Override public SingleSource apply(Integer v) @@ -196,7 +197,7 @@ protected void subscribeActual( }; } } - ).test(); + ).to(TestHelper.testConsumer()); ps.onNext(1); @@ -213,7 +214,7 @@ protected void subscribeActual( @Test public void delayAllErrors() { - Observable.range(1, 5) + TestObserverEx to = Observable.range(1, 5) .concatMapSingleDelayError(new Function>() { @Override public SingleSource apply(Integer v) @@ -221,15 +222,12 @@ public SingleSource apply(Integer v) return Single.error(new TestException()); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class) - .assertOf(new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - CompositeException ce = (CompositeException)to.errors().get(0); - assertEquals(5, ce.getExceptions().size()); - } - }); + ; + + CompositeException ce = (CompositeException)to.errors().get(0); + assertEquals(5, ce.getExceptions().size()); } @Test @@ -326,7 +324,7 @@ public void cancelNoConcurrentClean() { operator.getAndIncrement(); - to.cancel(); + to.dispose(); assertFalse(operator.queue.isEmpty()); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java index c8b1bd3bc4..e791c024ad 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapCompletableTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableSwitchMapCompletableTest { @@ -176,7 +177,7 @@ public void mapperCancels() { Observable.range(1, 5).switchMapCompletable(new Function() { @Override public CompletableSource apply(Integer f) throws Exception { - to.cancel(); + to.dispose(); return Completable.complete(); } }) @@ -319,7 +320,7 @@ protected void subscribeActual(Observer observer) { } } .switchMapCompletable(Functions.justFunction(Completable.error(new TestException("inner")))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "main"); diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java index 7830b885da..82e891ab5b 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapMaybeTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableSwitchMapMaybeTest { @@ -289,7 +290,7 @@ public void disposeBeforeSwitchInOnNext() { @Override public MaybeSource apply(Integer v) throws Exception { - to.cancel(); + to.dispose(); return Maybe.just(1); } }).subscribe(to); @@ -307,7 +308,7 @@ public void disposeOnNextAfterFirst() { public MaybeSource apply(Integer v) throws Exception { if (v == 2) { - to.cancel(); + to.dispose(); } return Maybe.just(1); } @@ -341,7 +342,7 @@ public MaybeSource apply(Integer v) assertTrue(ps.hasObservers()); assertTrue(ms.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); assertFalse(ms.hasObservers()); @@ -366,7 +367,7 @@ public MaybeSource apply(Integer v) return Maybe.error(new TestException("inner")); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); @@ -381,7 +382,7 @@ public void innerErrorAfterTermination() { try { final AtomicReference> moRef = new AtomicReference>(); - TestObserver to = new Observable() { + TestObserverEx to = new Observable() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); @@ -403,7 +404,7 @@ protected void subscribeActual( }; } }) - .test(); + .to(TestHelper.testConsumer()); to.assertFailureAndMessage(TestException.class, "outer"); @@ -442,7 +443,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -465,7 +466,7 @@ public void nextInnerErrorRace() { final MaybeSubject ms = MaybeSubject.create(); - final TestObserver to = ps.switchMapMaybeDelayError(new Function>() { + final TestObserverEx to = ps.switchMapMaybeDelayError(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { @@ -474,7 +475,7 @@ public MaybeSource apply(Integer v) } return Maybe.never(); } - }).test(); + }).to(TestHelper.testConsumer()); ps.onNext(1); @@ -494,7 +495,7 @@ public void run() { TestHelper.race(r1, r2); - if (to.errorCount() != 0) { + if (to.errors().size() != 0) { assertTrue(errors.isEmpty()); to.assertFailure(TestException.class); } else if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java index da35b10df1..99c533c826 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ObservableSwitchMapSingleTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableSwitchMapSingleTest { @@ -258,7 +259,7 @@ public void disposeBeforeSwitchInOnNext() { @Override public SingleSource apply(Integer v) throws Exception { - to.cancel(); + to.dispose(); return Single.just(1); } }).subscribe(to); @@ -276,7 +277,7 @@ public void disposeOnNextAfterFirst() { public SingleSource apply(Integer v) throws Exception { if (v == 2) { - to.cancel(); + to.dispose(); } return Single.just(1); } @@ -310,7 +311,7 @@ public SingleSource apply(Integer v) assertTrue(ps.hasObservers()); assertTrue(ms.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); assertFalse(ms.hasObservers()); @@ -335,7 +336,7 @@ public SingleSource apply(Integer v) return Single.error(new TestException("inner")); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "outer"); @@ -350,7 +351,7 @@ public void innerErrorAfterTermination() { try { final AtomicReference> moRef = new AtomicReference>(); - TestObserver to = new Observable() { + TestObserverEx to = new Observable() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); @@ -372,7 +373,7 @@ protected void subscribeActual( }; } }) - .test(); + .to(TestHelper.testConsumer()); to.assertFailureAndMessage(TestException.class, "outer"); @@ -410,7 +411,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -433,7 +434,7 @@ public void nextInnerErrorRace() { final SingleSubject ms = SingleSubject.create(); - final TestObserver to = ps.switchMapSingleDelayError(new Function>() { + final TestObserverEx to = ps.switchMapSingleDelayError(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { @@ -442,7 +443,7 @@ public SingleSource apply(Integer v) } return Single.never(); } - }).test(); + }).to(TestHelper.testConsumer()); ps.onNext(1); @@ -462,7 +463,7 @@ public void run() { TestHelper.race(r1, r2); - if (to.errorCount() != 0) { + if (to.errors().size() != 0) { assertTrue(errors.isEmpty()); to.assertFailure(TestException.class); } else if (!errors.isEmpty()) { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelperTest.java b/src/test/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelperTest.java index c30d0c4624..b4b785844d 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelperTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/ScalarXMapZHelperTest.java @@ -15,7 +15,7 @@ import org.junit.Test; -import io.reactivex.TestHelper; +import io.reactivex.testsupport.TestHelper; public class ScalarXMapZHelperTest { diff --git a/src/test/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservableTest.java b/src/test/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservableTest.java index a6b0d80344..198fc8f3e9 100644 --- a/src/test/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/mixed/SingleFlatMapObservableTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class SingleFlatMapObservableTest { @@ -37,7 +38,7 @@ public void cancelMain() { assertTrue(ss.hasObservers()); assertFalse(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ss.hasObservers()); assertFalse(ps.hasObservers()); @@ -59,7 +60,7 @@ public void cancelOther() { assertFalse(ss.hasObservers()); assertTrue(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ss.hasObservers()); assertFalse(ps.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java index cdd95c58f2..ea9790e3fe 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableLatestTest.java @@ -22,11 +22,11 @@ import io.reactivex.Observable; import io.reactivex.Observer; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class BlockingObservableLatestTest { @Test(timeout = 1000) diff --git a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java index 2b8e670c16..a72e51bf47 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/BlockingObservableNextTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.BehaviorProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class BlockingObservableNextTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java index dc8445068c..94b790bf80 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAllTest.java @@ -27,8 +27,8 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class ObservableAllTest { @@ -146,7 +146,7 @@ public Observable apply(Boolean t1) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessageObservable() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final IllegalArgumentException ex = new IllegalArgumentException(); @@ -277,7 +277,7 @@ public Observable apply(Boolean t1) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final IllegalArgumentException ex = new IllegalArgumentException(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java index 6e2c737f75..b7f69722a6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAmbTest.java @@ -35,6 +35,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableAmbTest { @@ -179,7 +180,7 @@ public void accept(Disposable d) { .delay(100, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.computation()); TestObserver to = new TestObserver(); Observable.ambArray(o1, o2).subscribe(to); - to.awaitTerminalEvent(5, TimeUnit.SECONDS); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(2, count.get()); } @@ -277,7 +278,7 @@ public void onNextRace() { final PublishSubject ps2 = PublishSubject.create(); @SuppressWarnings("unchecked") - TestObserver to = Observable.ambArray(ps1, ps2).test(); + TestObserverEx to = Observable.ambArray(ps1, ps2).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -294,8 +295,10 @@ public void run() { TestHelper.race(r1, r2); - to.assertSubscribed().assertNoErrors() - .assertNotComplete().assertValueCount(1); + to.assertSubscribed() + .assertNoErrors() + .assertNotComplete() + .assertValueCount(1); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java index 7c66cba3f6..eb19b8ef98 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableAnyTest.java @@ -28,8 +28,8 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class ObservableAnyTest { @@ -247,7 +247,7 @@ public Observable apply(Boolean t1) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessageObservable() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final IllegalArgumentException ex = new IllegalArgumentException(); Observable.just("Boo!").any(new Predicate() { @@ -469,7 +469,7 @@ public Observable apply(Boolean t1) { @Test public void testPredicateThrowsExceptionAndValueInCauseMessage() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final IllegalArgumentException ex = new IllegalArgumentException(); Observable.just("Boo!").any(new Predicate() { @@ -557,7 +557,7 @@ protected void subscribeActual(Observer observer) { } } .any(Functions.alwaysTrue()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBlockingTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBlockingTest.java index ed4d73818c..72e43d1ed8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBlockingTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBlockingTest.java @@ -22,7 +22,6 @@ import io.reactivex.Observable; import io.reactivex.Observer; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; @@ -30,6 +29,7 @@ import io.reactivex.internal.observers.BlockingFirstObserver; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableBlockingTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java index 97dd5e58da..3f71fb991a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableBufferTest.java @@ -40,6 +40,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableBufferTest { @@ -1564,7 +1565,7 @@ public Observable apply(Long a) { return Observable.just(a).delay(100, TimeUnit.MILLISECONDS); } }) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .awaitDone(3, TimeUnit.SECONDS) .assertComplete(); @@ -1587,7 +1588,7 @@ public Observable apply(Long a) { return Observable.just(a).delay(200, TimeUnit.MILLISECONDS); } }) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .awaitDone(3, TimeUnit.SECONDS) .assertComplete(); @@ -1888,7 +1889,7 @@ protected void subscribeActual(Observer observer) { observer.onError(new TestException("second")); } })) - .test() + .to(TestHelper.>testConsumer()) .assertError(TestException.class) .assertErrorMessage("first") .assertNotComplete(); @@ -2055,7 +2056,7 @@ public void timedSkipCancelWhenSecondBuffer() { @Override public List get() throws Exception { if (++calls == 2) { - to.cancel(); + to.dispose(); } return new ArrayList(); } @@ -2065,7 +2066,7 @@ public List get() throws Exception { sub.run(); - assertTrue(to.isCancelled()); + assertTrue(to.isDisposed()); } @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java index 033c06d644..d3b7e2ddac 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCacheTest.java @@ -22,8 +22,8 @@ import org.junit.*; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; @@ -31,6 +31,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableCacheTest { @Test @@ -39,7 +40,7 @@ public void testColdReplayNoBackpressure() { assertFalse("Source is connected!", source.isConnected()); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); source.subscribe(to); @@ -140,7 +141,7 @@ public void testAsync() { cached.observeOn(Schedulers.computation()).subscribe(to1); - to1.awaitTerminalEvent(2, TimeUnit.SECONDS); + to1.awaitDone(2, TimeUnit.SECONDS); to1.assertNoErrors(); to1.assertComplete(); assertEquals(10000, to1.values().size()); @@ -148,7 +149,7 @@ public void testAsync() { TestObserver to2 = new TestObserver(); cached.observeOn(Schedulers.computation()).subscribe(to2); - to2.awaitTerminalEvent(2, TimeUnit.SECONDS); + to2.awaitDone(2, TimeUnit.SECONDS); to2.assertNoErrors(); to2.assertComplete(); assertEquals(10000, to2.values().size()); @@ -177,7 +178,7 @@ public void testAsyncComeAndGo() { } int j = 0; for (TestObserver to : list) { - to.awaitTerminalEvent(3, TimeUnit.SECONDS); + to.awaitDone(3, TimeUnit.SECONDS); to.assertNoErrors(); to.assertComplete(); @@ -208,7 +209,7 @@ public void subscribe(Observer t) { TestObserver to = new TestObserver(); firehose.cache().observeOn(Schedulers.computation()).takeLast(100).subscribe(to); - to.awaitTerminalEvent(3, TimeUnit.SECONDS); + to.awaitDone(3, TimeUnit.SECONDS); to.assertNoErrors(); to.assertComplete(); @@ -325,7 +326,7 @@ public void subscribeEmitRace() { cache.test(); - final TestObserver to = new TestObserver(); + final TestObserverEx to = new TestObserverEx(); Runnable r1 = new Runnable() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCastTest.java index a2b08a6439..d5dbd9b5f1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCastTest.java @@ -18,6 +18,7 @@ import org.junit.Test; import io.reactivex.*; +import io.reactivex.testsupport.TestHelper; public class ObservableCastTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCollectTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCollectTest.java index 4c7b85e6ee..8bc333ba70 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCollectTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCollectTest.java @@ -26,6 +26,7 @@ import io.reactivex.Observable; import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public final class ObservableCollectTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java index 55256bccd8..d0c865c300 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCombineLatestTest.java @@ -35,6 +35,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableCombineLatestTest { @@ -883,7 +884,7 @@ public void cancelWhileSubscribing() { .doOnNext(new Consumer() { @Override public void accept(Integer v) throws Exception { - to.cancel(); + to.dispose(); } }), Observable.never(), @@ -969,12 +970,12 @@ public void onErrorRace() { final PublishSubject ps1 = PublishSubject.create(); final PublishSubject ps2 = PublishSubject.create(); - TestObserver to = Observable.combineLatest(ps1, ps2, new BiFunction() { + TestObserverEx to = Observable.combineLatest(ps1, ps2, new BiFunction() { @Override public Integer apply(Integer a, Integer b) throws Exception { return a; } - }).test(); + }).to(TestHelper.testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); @@ -994,7 +995,7 @@ public void run() { TestHelper.race(r1, r2); - if (to.errorCount() != 0) { + if (to.errors().size() != 0) { if (to.errors().get(0) instanceof CompositeException) { to.assertSubscribed() .assertNotComplete() @@ -1157,7 +1158,7 @@ public void run() throws Exception { testScheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS); - testObserver.awaitTerminalEvent(); + testObserver.awaitDone(5, TimeUnit.SECONDS); assertTrue(errors.toString(), errors.isEmpty()); } finally { @@ -1174,7 +1175,7 @@ public void eagerDispose() { @Override public void onNext(Integer t) { super.onNext(t); - cancel(); + dispose(); if (ps1.hasObservers()) { onError(new IllegalStateException("ps1 not disposed")); } else diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java index ab34d4e03e..b833852d47 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapCompletableTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableConcatMapCompletableTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java index 17e418bab7..035d6295f1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapEagerTest.java @@ -22,8 +22,8 @@ import org.junit.*; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; @@ -31,6 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableConcatMapEagerTest { @@ -159,13 +160,13 @@ public void mainErrorsDelayBoundary() { PublishSubject main = PublishSubject.create(); final PublishSubject inner = PublishSubject.create(); - TestObserver to = main.concatMapEagerDelayError( + TestObserverEx to = main.concatMapEagerDelayError( new Function>() { @Override public ObservableSource apply(Integer t) { return inner; } - }, false).test(); + }, false).to(TestHelper.testConsumer()); main.onNext(1); @@ -188,13 +189,13 @@ public void mainErrorsDelayEnd() { PublishSubject main = PublishSubject.create(); final PublishSubject inner = PublishSubject.create(); - TestObserver to = main.concatMapEagerDelayError( + TestObserverEx to = main.concatMapEagerDelayError( new Function>() { @Override public ObservableSource apply(Integer t) { return inner; } - }, true).test(); + }, true).to(TestHelper.testConsumer()); main.onNext(1); main.onNext(2); @@ -218,13 +219,13 @@ public void mainErrorsImmediate() { PublishSubject main = PublishSubject.create(); final PublishSubject inner = PublishSubject.create(); - TestObserver to = main.concatMapEager( + TestObserverEx to = main.concatMapEager( new Function>() { @Override public ObservableSource apply(Integer t) { return inner; } - }).test(); + }).to(TestHelper.testConsumer()); main.onNext(1); main.onNext(2); @@ -548,7 +549,7 @@ public Observable apply(Integer t) { } }).observeOn(Schedulers.newThread()).subscribe(to); - to.awaitTerminalEvent(5, TimeUnit.SECONDS); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertValueCount(2000); } @@ -812,12 +813,12 @@ public void innerOuterRace() { final PublishSubject ps1 = PublishSubject.create(); final PublishSubject ps2 = PublishSubject.create(); - TestObserver to = ps1.concatMapEager(new Function>() { + TestObserverEx to = ps1.concatMapEager(new Function>() { @Override public ObservableSource apply(Integer v) throws Exception { return ps2; } - }).test(); + }).to(TestHelper.testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); @@ -880,7 +881,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -898,7 +899,7 @@ public void mapperCancels() { .concatMapEager(new Function>() { @Override public ObservableSource apply(Integer v) throws Exception { - to.cancel(); + to.dispose(); return Observable.never(); } }, 1, 128) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java index 4940d6c857..c9dbd0cda6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatMapTest.java @@ -29,6 +29,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableConcatMapTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java index d47c684cfc..2caff4ccb8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -28,12 +29,12 @@ import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Action; -import io.reactivex.functions.Function; +import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.observers.*; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableConcatTest { @@ -673,9 +674,9 @@ public void subscribe(Observer observer) { }); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.concat(o, o).subscribe(to); - to.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + to.awaitDone(500, TimeUnit.MILLISECONDS); to.assertTerminated(); to.assertNoErrors(); to.assertValues("hello", "hello"); @@ -744,7 +745,8 @@ public void concatMapRangeAsyncLoopIssue2876() { if (i % 1000 == 0) { System.out.println("concatMapRangeAsyncLoop > " + i); } - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + Observable.range(0, 1000) .concatMap(new Function>() { @Override @@ -752,12 +754,13 @@ public Observable apply(Integer t) { return Observable.fromIterable(Arrays.asList(t)); } }) - .observeOn(Schedulers.computation()).subscribe(to); + .observeOn(Schedulers.computation()) + .subscribe(to); - to.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + to.awaitDone(2500, TimeUnit.MILLISECONDS); to.assertTerminated(); to.assertNoErrors(); - assertEquals(1000, to.valueCount()); + assertEquals(1000, to.values().size()); assertEquals((Integer)999, to.values().get(999)); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java index 458d0320c0..d77c64a7a9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithCompletableTest.java @@ -96,7 +96,7 @@ public void cancelOther() { assertTrue(other.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(other.hasObservers()); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java index 3d03c3d8a1..d982dc0152 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithMaybeTest.java @@ -107,7 +107,7 @@ public void cancelOther() { assertTrue(other.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(other.hasObservers()); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java index 824c6ac59e..9cdecb02fe 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableConcatWithSingleTest.java @@ -80,7 +80,7 @@ public void cancelOther() { assertTrue(other.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(other.hasObservers()); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCountTest.java index 5c081a43c7..ef4442b338 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCountTest.java @@ -17,6 +17,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class ObservableCountTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableCreateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableCreateTest.java index a3e86e18e9..07114f0847 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableCreateTest.java @@ -24,8 +24,8 @@ import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Cancellable; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class ObservableCreateTest { @@ -447,8 +447,11 @@ public void run() { } }) .take(TestHelper.RACE_DEFAULT_LOOPS) - .test() - .assertSubscribed().assertValueCount(TestHelper.RACE_DEFAULT_LOOPS).assertComplete().assertNoErrors(); + .to(TestHelper.testConsumer()) + .assertSubscribed() + .assertValueCount(TestHelper.RACE_DEFAULT_LOOPS) + .assertComplete() + .assertNoErrors(); } @Test @@ -480,14 +483,15 @@ public void run() { TestHelper.race(r1, r2); } }) - .test() - .assertSubscribed().assertNotComplete() + .to(TestHelper.testConsumer()) + .assertSubscribed() + .assertNotComplete() .assertError(TestException.class); } @Test public void serializedConcurrentOnNextOnComplete() { - TestObserver to = Observable.create(new ObservableOnSubscribe() { + TestObserverEx to = Observable.create(new ObservableOnSubscribe() { @Override public void subscribe(ObservableEmitter e) throws Exception { final ObservableEmitter f = e.serialize(); @@ -514,11 +518,12 @@ public void run() { TestHelper.race(r1, r2); } }) - .test() - .assertSubscribed().assertComplete() + .to(TestHelper.testConsumer()) + .assertSubscribed() + .assertComplete() .assertNoErrors(); - int c = to.valueCount(); + int c = to.values().size(); assertTrue("" + c, c >= 100); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java index 01bf61ac6e..6477983151 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDebounceTest.java @@ -35,6 +35,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableDebounceTest { @@ -287,7 +288,8 @@ public Observable apply(Integer t1) { @Test public void debounceWithTimeBackpressure() throws InterruptedException { TestScheduler scheduler = new TestScheduler(); - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); + Observable.merge( Observable.just(1), Observable.just(2).delay(10, TimeUnit.MILLISECONDS, scheduler) @@ -399,7 +401,7 @@ public void disposeInOnNext() { .debounce(new Function>() { @Override public ObservableSource apply(Integer o) throws Exception { - to.cancel(); + to.dispose(); return Observable.never(); } }) @@ -417,7 +419,7 @@ public void disposedInOnComplete() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); - to.cancel(); + to.dispose(); observer.onComplete(); } } @@ -474,7 +476,7 @@ public void timedDisposedIgnoredBySource() { protected void subscribeActual( Observer observer) { observer.onSubscribe(Disposables.empty()); - to.cancel(); + to.dispose(); observer.onNext(1); observer.onComplete(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDefaultIfEmptyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDefaultIfEmptyTest.java index 6e6747dc6a..bd382c644f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDefaultIfEmptyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDefaultIfEmptyTest.java @@ -20,6 +20,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.observers.DefaultObserver; +import io.reactivex.testsupport.TestHelper; public class ObservableDefaultIfEmptyTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java index 6575dd6033..62b7be3cd3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDeferTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Supplier; +import io.reactivex.testsupport.TestHelper; @SuppressWarnings("unchecked") public class ObservableDeferTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java index a37a2b00a7..a4466b6235 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelaySubscriptionOtherTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableDelaySubscriptionOtherTest { @Test @@ -221,7 +222,7 @@ public void subscribe(ObservableEmitter emitter) throws Exception { .delaySubscription(100, TimeUnit.MILLISECONDS, s) .subscribe(observer); - observer.awaitTerminalEvent(); + observer.awaitDone(5, TimeUnit.SECONDS); observer.assertValue(false); } } finally { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java index 28f89d37cc..3f686e0cd2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDelayTest.java @@ -33,6 +33,7 @@ import io.reactivex.observers.*; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableDelayTest { private Observer observer; @@ -661,9 +662,9 @@ public Integer apply(Integer t) { }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, to.valueCount()); + assertEquals(Flowable.bufferSize() * 2, to.values().size()); } @Test @@ -690,9 +691,9 @@ public Integer apply(Integer t) { }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, to.valueCount()); + assertEquals(Flowable.bufferSize() * 2, to.values().size()); } @Test @@ -725,9 +726,9 @@ public Integer apply(Integer t) { }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, to.valueCount()); + assertEquals(Flowable.bufferSize() * 2, to.values().size()); } @Test @@ -761,9 +762,9 @@ public Integer apply(Integer t) { }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 2, to.valueCount()); + assertEquals(Flowable.bufferSize() * 2, to.values().size()); } @Test @@ -974,7 +975,7 @@ public Observable apply(Integer t) throws Exception { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The itemDelay returned a null ObservableSource"); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java index d815a70ea5..10ca5833de 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDematerializeTest.java @@ -25,8 +25,8 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; @SuppressWarnings("deprecation") public class ObservableDematerializeTest { @@ -141,7 +141,7 @@ public void testCompletePassThru() { Observer observer = TestHelper.mockObserver(); - TestObserver to = new TestObserver(observer); + TestObserverEx to = new TestObserverEx(observer); dematerialize.subscribe(to); System.out.println(to.errors()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java index ab20fccc38..41a09281ef 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDetachTest.java @@ -23,6 +23,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestHelper; public class ObservableDetachTest { @@ -120,7 +121,7 @@ public void justUnsubscribed() throws Exception { TestObserver to = Observable.just(o).count().toObservable().onTerminateDetach().test(); o = null; - to.cancel(); + to.dispose(); System.gc(); Thread.sleep(200); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java index 55a86ecb77..2c333799cb 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctTest.java @@ -24,15 +24,14 @@ import io.reactivex.Observable; import io.reactivex.Observer; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.UnicastSubject; +import io.reactivex.testsupport.*; public class ObservableDistinctTest { @@ -143,19 +142,19 @@ public void error() { @Test public void fusedSync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.just(1, 1, 2, 1, 3, 2, 4, 5, 4) .distinct() .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.SYNC) + to.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void fusedAsync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); UnicastSubject us = UnicastSubject.create(); @@ -165,7 +164,7 @@ public void fusedAsync() { TestHelper.emit(us, 1, 1, 2, 1, 3, 2, 4, 5, 4); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); } @@ -221,7 +220,7 @@ public Collection get() throws Exception { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java index b0ba634354..120a3d8b6f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDistinctUntilChangedTest.java @@ -26,10 +26,11 @@ import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; -import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableDistinctUntilChangedTest { @@ -178,7 +179,7 @@ public boolean test(String a, String b) { @Test public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.just(1, 2, 2, 3, 3, 4, 5) .distinctUntilChanged(new BiPredicate() { @@ -189,15 +190,15 @@ public boolean test(Integer a, Integer b) throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5) ; } @Test public void fusedAsync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); UnicastSubject up = UnicastSubject.create(); @@ -212,8 +213,8 @@ public boolean test(Integer a, Integer b) throws Exception { TestHelper.emit(up, 1, 2, 2, 3, 3, 4, 5); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5) ; } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoAfterNextTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoAfterNextTest.java index a091306b9e..deef1389c4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoAfterNextTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoAfterNextTest.java @@ -20,13 +20,13 @@ import org.junit.Test; import io.reactivex.Observable; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.observers.*; import io.reactivex.subjects.UnicastSubject; +import io.reactivex.testsupport.*; public class ObservableDoAfterNextTest { @@ -100,13 +100,13 @@ public void empty() { @Test public void syncFused() { - TestObserver to0 = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to0 = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5) .doAfterNext(afterNext) .subscribe(to0); - ObserverFusion.assertFusion(to0, QueueFuseable.SYNC) + to0.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -114,13 +114,13 @@ public void syncFused() { @Test public void asyncFusedRejected() { - TestObserver to0 = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to0 = new TestObserverEx(QueueFuseable.ASYNC); Observable.range(1, 5) .doAfterNext(afterNext) .subscribe(to0); - ObserverFusion.assertFusion(to0, QueueFuseable.NONE) + to0.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -128,7 +128,7 @@ public void asyncFusedRejected() { @Test public void asyncFused() { - TestObserver to0 = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to0 = new TestObserverEx(QueueFuseable.ASYNC); UnicastSubject up = UnicastSubject.create(); @@ -138,7 +138,7 @@ public void asyncFused() { .doAfterNext(afterNext) .subscribe(to0); - ObserverFusion.assertFusion(to0, QueueFuseable.ASYNC) + to0.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -195,14 +195,14 @@ public void emptyConditional() { @Test public void syncFusedConditional() { - TestObserver to0 = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to0 = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5) .doAfterNext(afterNext) .filter(Functions.alwaysTrue()) .subscribe(to0); - ObserverFusion.assertFusion(to0, QueueFuseable.SYNC) + to0.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -210,14 +210,14 @@ public void syncFusedConditional() { @Test public void asyncFusedRejectedConditional() { - TestObserver to0 = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to0 = new TestObserverEx(QueueFuseable.ASYNC); Observable.range(1, 5) .doAfterNext(afterNext) .filter(Functions.alwaysTrue()) .subscribe(to0); - ObserverFusion.assertFusion(to0, QueueFuseable.NONE) + to0.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); @@ -225,7 +225,7 @@ public void asyncFusedRejectedConditional() { @Test public void asyncFusedConditional() { - TestObserver to0 = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to0 = new TestObserverEx(QueueFuseable.ASYNC); UnicastSubject up = UnicastSubject.create(); @@ -236,7 +236,7 @@ public void asyncFusedConditional() { .filter(Functions.alwaysTrue()) .subscribe(to0); - ObserverFusion.assertFusion(to0, QueueFuseable.ASYNC) + to0.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(Arrays.asList(-1, -2, -3, -4, -5), values); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java index d6f08fff27..99a7eb4cc0 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoFinallyTest.java @@ -21,15 +21,14 @@ import io.reactivex.Observable; import io.reactivex.Observer; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.UnicastSubject; +import io.reactivex.testsupport.*; public class ObservableDoFinallyTest implements Action { @@ -99,13 +98,13 @@ public Observable apply(Observable f) throws Exception { @Test public void syncFused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5) .doFinally(this) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.SYNC) + to.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -113,13 +112,13 @@ public void syncFused() { @Test public void syncFusedBoundary() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); Observable.range(1, 5) .doFinally(this) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -127,7 +126,7 @@ public void syncFusedBoundary() { @Test public void asyncFused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC); UnicastSubject up = UnicastSubject.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -136,7 +135,7 @@ public void asyncFused() { .doFinally(this) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -144,7 +143,7 @@ public void asyncFused() { @Test public void asyncFusedBoundary() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); UnicastSubject up = UnicastSubject.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -153,7 +152,7 @@ public void asyncFusedBoundary() { .doFinally(this) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -206,14 +205,14 @@ public void normalTakeConditional() { @Test public void syncFusedConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5) .doFinally(this) .filter(Functions.alwaysTrue()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.SYNC) + to.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -221,13 +220,13 @@ public void syncFusedConditional() { @Test public void nonFused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5).hide() .doFinally(this) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -235,14 +234,14 @@ public void nonFused() { @Test public void nonFusedConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5).hide() .doFinally(this) .filter(Functions.alwaysTrue()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -250,14 +249,14 @@ public void nonFusedConditional() { @Test public void syncFusedBoundaryConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC | QueueFuseable.BOUNDARY); Observable.range(1, 5) .doFinally(this) .filter(Functions.alwaysTrue()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -265,7 +264,7 @@ public void syncFusedBoundaryConditional() { @Test public void asyncFusedConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC); UnicastSubject up = UnicastSubject.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -275,7 +274,7 @@ public void asyncFusedConditional() { .filter(Functions.alwaysTrue()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -283,7 +282,7 @@ public void asyncFusedConditional() { @Test public void asyncFusedBoundaryConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC | QueueFuseable.BOUNDARY); UnicastSubject up = UnicastSubject.create(); TestHelper.emit(up, 1, 2, 3, 4, 5); @@ -293,7 +292,7 @@ public void asyncFusedBoundaryConditional() { .filter(Functions.alwaysTrue()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(1, calls); @@ -317,7 +316,7 @@ public void run() throws Exception { }) .test() .assertResult(1) - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -339,7 +338,7 @@ public void run() throws Exception { .filter(Functions.alwaysTrue()) .test() .assertResult(1) - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java index 161ae3db9e..0861a69395 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnEachTest.java @@ -29,9 +29,10 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.internal.fuseable.QueueFuseable; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.UnicastSubject; +import io.reactivex.testsupport.*; public class ObservableDoOnEachTest { @@ -201,7 +202,7 @@ public void accept(List booleans) { @Test public void onErrorThrows() { - TestObserver to = TestObserver.create(); + TestObserverEx to = new TestObserverEx(); Observable.error(new TestException()) .doOnError(new Consumer() { @@ -451,7 +452,7 @@ public void run() throws Exception { @Test public void onErrorOnErrorCrashConditional() { - TestObserver to = Observable.error(new TestException("Outer")) + TestObserverEx to = Observable.error(new TestException("Outer")) .doOnError(new Consumer() { @Override public void accept(Throwable e) throws Exception { @@ -459,7 +460,7 @@ public void accept(Throwable e) throws Exception { } }) .filter(Functions.alwaysTrue()) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -471,7 +472,7 @@ public void accept(Throwable e) throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -490,8 +491,8 @@ public void run() throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -501,7 +502,7 @@ public void run() throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fusedOnErrorCrash() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0 }; @@ -520,8 +521,8 @@ public void run() throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertFailure(TestException.class); assertEquals(0, call[0]); @@ -530,7 +531,7 @@ public void run() throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fusedConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -550,8 +551,8 @@ public void run() throws Exception { .filter(Functions.alwaysTrue()) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -561,7 +562,7 @@ public void run() throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fusedOnErrorCrashConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0 }; @@ -581,8 +582,8 @@ public void run() throws Exception { .filter(Functions.alwaysTrue()) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) .assertFailure(TestException.class); assertEquals(0, call[0]); @@ -591,7 +592,7 @@ public void run() throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fusedAsync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -614,8 +615,8 @@ public void run() throws Exception { TestHelper.emit(up, 1, 2, 3, 4, 5); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -625,7 +626,7 @@ public void run() throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fusedAsyncConditional() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -649,8 +650,8 @@ public void run() throws Exception { TestHelper.emit(up, 1, 2, 3, 4, 5); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); @@ -660,7 +661,7 @@ public void run() throws Exception { @Test @Ignore("Fusion not supported yet") // TODO decide/implement fusion public void fusedAsyncConditional2() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); final int[] call = { 0, 0 }; @@ -684,8 +685,8 @@ public void run() throws Exception { TestHelper.emit(up, 1, 2, 3, 4, 5); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); assertEquals(5, call[0]); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java index 76b9737959..118e24a909 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableDoOnSubscribeTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ObservableDoOnSubscribeTest { @@ -126,7 +127,7 @@ public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(bs.isDisposed()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableElementAtTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableElementAtTest.java index d76be9b478..b55a02992c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableElementAtTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableElementAtTest.java @@ -27,6 +27,7 @@ import io.reactivex.functions.Function; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableElementAtTest { @@ -128,7 +129,7 @@ public void elementAtOrErrorInvalidIndex() { public void elementAtOrErrorError() { Observable.error(new RuntimeException("error")) .elementAtOrError(0) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java index e855c07820..4554c9cf68 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFilterTest.java @@ -23,9 +23,9 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.subjects.UnicastSubject; +import io.reactivex.testsupport.*; public class ObservableFilterTest { @@ -94,7 +94,7 @@ public ObservableSource apply(Observable o) throws Exception { @Test public void fusedSync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.range(1, 5) .filter(new Predicate() { @@ -105,13 +105,13 @@ public boolean test(Integer v) throws Exception { }) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.SYNC) + to.assertFusionMode(QueueFuseable.SYNC) .assertResult(2, 4); } @Test public void fusedAsync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); UnicastSubject us = UnicastSubject.create(); @@ -126,13 +126,13 @@ public boolean test(Integer v) throws Exception { TestHelper.emit(us, 1, 2, 3, 4, 5); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .assertResult(2, 4); } @Test public void fusedReject() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY | QueueFuseable.BOUNDARY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY | QueueFuseable.BOUNDARY); Observable.range(1, 5) .filter(new Predicate() { @@ -143,7 +143,7 @@ public boolean test(Integer v) throws Exception { }) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(2, 4); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFinallyTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFinallyTest.java index 77e5eabafc..ef783b5e81 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFinallyTest.java @@ -20,6 +20,7 @@ import io.reactivex.*; import io.reactivex.functions.Action; import io.reactivex.internal.util.ExceptionHelper; +import io.reactivex.testsupport.TestHelper; public class ObservableFinallyTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFirstTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFirstTest.java index 78409e802c..0a22df0160 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFirstTest.java @@ -22,6 +22,7 @@ import io.reactivex.*; import io.reactivex.functions.Predicate; +import io.reactivex.testsupport.TestHelper; public class ObservableFirstTest { @@ -536,7 +537,7 @@ public void firstOrErrorMultipleElements() { public void firstOrErrorError() { Observable.error(new RuntimeException("error")) .firstOrError() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); @@ -577,7 +578,7 @@ public void firstOrErrorErrorObservable() { Observable.error(new RuntimeException("error")) .firstOrError() .toObservable() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java index bd7dc12cf6..82e5db841c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapCompletableTest.java @@ -25,9 +25,10 @@ import io.reactivex.exceptions.*; import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableFlatMapCompletableTest { @@ -117,14 +118,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAllObservable() { - TestObserver to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) + TestObserverEx to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true).toObservable() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -136,14 +137,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayInnerErrorAllObservable() { - TestObserver to = Observable.range(1, 10) + TestObserverEx to = Observable.range(1, 10) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true).toObservable() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -168,7 +169,7 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void fusedObservable() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.range(1, 10) .flatMapCompletable(new Function() { @@ -180,8 +181,8 @@ public CompletableSource apply(Integer v) throws Exception { .subscribe(to); to - .assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } @@ -282,14 +283,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAll() { - TestObserver to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) + TestObserverEx to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -301,14 +302,14 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void normalDelayInnerErrorAll() { - TestObserver to = Observable.range(1, 10) + TestObserverEx to = Observable.range(1, 10) .flatMapCompletable(new Function() { @Override public CompletableSource apply(Integer v) throws Exception { return Completable.error(new TestException()); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -333,7 +334,7 @@ public CompletableSource apply(Integer v) throws Exception { @Test public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.range(1, 10) .flatMapCompletable(new Function() { @@ -346,8 +347,8 @@ public CompletableSource apply(Integer v) throws Exception { .subscribe(to); to - .assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java index 56ecedc02b..7d03d137f5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapMaybeTest.java @@ -31,6 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableFlatMapMaybeTest { @@ -75,19 +76,20 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void normalAsync() { - Observable.range(1, 10) + TestObserverEx to = Observable.range(1, 10) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { return Maybe.just(v).subscribeOn(Schedulers.computation()); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(to, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -136,14 +138,15 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAll() { - TestObserver to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) + TestObserverEx to = Observable.range(1, 10) + .concatWith(Observable.error(new TestException())) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { return Maybe.error(new TestException()); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -155,7 +158,7 @@ public MaybeSource apply(Integer v) throws Exception { @Test public void takeAsync() { - Observable.range(1, 10) + TestObserverEx to = Observable.range(1, 10) .flatMapMaybe(new Function>() { @Override public MaybeSource apply(Integer v) throws Exception { @@ -163,13 +166,14 @@ public MaybeSource apply(Integer v) throws Exception { } }) .take(2) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(2) - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(to, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -214,7 +218,7 @@ public MaybeSource apply(Integer v) throws Exception { } }) .take(500) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) @@ -329,7 +333,7 @@ protected void subscribeActual(Observer observer) { } } .flatMapMaybe(Functions.justFunction(Maybe.just(2))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -351,7 +355,7 @@ protected void subscribeActual(MaybeObserver observer) { observer.onError(new TestException("Second")); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java index 5226fc594c..d09f432633 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapSingleTest.java @@ -18,7 +18,7 @@ import java.util.*; import java.util.concurrent.*; -import org.junit.*; +import org.junit.Test; import io.reactivex.*; import io.reactivex.Observable; @@ -31,6 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableFlatMapSingleTest { @@ -62,19 +63,20 @@ public SingleSource apply(Integer v) throws Exception { @Test public void normalAsync() { - Observable.range(1, 10) + TestObserverEx to = Observable.range(1, 10) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { return Single.just(v).subscribeOn(Schedulers.computation()); } }) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(to, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -123,14 +125,14 @@ public SingleSource apply(Integer v) throws Exception { @Test public void normalDelayErrorAll() { - TestObserver to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) + TestObserverEx to = Observable.range(1, 10).concatWith(Observable.error(new TestException())) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { return Single.error(new TestException()); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -142,7 +144,7 @@ public SingleSource apply(Integer v) throws Exception { @Test public void takeAsync() { - Observable.range(1, 10) + TestObserverEx to = Observable.range(1, 10) .flatMapSingle(new Function>() { @Override public SingleSource apply(Integer v) throws Exception { @@ -150,13 +152,14 @@ public SingleSource apply(Integer v) throws Exception { } }) .take(2) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(2) - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(to, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test @@ -201,7 +204,7 @@ public SingleSource apply(Integer v) throws Exception { } }) .take(500) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) @@ -279,7 +282,7 @@ protected void subscribeActual(Observer observer) { } } .flatMapSingle(Functions.justFunction(Single.just(2))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -301,7 +304,7 @@ protected void subscribeActual(SingleObserver observer) { observer.onError(new TestException("Second")); } })) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java index 17c5a3ba3e..dccc1d3bcd 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlatMapTest.java @@ -23,8 +23,8 @@ import org.junit.*; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; @@ -34,6 +34,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableFlatMapTest { @Test @@ -341,12 +342,12 @@ public Observable apply(Integer t1) { source.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); Set expected = new HashSet(Arrays.asList( 10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101 )); - Assert.assertEquals(expected.size(), to.valueCount()); + Assert.assertEquals(expected.size(), to.values().size()); Assert.assertTrue(expected.containsAll(to.values())); } @@ -372,13 +373,13 @@ public Integer apply(Integer t1, Integer t2) { source.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); Set expected = new HashSet(Arrays.asList( 1010, 1011, 2020, 2021, 3030, 3031, 4040, 4041, 5050, 5051, 6060, 6061, 7070, 7071, 8080, 8081, 9090, 9091, 10100, 10101 )); - Assert.assertEquals(expected.size(), to.valueCount()); + Assert.assertEquals(expected.size(), to.values().size()); System.out.println("--> testFlatMapSelectorMaxConcurrent: " + to.values()); Assert.assertTrue(expected.containsAll(to.values())); } @@ -414,12 +415,12 @@ public void testFlatMapTransformsMaxConcurrentNormal() { Observable source = Observable.fromIterable(Arrays.asList(10, 20, 30)); Observer o = TestHelper.mockObserver(); - TestObserver to = new TestObserver(o); + TestObserverEx to = new TestObserverEx(o); Function> just = just(onError); source.flatMap(just(onNext), just, just0(onComplete), m).subscribe(to); - to.awaitTerminalEvent(1, TimeUnit.SECONDS); + to.awaitDone(1, TimeUnit.SECONDS); to.assertNoErrors(); to.assertTerminated(); @@ -440,7 +441,7 @@ public void flatMapRangeAsyncLoop() { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); } - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.range(0, 1000) .flatMap(new Function>() { @Override @@ -451,9 +452,9 @@ public Observable apply(Integer t) { .observeOn(Schedulers.computation()) .subscribe(to); - to.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + to.awaitDone(2500, TimeUnit.MILLISECONDS); if (to.completions() == 0) { - System.out.println(to.valueCount()); + System.out.println(to.values().size()); } to.assertTerminated(); to.assertNoErrors(); @@ -478,7 +479,7 @@ public void flatMapRangeMixedAsyncLoop() { if (i % 10 == 0) { System.out.println("flatMapRangeAsyncLoop > " + i); } - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.range(0, 1000) .flatMap(new Function>() { final Random rnd = new Random(); @@ -494,9 +495,9 @@ public Observable apply(Integer t) { .observeOn(Schedulers.computation()) .subscribe(to); - to.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + to.awaitDone(2500, TimeUnit.MILLISECONDS); if (to.completions() == 0) { - System.out.println(to.valueCount()); + System.out.println(to.values().size()); } to.assertTerminated(); to.assertNoErrors(); @@ -525,7 +526,7 @@ public Observable apply(Integer t) { } }).subscribe(to); - to.awaitTerminalEvent(5, TimeUnit.SECONDS); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertComplete(); to.assertValueCount(1000); @@ -711,7 +712,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -739,7 +740,7 @@ public Object apply(Integer w) throws Exception { @Test public void fusedInnerThrows2() { - TestObserver to = Observable.range(1, 2).hide() + TestObserverEx to = Observable.range(1, 2).hide() .flatMap(new Function>() { @Override public ObservableSource apply(Integer v) throws Exception { @@ -751,7 +752,7 @@ public Integer apply(Integer w) throws Exception { }); } }, true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.errorList(to); @@ -802,7 +803,7 @@ public void cancelScalarDrainRace() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; Runnable r2 = new Runnable() { @@ -841,7 +842,7 @@ public void cancelDrainRace() { @Override public void run() { just2.onNext(1); - to.cancel(); + to.dispose(); } }; Runnable r2 = new Runnable() { @@ -875,7 +876,7 @@ public Object apply(Integer v, Object w) throws Exception { return v; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The mapper returned a null Iterable"); } @@ -893,7 +894,7 @@ public Object apply(Integer v, Object w) throws Exception { return v; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The mapper returned a null ObservableSource"); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlattenIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlattenIterableTest.java index 8b870877e4..3185870007 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFlattenIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFlattenIterableTest.java @@ -20,11 +20,11 @@ import org.junit.Test; -import io.reactivex.*; import io.reactivex.Observable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableFlattenIterableTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableForEachTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableForEachTest.java index 960f0acdde..979e41404b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableForEachTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableForEachTest.java @@ -20,13 +20,13 @@ import org.junit.Test; import io.reactivex.Observable; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableForEachTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java index 542165907f..034e18f529 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromCallableTest.java @@ -34,6 +34,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableFromCallableTest { @@ -130,7 +131,7 @@ public String answer(InvocationOnMock invocation) throws Throwable { observerLatch.await(); // Unsubscribing before emission - outer.cancel(); + outer.dispose(); // Emitting result funcLatch.countDown(); @@ -266,7 +267,7 @@ public void disposedOnCall() { Observable.fromCallable(new Callable() { @Override public Integer call() throws Exception { - to.cancel(); + to.dispose(); return 1; } }) @@ -284,7 +285,7 @@ public void disposedOnCallThrows() { Observable.fromCallable(new Callable() { @Override public Integer call() throws Exception { - to.cancel(); + to.dispose(); throw new TestException(); } }) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java index 3b0a9d4970..2e4fa99d8c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromIterableTest.java @@ -23,8 +23,8 @@ import org.junit.Test; import org.mockito.Mockito; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; @@ -32,6 +32,7 @@ import io.reactivex.internal.fuseable.*; import io.reactivex.internal.util.CrashingIterable; import io.reactivex.observers.*; +import io.reactivex.testsupport.*; public class ObservableFromIterableTest { @@ -118,7 +119,7 @@ public void testObservableFromIterable() { public void testNoBackpressure() { Observable o = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5)); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); o.subscribe(to); @@ -252,14 +253,14 @@ public ObservableSource apply(Integer v) { @Test public void iteratorThrows() { Observable.fromIterable(new CrashingIterable(1, 100, 100)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @Test public void hasNext2Throws() { Observable.fromIterable(new CrashingIterable(100, 2, 100)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -276,7 +277,7 @@ public Iterator iterator() { @Override public boolean hasNext() { if (++count == 2) { - to.cancel(); + to.dispose(); } return true; } @@ -302,12 +303,12 @@ public void remove() { @Test public void fusionRejected() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC); Observable.fromIterable(Arrays.asList(1, 2, 3)) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromTest.java index 61d459fa43..36f0797445 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableFromTest.java @@ -22,8 +22,8 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class ObservableFromTest { @@ -77,12 +77,12 @@ public ObservableSource apply(Flowable f) throws Exception { @Test public void fusionRejected() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC); Observable.fromArray(1, 2, 3) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGenerateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGenerateTest.java index 94a5fa5adc..28b16fae7b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGenerateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGenerateTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ObservableGenerateTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java index 42f441bd10..ed62bd0bc4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupByTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -21,6 +22,7 @@ import java.util.concurrent.atomic.*; import org.junit.Test; +import org.mockito.Mockito; import io.reactivex.*; import io.reactivex.Observable; @@ -33,8 +35,7 @@ import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; - -import org.mockito.Mockito; +import io.reactivex.testsupport.*; public class ObservableGroupByTest { @@ -1051,7 +1052,7 @@ public String apply(Integer l) { } }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } @@ -1153,7 +1154,7 @@ public String apply(String v) { TestObserver to = new TestObserver(); m.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); System.out.println("ts .get " + to.values()); to.assertNoErrors(); assertEquals(to.values(), @@ -1167,10 +1168,10 @@ public void keySelectorThrows() { Observable m = source.groupBy(fail(0), dbl).flatMap(FLATTEN_INTEGER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); m.subscribe(to); - to.awaitTerminalEvent(); - assertEquals(1, to.errorCount()); + to.awaitDone(5, TimeUnit.SECONDS); + assertEquals(1, to.errors().size()); to.assertNoValues(); } @@ -1179,10 +1180,10 @@ public void valueSelectorThrows() { Observable source = Observable.just(0, 1, 2, 3, 4, 5, 6); Observable m = source.groupBy(identity, fail(0)).flatMap(FLATTEN_INTEGER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); m.subscribe(to); - to.awaitTerminalEvent(); - assertEquals(1, to.errorCount()); + to.awaitDone(5, TimeUnit.SECONDS); + assertEquals(1, to.errors().size()); to.assertNoValues(); } @@ -1195,7 +1196,7 @@ public void innerEscapeCompleted() { TestObserver to = new TestObserver(); m.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); System.out.println(to.values()); } @@ -1236,10 +1237,10 @@ public void testError2() { Observable m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); m.subscribe(to); - to.awaitTerminalEvent(); - assertEquals(1, to.errorCount()); + to.awaitDone(5, TimeUnit.SECONDS); + assertEquals(1, to.errors().size()); to.assertValueCount(1); } @@ -1295,7 +1296,7 @@ public void accept(Notification t1) { } }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } @@ -1327,7 +1328,7 @@ public String apply(Integer l) { } }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } @@ -1397,11 +1398,11 @@ public Integer apply(Integer integer) { @Test public void testGroupByShouldPropagateError() { final Throwable e = new RuntimeException("Oops"); - final TestObserver inner1 = new TestObserver(); - final TestObserver inner2 = new TestObserver(); + final TestObserverEx inner1 = new TestObserverEx(); + final TestObserverEx inner2 = new TestObserverEx(); - final TestObserver> outer - = new TestObserver>(new DefaultObserver>() { + final TestObserverEx> outer + = new TestObserverEx>(new DefaultObserver>() { @Override public void onComplete() { @@ -1511,7 +1512,7 @@ public void onNext(Integer t) { public void reentrantCompleteCancel() { final PublishSubject ps = PublishSubject.create(); - TestObserver to = new TestObserver() { + TestObserverEx to = new TestObserverEx() { @Override public void onNext(Integer t) { super.onNext(t); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java index 03d801f4d8..de376fcf2f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableGroupJoinTest.java @@ -24,8 +24,8 @@ import org.junit.*; import org.mockito.MockitoAnnotations; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.*; @@ -35,6 +35,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableGroupJoinTest { @@ -515,7 +516,7 @@ public void innerErrorRace() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver> to = Observable.just(1) + TestObserverEx> to = Observable.just(1) .groupJoin( Observable.just(2).concatWith(Observable.never()), new Function>() { @@ -537,7 +538,7 @@ public Observable apply(Integer r, Observable l) throws Except } } ) - .test(); + .to(TestHelper.>testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); @@ -587,7 +588,7 @@ public void outerErrorRace() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = ps1 + TestObserverEx to = ps1 .groupJoin( ps2, new Function>() { @@ -610,7 +611,7 @@ public Observable apply(Object r, Observable l) throws Exception } ) .flatMap(Functions.>identity()) - .test(); + .to(TestHelper.testConsumer()); final TestException ex1 = new TestException(); final TestException ex2 = new TestException(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableHideTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableHideTest.java index d4c2bf002f..d152ae36fd 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableHideTest.java @@ -22,6 +22,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableHideTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsTest.java index b930349d18..fdcb7012b9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableIgnoreElementsTest.java @@ -19,11 +19,12 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableIgnoreElementsTest { @@ -57,7 +58,7 @@ public void accept(Integer t) { @Test public void testCompletedOkObservable() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.range(1, 10).ignoreElements().toObservable().subscribe(to); to.assertNoErrors(); to.assertNoValues(); @@ -68,7 +69,7 @@ public void testCompletedOkObservable() { @Test public void testErrorReceivedObservable() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); TestException ex = new TestException("boo"); Observable.error(ex).ignoreElements().toObservable().subscribe(to); to.assertNoValues(); @@ -123,7 +124,7 @@ public void accept(Integer t) { @Test public void testCompletedOk() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.range(1, 10).ignoreElements().subscribe(to); to.assertNoErrors(); to.assertNoValues(); @@ -134,7 +135,7 @@ public void testCompletedOk() { @Test public void testErrorReceived() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); TestException ex = new TestException("boo"); Observable.error(ex).ignoreElements().subscribe(to); to.assertNoValues(); @@ -161,7 +162,7 @@ public void run() { } @Test - public void cancel() { + public void dispose() { PublishSubject ps = PublishSubject.create(); @@ -169,7 +170,7 @@ public void cancel() { assertTrue(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); @@ -177,7 +178,7 @@ public void cancel() { } @Test - public void dispose() { + public void checkDispose() { TestHelper.checkDisposed(Observable.just(1).ignoreElements()); TestHelper.checkDisposed(Observable.just(1).ignoreElements().toObservable()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableInternalHelperTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableInternalHelperTest.java index e03d651bda..c748cf67cb 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableInternalHelperTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableInternalHelperTest.java @@ -15,7 +15,7 @@ import static org.junit.Assert.*; import org.junit.Test; -import io.reactivex.TestHelper; +import io.reactivex.testsupport.TestHelper; public class ObservableInternalHelperTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalRangeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalRangeTest.java index e7af11c54c..289a6e3672 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalRangeTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableIntervalRangeTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalTest.java index 17d370a56d..68a5990eae 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableIntervalTest.java @@ -21,6 +21,7 @@ import io.reactivex.internal.operators.observable.ObservableInterval.IntervalObserver; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class ObservableIntervalTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java index 8ced523827..4cba3c7887 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableJoinTest.java @@ -31,6 +31,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableJoinTest { Observer observer = TestHelper.mockObserver(); @@ -400,7 +401,7 @@ public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -416,7 +417,7 @@ public void badEndSource() { @SuppressWarnings("rawtypes") final Observer[] o = { null }; - TestObserver to = Observable.just(1) + TestObserverEx to = Observable.just(1) .join(Observable.just(2), Functions.justFunction(Observable.never()), Functions.justFunction(new Observable() { @@ -433,7 +434,7 @@ public Integer apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test(); + .to(TestHelper.testConsumer()); o[0].onError(new TestException("Second")); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java index 6f3ecd39c8..05fbb2ecf9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableLastTest.java @@ -25,6 +25,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class ObservableLastTest { @@ -291,7 +292,7 @@ public void lastOrErrorMultipleElements() { public void lastOrErrorError() { Observable.error(new RuntimeException("error")) .lastOrError() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMapNotificationTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMapNotificationTest.java index 78b794e237..10e8c10500 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMapNotificationTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMapNotificationTest.java @@ -22,6 +22,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.operators.observable.ObservableMapNotification.MapNotificationObserver; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class ObservableMapNotificationTest { @Test @@ -87,7 +88,7 @@ public ObservableSource apply(Observable o) throws Exception { @Test public void onErrorCrash() { - TestObserver to = Observable.error(new TestException("Outer")) + TestObserverEx to = Observable.error(new TestException("Outer")) .flatMap(Functions.justFunction(Observable.just(1)), new Function>() { @Override @@ -96,7 +97,7 @@ public Observable apply(Throwable t) throws Exception { } }, Functions.justSupplier(Observable.just(3))) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertError(to, 0, TestException.class, "Outer"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java index 3d824be862..27f9d357d8 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMapTest.java @@ -21,15 +21,15 @@ import org.junit.*; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.UnicastSubject; +import io.reactivex.testsupport.*; public class ObservableMapTest { @@ -350,19 +350,19 @@ public ObservableSource apply(Observable o) throws Exception { @Test public void fusedSync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.range(1, 5) .map(Functions.identity()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.SYNC) + to.assertFusionMode(QueueFuseable.SYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void fusedAsync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); UnicastSubject us = UnicastSubject.create(); @@ -372,19 +372,19 @@ public void fusedAsync() { TestHelper.emit(us, 1, 2, 3, 4, 5); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3, 4, 5); } @Test public void fusedReject() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY | QueueFuseable.BOUNDARY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY | QueueFuseable.BOUNDARY); Observable.range(1, 5) .map(Functions.identity()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMaterializeTest.java index d163293c69..17aa3f40e1 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMaterializeTest.java @@ -25,7 +25,8 @@ import io.reactivex.Observer; import io.reactivex.disposables.Disposables; import io.reactivex.functions.*; -import io.reactivex.observers.*; +import io.reactivex.observers.DefaultObserver; +import io.reactivex.testsupport.*; public class ObservableMaterializeTest { @@ -101,7 +102,7 @@ public void testMultipleSubscribes() throws InterruptedException, ExecutionExcep @Test public void testWithCompletionCausingError() { - TestObserver> to = new TestObserver>(); + TestObserverEx> to = new TestObserverEx>(); final RuntimeException ex = new RuntimeException("boo"); Observable.empty().materialize().doOnNext(new Consumer() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java index 833f9105c5..186034529a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeDelayErrorTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -22,12 +23,13 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.*; -import io.reactivex.observers.*; +import io.reactivex.observers.DefaultObserver; +import io.reactivex.testsupport.*; public class ObservableMergeDelayErrorTest { @@ -488,15 +490,15 @@ public void onComplete() { @Test public void testErrorInParentObservable() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.mergeDelayError( Observable.just(Observable.just(1), Observable.just(2)) .startWith(Observable. error(new RuntimeException())) ).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertTerminated(); to.assertValues(1, 2); - assertEquals(1, to.errorCount()); + assertEquals(1, to.errors().size()); } @@ -517,11 +519,11 @@ public void subscribe(Observer> op) { Observer stringObserver = TestHelper.mockObserver(); - TestObserver to = new TestObserver(stringObserver); + TestObserverEx to = new TestObserverEx(stringObserver); Observable m = Observable.mergeDelayError(parentObservable); m.subscribe(to); System.out.println("testErrorInParentObservableDelayed | " + i); - to.awaitTerminalEvent(2000, TimeUnit.MILLISECONDS); + to.awaitDone(2000, TimeUnit.MILLISECONDS); to.assertTerminated(); verify(stringObserver, times(2)).onNext("hello"); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java index ef52095f25..5ce308c607 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeMaxConcurrentTest.java @@ -21,13 +21,14 @@ import org.junit.*; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.Disposables; import io.reactivex.internal.schedulers.IoScheduler; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class ObservableMergeMaxConcurrentTest { @@ -157,7 +158,7 @@ public void testMergeALotOfSourcesOneByOneSynchronouslyTakeHalf() { @Test public void testSimple() { for (int i = 1; i < 100; i++) { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { @@ -176,7 +177,7 @@ public void testSimple() { @Test public void testSimpleOneLess() { for (int i = 2; i < 100; i++) { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); List> sourceList = new ArrayList>(i); List result = new ArrayList(i); for (int j = 1; j <= i; j++) { @@ -218,7 +219,7 @@ public void testSimpleAsync() { Observable.merge(sourceList, i).subscribe(to); - to.awaitTerminalEvent(1, TimeUnit.SECONDS); + to.awaitDone(1, TimeUnit.SECONDS); to.assertNoErrors(); Set actual = new HashSet(to.values()); @@ -250,7 +251,7 @@ public void testSimpleOneLessAsync() { Observable.merge(sourceList, i - 1).subscribe(to); - to.awaitTerminalEvent(1, TimeUnit.SECONDS); + to.awaitDone(1, TimeUnit.SECONDS); to.assertNoErrors(); Set actual = new HashSet(to.values()); @@ -270,7 +271,7 @@ public void testTake() throws Exception { Observable.merge(sourceList, 2).take(5).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertValueCount(5); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java index 8b69ef593b..3694e90681 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.*; @@ -32,6 +33,7 @@ import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.*; public class ObservableMergeTest { @@ -192,7 +194,7 @@ public void testMergeArrayWithThreading() { TestObserver to = new TestObserver(stringObserver); m.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); verify(stringObserver, never()).onError(any(Throwable.class)); @@ -339,7 +341,7 @@ public void testError2() { @Test @Ignore("Subscribe should not throw") public void testThrownErrorHandling() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable o1 = Observable.unsafeCreate(new ObservableSource() { @Override @@ -350,7 +352,7 @@ public void subscribe(Observer observer) { }); Observable.merge(o1, o1).subscribe(to); - to.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + to.awaitDone(1000, TimeUnit.MILLISECONDS); to.assertTerminated(); System.out.println("Error: " + to.errors()); } @@ -425,7 +427,7 @@ public void testUnsubscribeAsObservablesComplete() { AtomicBoolean os2 = new AtomicBoolean(false); Observable o2 = createObservableOf5IntervalsOf1SecondIncrementsWithSubscriptionHook(scheduler2, os2); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.merge(o1, o2).subscribe(to); // we haven't incremented time so nothing should be received yet @@ -540,10 +542,10 @@ public void testConcurrency() { for (int i = 0; i < 10; i++) { Observable merge = Observable.merge(o, o, o); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); merge.subscribe(to); - to.awaitTerminalEvent(3, TimeUnit.SECONDS); + to.awaitDone(3, TimeUnit.SECONDS); to.assertTerminated(); to.assertNoErrors(); to.assertComplete(); @@ -596,7 +598,7 @@ public void run() { TestObserver to = new TestObserver(); merge.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertComplete(); List onNextEvents = to.values(); assertEquals(300, onNextEvents.size()); @@ -643,7 +645,7 @@ public void run() { TestObserver to = new TestObserver(); merge.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertComplete(); List onNextEvents = to.values(); @@ -659,7 +661,7 @@ public void testBackpressureUpstream() throws InterruptedException { final AtomicInteger generated2 = new AtomicInteger(); Observable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); - TestObserver testObserver = new TestObserver() { + TestObserverEx testObserver = new TestObserverEx() { @Override public void onNext(Integer t) { System.err.println("TestObserver received => " + t + " on thread " + Thread.currentThread()); @@ -668,7 +670,7 @@ public void onNext(Integer t) { }; Observable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).subscribe(testObserver); - testObserver.awaitTerminalEvent(); + testObserver.awaitDone(5, TimeUnit.SECONDS); if (testObserver.errors().size() > 0) { testObserver.errors().get(0).printStackTrace(); } @@ -697,7 +699,7 @@ public void testBackpressureUpstream2() throws InterruptedException { final AtomicInteger generated1 = new AtomicInteger(); Observable o1 = createInfiniteObservable(generated1).subscribeOn(Schedulers.computation()); - TestObserver testObserver = new TestObserver() { + TestObserverEx testObserver = new TestObserverEx() { @Override public void onNext(Integer t) { super.onNext(t); @@ -705,7 +707,7 @@ public void onNext(Integer t) { }; Observable.merge(o1.take(Flowable.bufferSize() * 2), Observable.just(-99)).subscribe(testObserver); - testObserver.awaitTerminalEvent(); + testObserver.awaitDone(5, TimeUnit.SECONDS); List onNextEvents = testObserver.values(); @@ -734,7 +736,7 @@ public void testBackpressureDownstreamWithConcurrentStreams() throws Interrupted final AtomicInteger generated2 = new AtomicInteger(); Observable o2 = createInfiniteObservable(generated2).subscribeOn(Schedulers.computation()); - TestObserver to = new TestObserver() { + TestObserverEx to = new TestObserverEx() { @Override public void onNext(Integer t) { if (t < 100) { @@ -751,7 +753,7 @@ public void onNext(Integer t) { }; Observable.merge(o1.take(Flowable.bufferSize() * 2), o2.take(Flowable.bufferSize() * 2)).observeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); if (to.errors().size() > 0) { to.errors().get(0).printStackTrace(); } @@ -788,7 +790,7 @@ public Observable apply(Integer t1) { }); - TestObserver to = new TestObserver() { + TestObserverEx to = new TestObserverEx() { int i; @Override @@ -807,7 +809,7 @@ public void onNext(Integer t) { }; Observable.merge(o1).observeOn(Schedulers.computation()).take(Flowable.bufferSize() * 2).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); if (to.errors().size() > 0) { to.errors().get(0).printStackTrace(); } @@ -825,7 +827,7 @@ public void onNext(Integer t) { @Ignore("Null values not permitted") public void mergeWithNullValues() { System.out.println("mergeWithNullValues"); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.merge(Observable.just(null, "one"), Observable.just("two", null)).subscribe(to); to.assertTerminated(); to.assertNoErrors(); @@ -866,7 +868,7 @@ public void mergingNullObservable() { public void merge1AsyncStreamOf1() { TestObserver to = new TestObserver(); mergeNAsyncStreamsOfN(1, 1).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1, to.values().size()); } @@ -875,7 +877,7 @@ public void merge1AsyncStreamOf1() { public void merge1AsyncStreamOf1000() { TestObserver to = new TestObserver(); mergeNAsyncStreamsOfN(1, 1000).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1000, to.values().size()); } @@ -884,7 +886,7 @@ public void merge1AsyncStreamOf1000() { public void merge10AsyncStreamOf1000() { TestObserver to = new TestObserver(); mergeNAsyncStreamsOfN(10, 1000).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(10000, to.values().size()); } @@ -893,7 +895,7 @@ public void merge10AsyncStreamOf1000() { public void merge1000AsyncStreamOf1000() { TestObserver to = new TestObserver(); mergeNAsyncStreamsOfN(1000, 1000).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1000000, to.values().size()); } @@ -902,7 +904,7 @@ public void merge1000AsyncStreamOf1000() { public void merge2000AsyncStreamOf100() { TestObserver to = new TestObserver(); mergeNAsyncStreamsOfN(2000, 100).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(200000, to.values().size()); } @@ -911,7 +913,7 @@ public void merge2000AsyncStreamOf100() { public void merge100AsyncStreamOf1() { TestObserver to = new TestObserver(); mergeNAsyncStreamsOfN(100, 1).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(100, to.values().size()); } @@ -933,7 +935,7 @@ public Observable apply(Integer i) { public void merge1SyncStreamOf1() { TestObserver to = new TestObserver(); mergeNSyncStreamsOfN(1, 1).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1, to.values().size()); } @@ -942,7 +944,7 @@ public void merge1SyncStreamOf1() { public void merge1SyncStreamOf1000000() { TestObserver to = new TestObserver(); mergeNSyncStreamsOfN(1, 1000000).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1000000, to.values().size()); } @@ -951,7 +953,7 @@ public void merge1SyncStreamOf1000000() { public void merge1000SyncStreamOf1000() { TestObserver to = new TestObserver(); mergeNSyncStreamsOfN(1000, 1000).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1000000, to.values().size()); } @@ -960,7 +962,7 @@ public void merge1000SyncStreamOf1000() { public void merge10000SyncStreamOf10() { TestObserver to = new TestObserver(); mergeNSyncStreamsOfN(10000, 10).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(100000, to.values().size()); } @@ -969,7 +971,7 @@ public void merge10000SyncStreamOf10() { public void merge1000000SyncStreamOf1() { TestObserver to = new TestObserver(); mergeNSyncStreamsOfN(1000000, 1).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(1000000, to.values().size()); } @@ -1041,7 +1043,7 @@ public void subscribe(Observer observer) { }); Observable.merge(os).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); assertEquals(10000, to.values().size()); } @@ -1061,7 +1063,7 @@ public Observable apply(Integer t) { }; ; - void runMerge(Function> func, TestObserver to) { + void runMerge(Function> func, TestObserverEx to) { List list = new ArrayList(); for (int i = 0; i < 1000; i++) { list.add(i); @@ -1080,18 +1082,18 @@ void runMerge(Function> func, TestObserver @Test public void testFastMergeFullScalar() { - runMerge(toScalar, new TestObserver()); + runMerge(toScalar, new TestObserverEx()); } @Test public void testFastMergeHiddenScalar() { - runMerge(toHiddenScalar, new TestObserver()); + runMerge(toHiddenScalar, new TestObserverEx()); } @Test public void testSlowMergeFullScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { - TestObserver to = new TestObserver() { + TestObserverEx to = new TestObserverEx() { int remaining = req; @Override @@ -1109,7 +1111,7 @@ public void onNext(Integer t) { @Test public void testSlowMergeHiddenScalar() { for (final int req : new int[] { 16, 32, 64, 128, 256 }) { - TestObserver to = new TestObserver() { + TestObserverEx to = new TestObserverEx() { int remaining = req; @Override public void onNext(Integer t) { @@ -1139,7 +1141,7 @@ public void mergeErrors() { Observable source2 = Observable.error(new TestException("Second")); Observable.merge(source1, source2) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(errors.toString(), errors.isEmpty()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java index 872509e164..76c939bc76 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithCompletableTest.java @@ -23,6 +23,7 @@ import io.reactivex.functions.Action; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableMergeWithCompletableTest { @@ -66,7 +67,7 @@ public void cancel() { assertTrue(ps.hasObservers()); assertTrue(cs.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); assertFalse(cs.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java index a70e4c2fa8..fec139f169 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithMaybeTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableMergeWithMaybeTest { @@ -75,7 +76,7 @@ public void cancel() { assertTrue(ps.hasObservers()); assertTrue(cs.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); assertFalse(cs.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java index 25ce78d486..cf5710ad00 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableMergeWithSingleTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableMergeWithSingleTest { @@ -67,7 +68,7 @@ public void cancel() { assertTrue(ps.hasObservers()); assertTrue(cs.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); assertFalse(cs.hasObservers()); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java index 8d948b2592..062da1e6d0 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableObserveOnTest.java @@ -39,6 +39,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableObserveOnTest { @@ -65,11 +66,11 @@ public void testOrdering() throws InterruptedException { Observer observer = TestHelper.mockObserver(); InOrder inOrder = inOrder(observer); - TestObserver to = new TestObserver(observer); + TestObserverEx to = new TestObserverEx(observer); obs.observeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + to.awaitDone(1000, TimeUnit.MILLISECONDS); if (to.errors().size() > 0) { for (Throwable t : to.errors()) { t.printStackTrace(); @@ -433,7 +434,7 @@ public boolean hasNext() { .observeOn(Schedulers.newThread()) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertValues(0, 1, 2, 3, 4, 5, 6); assertEquals(7, generated.get()); } @@ -442,7 +443,7 @@ public boolean hasNext() { public void testAsyncChild() { TestObserver to = new TestObserver(); Observable.range(0, 100000).observeOn(Schedulers.newThread()).observeOn(Schedulers.newThread()).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } @@ -564,33 +565,33 @@ public void inputAsyncFusedErrorDelayed() { @Test public void outputFused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.range(1, 5).hide() .observeOn(Schedulers.single()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5); } @Test public void outputFusedReject() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Observable.range(1, 5).hide() .observeOn(Schedulers.single()) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5); } @Test public void inputOutputAsyncFusedError() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); UnicastSubject us = UnicastSubject.create(); @@ -603,14 +604,14 @@ public void inputOutputAsyncFusedError() { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); } @Test public void inputOutputAsyncFusedErrorDelayed() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); UnicastSubject us = UnicastSubject.create(); @@ -623,7 +624,7 @@ public void inputOutputAsyncFusedErrorDelayed() { .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); - ObserverFusion.assertFusion(to, QueueFuseable.ASYNC) + to.assertFusionMode(QueueFuseable.ASYNC) .awaitDone(5, TimeUnit.SECONDS) .assertFailure(TestException.class); } @@ -789,7 +790,7 @@ public void workerNotDisposedPrematurelyAsyncInNormalOut() { } static final class TestObserverFusedCanceling - extends TestObserver { + extends TestObserverEx { TestObserverFusedCanceling() { super(); @@ -798,7 +799,7 @@ static final class TestObserverFusedCanceling @Override public void onComplete() { - cancel(); + dispose(); super.onComplete(); } } @@ -807,7 +808,7 @@ public void onComplete() { public void workerNotDisposedPrematurelyNormalInAsyncOut() { DisposeTrackingScheduler s = new DisposeTrackingScheduler(); - TestObserver to = new TestObserverFusedCanceling(); + TestObserverEx to = new TestObserverFusedCanceling(); Observable.just(1).hide().observeOn(s).subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java index b8b3f67f1e..fe855f5108 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaFunctionTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.*; import java.io.IOException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.*; @@ -28,8 +29,9 @@ import io.reactivex.disposables.*; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class ObservableOnErrorResumeNextViaFunctionTest { @@ -150,7 +152,7 @@ public Observable apply(Throwable t1) { @Test @Ignore("Failed operator may leave the child Observer in an inconsistent state which prevents further error delivery.") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperator() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just(1).lift(new ObservableOperator() { @Override @@ -183,7 +185,7 @@ public Observable apply(Throwable t1) { @Test @Ignore("A crashing operator may leave the downstream in an inconsistent state and not suitable for event delivery") public void testOnErrorResumeReceivesErrorFromPreviousNonProtectedOperatorOnNext() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just(1).lift(new ObservableOperator() { @Override @@ -262,7 +264,7 @@ public Observable apply(Throwable t1) { TestObserver to = new TestObserver(observer); o.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); @@ -341,7 +343,7 @@ public Integer apply(Integer t1) { }) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java index 3dab17f83f..bf520be0d9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorResumeNextViaObservableTest.java @@ -14,16 +14,20 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; + import org.junit.*; import org.mockito.Mockito; import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Function; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableOnErrorResumeNextViaObservableTest { @@ -137,7 +141,7 @@ public void subscribe(Observer t1) { TestObserver to = new TestObserver(observer); observable.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); @@ -211,7 +215,7 @@ public Integer apply(Integer t1) { }) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java index 142d4a7f9f..87391ca1ad 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnErrorReturnTest.java @@ -14,8 +14,10 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import org.junit.Test; @@ -25,8 +27,9 @@ import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableOnErrorReturnTest { @@ -129,7 +132,7 @@ public String apply(Throwable t1) { Observer observer = TestHelper.mockObserver(); TestObserver to = new TestObserver(observer); observable.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); @@ -170,7 +173,7 @@ public Integer apply(Integer t1) { }) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java index 50312e3884..31c95c3ee2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableOnExceptionResumeNextViaObservableTest.java @@ -14,8 +14,11 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; + import org.junit.Test; import org.mockito.Mockito; @@ -24,6 +27,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableOnExceptionResumeNextViaObservableTest { @@ -207,7 +211,7 @@ public Integer apply(Integer t1) { }) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java index ff703266ad..e2f7c1aa1d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservablePublishTest.java @@ -34,6 +34,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservablePublishTest { @@ -128,9 +129,9 @@ public void run() { TestObserver to = new TestObserver(); Observable.merge(fast, slow).subscribe(to); is.connect(); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 4, to.valueCount()); + assertEquals(Flowable.bufferSize() * 4, to.values().size()); } // use case from https://github.com/ReactiveX/RxJava/issues/1732 @@ -161,7 +162,7 @@ public boolean test(Integer i) { } }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertValues(0, 1, 2, 3); assertEquals(5, emitted.get()); @@ -213,7 +214,7 @@ public void run() { final TestObserver to1 = new TestObserver() { @Override public void onNext(Integer t) { - if (valueCount() == 2) { + if (values().size() == 2) { source.doOnDispose(new Action() { @Override public void run() { @@ -233,8 +234,8 @@ public void run() { }).take(5) .subscribe(to1); - to1.awaitTerminalEvent(); - to2.awaitTerminalEvent(); + to1.awaitDone(5, TimeUnit.SECONDS); + to2.awaitDone(5, TimeUnit.SECONDS); to1.assertNoErrors(); to2.assertNoErrors(); @@ -256,7 +257,7 @@ public void testConnectWithNoSubscriber() { co.connect(); // Emit 0 scheduler.advanceTimeBy(15, TimeUnit.MILLISECONDS); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); co.subscribe(to); // Emit 1 and 2 scheduler.advanceTimeBy(50, TimeUnit.MILLISECONDS); @@ -269,7 +270,7 @@ public void testConnectWithNoSubscriber() { public void testSubscribeAfterDisconnectThenConnect() { ConnectableObservable source = Observable.just(1).publish(); - TestObserver to1 = new TestObserver(); + TestObserverEx to1 = new TestObserverEx(); source.subscribe(to1); @@ -280,8 +281,8 @@ public void testSubscribeAfterDisconnectThenConnect() { to1.assertTerminated(); source.reset(); - - TestObserver to2 = new TestObserver(); + + TestObserverEx to2 = new TestObserverEx(); source.subscribe(to2); @@ -299,7 +300,7 @@ public void testSubscribeAfterDisconnectThenConnect() { public void testNoSubscriberRetentionOnCompleted() { ObservablePublish source = (ObservablePublish)Observable.just(1).publish(); - TestObserver to1 = new TestObserver(); + TestObserverEx to1 = new TestObserverEx(); source.subscribe(to1); @@ -381,20 +382,20 @@ public void testObserveOn() { Observable obs = co.observeOn(Schedulers.computation()); for (int i = 0; i < 1000; i++) { for (int j = 1; j < 6; j++) { - List> tos = new ArrayList>(); + List> tos = new ArrayList>(); for (int k = 1; k < j; k++) { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); tos.add(to); obs.subscribe(to); } Disposable connection = co.connect(); - for (TestObserver to : tos) { - to.awaitTerminalEvent(2, TimeUnit.SECONDS); + for (TestObserverEx to : tos) { + to.awaitDone(2, TimeUnit.SECONDS); to.assertTerminated(); to.assertNoErrors(); - assertEquals(1000, to.valueCount()); + assertEquals(1000, to.values().size()); } connection.dispose(); } @@ -491,7 +492,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -573,7 +574,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java index d09ec0d6ce..95b15a3ccd 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeLongTest.java @@ -24,8 +24,9 @@ import io.reactivex.*; import io.reactivex.functions.Consumer; -import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.observers.*; +import io.reactivex.testsupport.*; public class ObservableRangeLongTest { @Test @@ -99,7 +100,7 @@ public void testNoBackpressure() { Observable o = Observable.rangeLong(1, list.size()); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); o.subscribe(to); @@ -170,21 +171,21 @@ public void noOverflow() { @Test public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Observable.rangeLong(1, 2).subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.SYNC) + to.assertFusionMode(QueueFuseable.SYNC) .assertResult(1L, 2L); } @Test public void fusedReject() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC); Observable.rangeLong(1, 2).subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1L, 2L); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java index cbdc0130ec..3a0121d217 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRangeTest.java @@ -26,6 +26,7 @@ import io.reactivex.functions.Consumer; import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.observers.*; +import io.reactivex.testsupport.*; public class ObservableRangeTest { @@ -100,7 +101,7 @@ public void testNoBackpressure() { Observable o = Observable.range(1, list.size()); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); o.subscribe(to); @@ -157,12 +158,12 @@ public void negativeCount() { @Test public void requestWrongFusion() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ASYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.ASYNC); Observable.range(1, 5) .subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE) + to.assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2, 3, 4, 5); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRedoTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRedoTest.java index 9accea7e7e..0bcba7d31c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRedoTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRedoTest.java @@ -35,7 +35,7 @@ public ObservableSource apply(Observable o) throws Exception { @Override public Object apply(Object v) throws Exception { if (++count == 1) { - to.cancel(); + to.dispose(); } return v; } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java index b3f03f79ff..1cd257c22b 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReduceTest.java @@ -27,6 +27,7 @@ import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableReduceTest { Observer observer; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java index 8eec8664d2..49bfc110a4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRefCountTest.java @@ -40,6 +40,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableRefCountTest { @@ -201,8 +202,8 @@ public void run() { to2.dispose(); to1.assertNoErrors(); to2.assertNoErrors(); - assertTrue(to1.valueCount() > 0); - assertTrue(to2.valueCount() > 0); + assertTrue(to1.values().size() > 0); + assertTrue(to2.values().size() > 0); } assertEquals(10, subscribeCount.get()); @@ -232,7 +233,7 @@ public void run() { } }); - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); o.publish().refCount().subscribeOn(Schedulers.newThread()).subscribe(observer); System.out.println("send unsubscribe"); // wait until connected @@ -277,7 +278,7 @@ public void accept(Disposable d) { } }); - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); o.publish().refCount().subscribeOn(Schedulers.computation()).subscribe(observer); System.out.println("send unsubscribe"); @@ -497,8 +498,8 @@ public Integer apply(Integer t1, Integer t2) { }) .publish().refCount(); - TestObserver to1 = new TestObserver(); - TestObserver to2 = new TestObserver(); + TestObserverEx to1 = new TestObserverEx(); + TestObserverEx to2 = new TestObserverEx(); combined.subscribe(to1); combined.subscribe(to2); @@ -865,7 +866,7 @@ public void badSourceDispose() { try { bo.refCount() .test() - .cancel(); + .dispose(); fail("Should have thrown"); } catch (TestException expected) { } @@ -1047,7 +1048,7 @@ public void accept(Disposable d) throws Exception { assertEquals(1, subscriptions[0]); - to1.cancel(); + to1.dispose(); Thread.sleep(100); @@ -1090,7 +1091,7 @@ public void accept(Disposable d) throws Exception { assertEquals(1, subscriptions[0]); - to1.cancel(); + to1.dispose(); assertTrue(ps.hasObservers()); @@ -1122,11 +1123,11 @@ public void comeAndGo() { for (int i = 0; i < 3; i++) { TestObserver to2 = source.test(); - to1.cancel(); + to1.dispose(); to1 = to2; } - to1.cancel(); + to1.dispose(); assertFalse(ps.hasObservers()); } @@ -1147,7 +1148,7 @@ public void unsubscribeSubscribeRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java index dbb72e21ef..28932f9ff6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRepeatTest.java @@ -23,8 +23,8 @@ import org.junit.Test; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; @@ -33,6 +33,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableRepeatTest { @@ -163,7 +164,7 @@ public void testRepeatAndDistinctUnbounded() { .repeat(3) .distinct(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); src.subscribe(to); @@ -190,7 +191,7 @@ public Observable apply(Integer x) { }) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertNoValues(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java index 208d6d0cc0..afff6022d5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableReplayTest.java @@ -25,8 +25,8 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.Scheduler.Worker; import io.reactivex.annotations.NonNull; @@ -41,6 +41,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableReplayTest { @Test @@ -870,7 +871,7 @@ public void testSizedTruncation() { public void testColdReplayNoBackpressure() { Observable source = Observable.range(0, 1000).replay().autoConnect(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); source.subscribe(to); @@ -948,7 +949,7 @@ public void testUnsubscribeSource() throws Throwable { @Test public void testTake() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable cached = Observable.range(1, 100).replay().autoConnect(); cached.take(10).subscribe(to); @@ -964,21 +965,21 @@ public void testTake() { public void testAsync() { Observable source = Observable.range(1, 10000); for (int i = 0; i < 100; i++) { - TestObserver to1 = new TestObserver(); + TestObserverEx to1 = new TestObserverEx(); Observable cached = source.replay().autoConnect(); cached.observeOn(Schedulers.computation()).subscribe(to1); - to1.awaitTerminalEvent(2, TimeUnit.SECONDS); + to1.awaitDone(2, TimeUnit.SECONDS); to1.assertNoErrors(); to1.assertTerminated(); assertEquals(10000, to1.values().size()); - TestObserver to2 = new TestObserver(); + TestObserverEx to2 = new TestObserverEx(); cached.observeOn(Schedulers.computation()).subscribe(to2); - to2.awaitTerminalEvent(2, TimeUnit.SECONDS); + to2.awaitDone(2, TimeUnit.SECONDS); to2.assertNoErrors(); to2.assertTerminated(); assertEquals(10000, to2.values().size()); @@ -994,9 +995,9 @@ public void testAsyncComeAndGo() { Observable output = cached.observeOn(Schedulers.computation()); - List> list = new ArrayList>(100); + List> list = new ArrayList>(100); for (int i = 0; i < 100; i++) { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); list.add(to); output.skip(i * 10).take(10).subscribe(to); } @@ -1006,8 +1007,8 @@ public void testAsyncComeAndGo() { expected.add((long)(i - 10)); } int j = 0; - for (TestObserver to : list) { - to.awaitTerminalEvent(3, TimeUnit.SECONDS); + for (TestObserverEx to : list) { + to.awaitDone(3, TimeUnit.SECONDS); to.assertNoErrors(); to.assertTerminated(); @@ -1035,10 +1036,10 @@ public void subscribe(Observer t) { } }); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); firehose.replay().autoConnect().observeOn(Schedulers.computation()).takeLast(100).subscribe(to); - to.awaitTerminalEvent(3, TimeUnit.SECONDS); + to.awaitDone(3, TimeUnit.SECONDS); to.assertNoErrors(); to.assertTerminated(); @@ -1051,14 +1052,14 @@ public void testValuesAndThenError() { .concatWith(Observable.error(new TestException())) .replay().autoConnect(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); source.subscribe(to); to.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); to.assertNotComplete(); Assert.assertEquals(1, to.errors().size()); - TestObserver to2 = new TestObserver(); + TestObserverEx to2 = new TestObserverEx(); source.subscribe(to2); to2.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); @@ -1229,7 +1230,7 @@ public void addRemoveRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; @@ -1283,7 +1284,7 @@ public void accept(Disposable t) throws Exception { // expected } - co.test().assertEmpty().cancel(); + co.test().assertEmpty().dispose(); co.connect(); @@ -1305,7 +1306,7 @@ protected void subscribeActual(Observer observer) { } }.replay() .autoConnect() - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -1454,7 +1455,7 @@ public void reentrantOnNextCancel() { public void onNext(Integer t) { if (t == 1) { ps.onNext(2); - cancel(); + dispose(); } super.onNext(t); } @@ -1476,7 +1477,7 @@ public void reentrantOnNextCancelBounded() { public void onNext(Integer t) { if (t == 1) { ps.onNext(2); - cancel(); + dispose(); } super.onNext(t); } @@ -1536,7 +1537,7 @@ public Observable apply(Observable v) throws Exception { return null; } }, Schedulers.trampoline()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The selector returned a null ObservableSource"); } @@ -1549,14 +1550,14 @@ public Observable apply(Observable v) throws Exception { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The selector returned a null ObservableSource"); } @Test public void replaySelectorConnectableReturnsNull() { ObservableReplay.multicastSelector(Functions.justSupplier((ConnectableObservable)null), Functions.justFunction(Observable.just(1))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The connectableFactory returned a null ConnectableObservable"); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableResourceWrapperTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableResourceWrapperTest.java index 3f7715e6b9..bed1f59774 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableResourceWrapperTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableResourceWrapperTest.java @@ -17,10 +17,10 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestHelper; public class ObservableResourceWrapperTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java index 551a4e40a8..8242019539 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryTest.java @@ -37,6 +37,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableRetryTest { @@ -90,7 +91,7 @@ public Observable apply(Tuple t) { }}).cast(Object.class); } }).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); InOrder inOrder = inOrder(consumer); @@ -157,7 +158,7 @@ public void accept(Throwable e) { }) .subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); InOrder inOrder = inOrder(observer); // should show 3 attempts inOrder.verify(observer, times(1 + numRetries)).onNext("beginningEveryTime"); @@ -672,7 +673,7 @@ public void testRetryWithBackpressure() throws InterruptedException { Observable origin = Observable.unsafeCreate(new FuncWithErrors(NUM_RETRIES)); TestObserver to = new TestObserver(observer); origin.retry().observeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(5, TimeUnit.SECONDS); + to.awaitDone(5, TimeUnit.SECONDS); InOrder inOrder = inOrder(observer); // should have no errors @@ -713,10 +714,10 @@ public void run() { final AtomicInteger nexts = new AtomicInteger(); try { Observable origin = Observable.unsafeCreate(new FuncWithErrors(NUM_RETRIES)); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); origin.retry() .observeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(2500, TimeUnit.MILLISECONDS); + to.awaitDone(2500, TimeUnit.MILLISECONDS); List onNextEvents = new ArrayList(to.values()); if (onNextEvents.size() != NUM_RETRIES + 2) { for (Throwable t : to.errors()) { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java index 7b0322ab87..d32a1b3839 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableRetryWithPredicateTest.java @@ -25,15 +25,16 @@ import org.junit.Test; import org.mockito.InOrder; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableRetryWithPredicateTest { BiPredicate retryTwice = new BiPredicate() { @@ -277,7 +278,7 @@ public void testTimeoutWithRetry() { @Test public void testIssue2826() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final RuntimeException e = new RuntimeException("You shall not pass"); final AtomicInteger c = new AtomicInteger(); Observable.just(1).map(new Function() { @@ -364,14 +365,14 @@ public void accept(Long t) { @Test public void predicateThrows() { - TestObserver to = Observable.error(new TestException("Outer")) + TestObserverEx to = Observable.error(new TestException("Outer")) .retry(new Predicate() { @Override public boolean test(Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -384,7 +385,7 @@ public boolean test(Throwable e) throws Exception { public void dontRetry() { Observable.error(new TestException("Outer")) .retry(Functions.alwaysFalse()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Outer"); } @@ -407,7 +408,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -420,14 +421,14 @@ public void run() { @Test public void bipredicateThrows() { - TestObserver to = Observable.error(new TestException("Outer")) + TestObserverEx to = Observable.error(new TestException("Outer")) .retry(new BiPredicate() { @Override public boolean test(Integer n, Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -460,7 +461,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java index 01f04653f2..282f3a341c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSampleTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSampleTest { private TestScheduler scheduler; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java index 195fe884d3..0b78c48339 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableScalarXMapTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.disposables.EmptyDisposable; import io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestHelper; public class ObservableScalarXMapTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java index 82e8679e54..b66c35f11e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableScanTest.java @@ -23,8 +23,8 @@ import org.junit.Test; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; @@ -32,6 +32,7 @@ import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableScanTest { @@ -206,7 +207,9 @@ public Integer apply(Integer t1, Integer t2) { } }).take(1); - TestObserver observer = new TestObserver(); + + TestObserverEx observer = new TestObserverEx(); + o.subscribe(observer); observer.assertValue(0); observer.assertTerminated(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java index 4a7a33ddd6..fac2c75237 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSequenceEqualTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.BiPredicate; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSequenceEqualTest { @@ -324,7 +325,7 @@ public void onNextCancelRace() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -351,7 +352,7 @@ public void onNextCancelRaceObservable() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSerializeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSerializeTest.java index 70b14dd6f6..5449a6fd80 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSerializeTest.java @@ -24,6 +24,7 @@ import io.reactivex.*; import io.reactivex.disposables.Disposables; import io.reactivex.observers.DefaultObserver; +import io.reactivex.testsupport.TestHelper; public class ObservableSerializeTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSingleTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSingleTest.java index 9407cf4969..d9cdd8953c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSingleTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSingleTest.java @@ -26,6 +26,7 @@ import io.reactivex.*; import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ObservableSingleTest { @@ -517,7 +518,7 @@ public void singleOrErrorMultipleElements() { public void singleOrErrorError() { Observable.error(new RuntimeException("error")) .singleOrError() - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertErrorMessage("error") .assertError(RuntimeException.class); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java index b89d70b8df..176a69b106 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTest.java @@ -18,6 +18,7 @@ import static org.mockito.Mockito.*; import java.util.Arrays; +import java.util.concurrent.TimeUnit; import org.junit.*; import org.mockito.InOrder; @@ -27,6 +28,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableSkipLastTest { @@ -98,9 +100,9 @@ public void testSkipLastWithBackpressure() { Observable o = Observable.range(0, Flowable.bufferSize() * 2).skipLast(Flowable.bufferSize() + 10); TestObserver to = new TestObserver(); o.observeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals((Flowable.bufferSize()) - 10, to.valueCount()); + assertEquals((Flowable.bufferSize()) - 10, to.values().size()); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java index 50df641a26..2ec860d995 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipLastTimedTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSkipLastTimedTest { @@ -210,7 +211,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java index 9b1de8ab4e..6cc701c33f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.Arrays; @@ -22,7 +23,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; -import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class ObservableSkipTest { @@ -137,8 +138,10 @@ public void testSkipError() { @Test public void testRequestOverflowDoesNotOccur() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + Observable.range(1, 10).skip(5).subscribe(to); + to.assertTerminated(); to.assertComplete(); to.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTimedTest.java index 04d5078775..2ad53f7de5 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipTimedTest.java @@ -24,6 +24,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSkipTimedTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipUntilTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipUntilTest.java index 60525e7071..d5dbd3a51f 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipUntilTest.java @@ -20,6 +20,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSkipUntilTest { Observer observer; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java index d4772b1a6a..7e651dc90a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSkipWhileTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSkipWhileTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java index c80b81e2cd..e3c20e996e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSubscribeOnTest.java @@ -18,13 +18,14 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; -import io.reactivex.annotations.NonNull; import org.junit.*; import io.reactivex.*; +import io.reactivex.annotations.NonNull; import io.reactivex.disposables.*; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.*; public class ObservableSubscribeOnTest { @@ -74,7 +75,7 @@ public void subscribe( @Test @Ignore("ObservableSource.subscribe can't throw") public void testThrownErrorHandling() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.unsafeCreate(new ObservableSource() { @Override @@ -83,13 +84,13 @@ public void subscribe(Observer observer) { } }).subscribeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + to.awaitDone(1000, TimeUnit.MILLISECONDS); to.assertTerminated(); } @Test public void testOnError() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.unsafeCreate(new ObservableSource() { @Override @@ -99,7 +100,7 @@ public void subscribe(Observer observer) { } }).subscribeOn(Schedulers.computation()).subscribe(to); - to.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + to.awaitDone(1000, TimeUnit.MILLISECONDS); to.assertTerminated(); } @@ -178,7 +179,7 @@ public void subscribe(Observer sub) { }).subscribeOn(Schedulers.newThread()).take(10).subscribe(to); - to.awaitTerminalEvent(1000, TimeUnit.MILLISECONDS); + to.awaitDone(1000, TimeUnit.MILLISECONDS); to.dispose(); Thread.sleep(200); // give time for the loop to continue to.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); @@ -189,7 +190,7 @@ public void subscribe(Observer sub) { public void cancelBeforeActualSubscribe() { TestScheduler test = new TestScheduler(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just(1).hide() .subscribeOn(test).subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java index 610f49eac4..c7e36895e6 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableSwitchTest.java @@ -34,7 +34,8 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; -import io.reactivex.subjects.*; +import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableSwitchTest { @@ -462,11 +463,11 @@ public String apply(Long i) { .share() ; - TestObserver to = new TestObserver() { + TestObserverEx to = new TestObserverEx() { @Override public void onNext(String t) { super.onNext(t); - if (valueCount() == 250) { + if (values().size() == 250) { onComplete(); dispose(); } @@ -474,22 +475,22 @@ public void onNext(String t) { }; src.subscribe(to); - to.awaitTerminalEvent(10, TimeUnit.SECONDS); + to.awaitDone(10, TimeUnit.SECONDS); - System.out.println("> testIssue2654: " + to.valueCount()); + System.out.println("> testIssue2654: " + to.values().size()); to.assertTerminated(); to.assertNoErrors(); - Assert.assertEquals(250, to.valueCount()); + Assert.assertEquals(250, to.values().size()); } @Test public void delayErrors() { PublishSubject> source = PublishSubject.create(); - TestObserver to = source.switchMapDelayError(Functions.>identity()) - .test(); + TestObserverEx to = source.switchMapDelayError(Functions.>identity()) + .to(TestHelper.testConsumer()); to.assertNoValues() .assertNoErrors() @@ -617,7 +618,7 @@ public void switchMapInnerCancelled() { assertTrue(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); } @@ -839,7 +840,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -1171,7 +1172,7 @@ public Integer apply(Integer v) throws Exception { public void fusedBoundary() { String thread = Thread.currentThread().getName(); - Observable.range(1, 10000) + TestObserver to = Observable.range(1, 10000) .switchMap(new Function>() { @Override public ObservableSource apply(Integer v) @@ -1188,8 +1189,11 @@ public Object apply(Integer w) throws Exception { }) .test() .awaitDone(5, TimeUnit.SECONDS) - .assertNever(thread) .assertNoErrors() .assertComplete(); + + for (Object o : to.values()) { + assertNotEquals(thread, o); + } } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java index 7dc3a1cf39..7ff1c5903d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastOneTest.java @@ -22,13 +22,13 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; -import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class ObservableTakeLastOneTest { @Test public void testLastOfManyReturnsLast() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.range(1, 10).takeLast(1).subscribe(to); to.assertValue(10); to.assertNoErrors(); @@ -39,7 +39,7 @@ public void testLastOfManyReturnsLast() { @Test public void testLastOfEmptyReturnsEmpty() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.empty().takeLast(1).subscribe(to); to.assertNoValues(); to.assertNoErrors(); @@ -50,7 +50,7 @@ public void testLastOfEmptyReturnsEmpty() { @Test public void testLastOfOneReturnsLast() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just(1).takeLast(1).subscribe(to); to.assertValue(1); to.assertNoErrors(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java index 34ab87312b..3850a8bce3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTest.java @@ -17,6 +17,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import org.junit.*; @@ -27,6 +28,7 @@ import io.reactivex.functions.*; import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ObservableTakeLastTest { @@ -107,7 +109,7 @@ public void testBackpressure1() { Observable.range(1, 100000).takeLast(1) .observeOn(Schedulers.newThread()) .map(newSlowProcessor()).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); to.assertValue(100000); } @@ -117,9 +119,9 @@ public void testBackpressure2() { TestObserver to = new TestObserver(); Observable.range(1, 100000).takeLast(Flowable.bufferSize() * 4) .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Flowable.bufferSize() * 4, to.valueCount()); + assertEquals(Flowable.bufferSize() * 4, to.values().size()); } private Function newSlowProcessor() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java index bc933f9b02..4910938b4c 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeLastTimedTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableTakeLastTimedTest { @@ -244,7 +245,7 @@ public void observeOn() { .takeLast(1, TimeUnit.DAYS) .take(500) .observeOn(Schedulers.single(), true, 1) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) @@ -269,7 +270,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java index a9b9ae35d9..dd49d6cd56 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTest.java @@ -18,14 +18,14 @@ import static org.mockito.Mockito.*; import java.util.*; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.*; import java.util.concurrent.atomic.*; import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; @@ -34,6 +34,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableTakeTest { @@ -289,7 +290,7 @@ public void testTakeObserveOn() { INFINITE_OBSERVABLE .observeOn(Schedulers.newThread()).take(1).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); verify(o).onNext(1L); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTimedTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTimedTest.java index 4bf7fac17c..b69ed946b3 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTimedTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeTimedTest.java @@ -24,6 +24,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableTakeTimedTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java index 0e6f040972..7e62c831c4 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilPredicateTest.java @@ -25,9 +25,9 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; ; public class ObservableTakeUntilPredicateTest { @@ -141,7 +141,7 @@ public boolean test(Integer v) { @Test public void testErrorIncludesLastValueAsCause() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final TestException e = new TestException("Forced failure"); Predicate predicate = (new Predicate() { @Override diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java index 7ea5698be3..7bdf46da3a 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeUntilTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableTakeUntilTest { @@ -189,7 +190,7 @@ public void testUntilFires() { PublishSubject source = PublishSubject.create(); PublishSubject until = PublishSubject.create(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); source.takeUntil(until).subscribe(to); @@ -216,7 +217,7 @@ public void testMainCompletes() { PublishSubject source = PublishSubject.create(); PublishSubject until = PublishSubject.create(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); source.takeUntil(until).subscribe(to); @@ -241,7 +242,7 @@ public void testDownstreamUnsubscribes() { PublishSubject source = PublishSubject.create(); PublishSubject until = PublishSubject.create(); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); source.takeUntil(until).take(1).subscribe(to); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java index 6a92491a87..3719d9990d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTakeWhileTest.java @@ -14,9 +14,10 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -import org.junit.*; +import org.junit.Test; import io.reactivex.*; import io.reactivex.disposables.*; @@ -25,6 +26,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableTakeWhileTest { @@ -234,7 +236,7 @@ public boolean test(Integer t1) { @Test public void testErrorCauseIncludesLastValue() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just("abc").takeWhile(new Predicate() { @Override public boolean test(String t1) { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTest.java index c2a1176f41..9a204b0c79 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleFirstTest.java @@ -27,6 +27,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableThrottleFirstTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java index c456c226fc..e426af5752 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableThrottleLatestTest.java @@ -25,6 +25,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableThrottleLatestTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeIntervalTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeIntervalTest.java index 4542892ba6..fd056db231 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeIntervalTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeIntervalTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableTimeIntervalTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java index 935922b67c..4ebe008281 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutTests.java @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableTimeoutTests { private PublishSubject underlyingSubject; @@ -82,7 +83,7 @@ public void shouldNotTimeoutIfSecondOnNextWithinTimeout() { @Test public void shouldTimeoutIfOnNextNotWithinTimeout() { - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); withTimeout.subscribe(observer); @@ -92,7 +93,7 @@ public void shouldTimeoutIfOnNextNotWithinTimeout() { @Test public void shouldTimeoutIfSecondOnNextNotWithinTimeout() { - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); withTimeout.subscribe(observer); testScheduler.advanceTimeBy(2, TimeUnit.SECONDS); underlyingSubject.onNext("One"); @@ -231,7 +232,7 @@ public void shouldTimeoutIfSynchronizedObservableEmitFirstOnNextNotWithinTimeout final CountDownLatch exit = new CountDownLatch(1); final CountDownLatch timeoutSetuped = new CountDownLatch(1); - final TestObserver observer = new TestObserver(); + final TestObserverEx observer = new TestObserverEx(); new Thread(new Runnable() { @@ -280,7 +281,7 @@ public void subscribe(Observer observer) { TestScheduler testScheduler = new TestScheduler(); Observable observableWithTimeout = never.timeout(1000, TimeUnit.MILLISECONDS, testScheduler); - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); observableWithTimeout.subscribe(observer); testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS); @@ -517,7 +518,7 @@ public void onNextOnTimeoutRace() { final PublishSubject ps = PublishSubject.create(); - TestObserver to = ps.timeout(1, TimeUnit.SECONDS, sch).test(); + TestObserverEx to = ps.timeout(1, TimeUnit.SECONDS, sch).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -535,8 +536,8 @@ public void run() { TestHelper.race(r1, r2); - if (to.valueCount() != 0) { - if (to.errorCount() != 0) { + if (to.values().size() != 0) { + if (to.errors().size() != 0) { to.assertFailure(TimeoutException.class, 1); to.assertErrorMessage(timeoutMessage(1, TimeUnit.SECONDS)); } else { @@ -556,7 +557,7 @@ public void onNextOnTimeoutRaceFallback() { final PublishSubject ps = PublishSubject.create(); - TestObserver to = ps.timeout(1, TimeUnit.SECONDS, sch, Observable.just(2)).test(); + TestObserverEx to = ps.timeout(1, TimeUnit.SECONDS, sch, Observable.just(2)).to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -575,7 +576,7 @@ public void run() { TestHelper.race(r1, r2); if (to.isTerminated()) { - int c = to.valueCount(); + int c = to.values().size(); if (c == 1) { int v = to.values().get(0); assertTrue("" + v, v == 1 || v == 2); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java index 28b11adc4c..eaccef788e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimeoutWithSelectorTest.java @@ -26,8 +26,8 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; @@ -37,6 +37,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableTimeoutWithSelectorTest { @Test(timeout = 2000) @@ -431,7 +432,7 @@ public void badInnerSource() { try { PublishSubject ps = PublishSubject.create(); - TestObserver to = ps + TestObserverEx to = ps .timeout(Functions.justFunction(new Observable() { @Override protected void subscribeActual(Observer observer) { @@ -442,7 +443,7 @@ protected void subscribeActual(Observer observer) { observer.onComplete(); } })) - .test(); + .to(TestHelper.testConsumer()); ps.onNext(1); @@ -460,7 +461,7 @@ public void badInnerSourceOther() { try { PublishSubject ps = PublishSubject.create(); - TestObserver to = ps + TestObserverEx to = ps .timeout(Functions.justFunction(new Observable() { @Override protected void subscribeActual(Observer observer) { @@ -471,7 +472,7 @@ protected void subscribeActual(Observer observer) { observer.onComplete(); } }), Observable.just(2)) - .test(); + .to(TestHelper.testConsumer()); ps.onNext(1); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java index c8af9d88b8..e86f387305 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimerTest.java @@ -33,6 +33,7 @@ import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class ObservableTimerTest { @Mock @@ -334,7 +335,7 @@ public Long apply(Long v) throws Exception { Thread.sleep(500); - to.cancel(); + to.dispose(); Thread.sleep(500); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimestampTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimestampTest.java index aee372b109..4041ec9bfc 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableTimestampTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableTimestampTest.java @@ -25,6 +25,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableTimestampTest { Observer observer; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToFutureTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToFutureTest.java index 4cd7e26076..0a105af884 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToFutureTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToFutureTest.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class ObservableToFutureTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java index 51b3c79f57..81849a93d7 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToListTest.java @@ -27,6 +27,7 @@ import io.reactivex.Observer; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class ObservableToListTest { @@ -238,7 +239,7 @@ public Collection get() throws Exception { } }) .toObservable() - .test() + .to(TestHelper.>testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } @@ -267,7 +268,7 @@ public Collection get() throws Exception { return null; } }) - .test() + .to(TestHelper.>testConsumer()) .assertFailure(NullPointerException.class) .assertErrorMessage("The collectionSupplier returned a null collection. Null values are generally not allowed in 2.x operators and sources."); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java index 6577881604..f542c33ced 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMapTest.java @@ -24,6 +24,7 @@ import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class ObservableToMapTest { Observer objectObserver; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java index e495c488e7..c418aaf8e2 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToMultimapTest.java @@ -24,6 +24,7 @@ import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.functions.*; +import io.reactivex.testsupport.TestHelper; public class ObservableToMultimapTest { Observer objectObserver; diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java index 20ffdd236a..b6db0ad884 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableToSortedListTest.java @@ -25,6 +25,7 @@ import io.reactivex.*; import io.reactivex.Observable; import io.reactivex.Observer; +import io.reactivex.testsupport.TestHelper; public class ObservableToSortedListTest { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java index 2b7d7f4141..5b41207768 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableUnsubscribeOnTest.java @@ -19,16 +19,16 @@ import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import io.reactivex.annotations.NonNull; import org.junit.Test; import io.reactivex.*; +import io.reactivex.annotations.NonNull; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class ObservableUnsubscribeOnTest { @@ -53,13 +53,14 @@ public void subscribe(Observer t1) { } }); - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); + w.subscribeOn(uiEventLoop).observeOn(Schedulers.computation()) .unsubscribeOn(uiEventLoop) .take(2) .subscribe(observer); - observer.awaitTerminalEvent(5, TimeUnit.SECONDS); + observer.awaitDone(5, TimeUnit.SECONDS); Thread unsubscribeThread = subscription.getThread(); @@ -102,13 +103,14 @@ public void subscribe(Observer t1) { } }); - TestObserver observer = new TestObserver(); + TestObserverEx observer = new TestObserverEx(); + w.subscribeOn(Schedulers.newThread()).observeOn(Schedulers.computation()) .unsubscribeOn(uiEventLoop) .take(2) .subscribe(observer); - observer.awaitTerminalEvent(1, TimeUnit.SECONDS); + observer.awaitDone(1, TimeUnit.SECONDS); Thread unsubscribeThread = subscription.getThread(); diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java index 22d7c13731..815c143961 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableUsingTest.java @@ -21,8 +21,8 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; @@ -30,6 +30,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class ObservableUsingTest { @@ -452,7 +453,7 @@ public ObservableSource apply(Object v) throws Exception { @Test public void supplierDisposerCrash() { - TestObserver to = Observable.using(new Supplier() { + TestObserverEx to = Observable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -468,7 +469,7 @@ public void accept(Object e) throws Exception { throw new TestException("Second"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -479,7 +480,7 @@ public void accept(Object e) throws Exception { @Test public void eagerOnErrorDisposerCrash() { - TestObserver to = Observable.using(new Supplier() { + TestObserverEx to = Observable.using(new Supplier() { @Override public Object get() throws Exception { return 1; @@ -495,7 +496,7 @@ public void accept(Object e) throws Exception { throw new TestException("Second"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -522,7 +523,7 @@ public void accept(Object e) throws Exception { throw new TestException("Second"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Second"); } @@ -560,7 +561,7 @@ public void sourceSupplierReturnsNull() { Observable.using(Functions.justSupplier(1), Functions.justFunction((Observable)null), Functions.emptyConsumer()) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The sourceSupplier returned a null ObservableSource") ; } @@ -584,7 +585,7 @@ public void eagerDisposedOnComplete() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); - to.cancel(); + to.dispose(); observer.onComplete(); } }), Functions.emptyConsumer(), true) @@ -599,7 +600,7 @@ public void eagerDisposedOnError() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); - to.cancel(); + to.dispose(); observer.onError(new TestException()); } }), Functions.emptyConsumer(), true) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java index 8215add86b..81d2489b28 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithObservableTest.java @@ -23,8 +23,8 @@ import org.junit.Test; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; @@ -33,6 +33,7 @@ import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableWindowWithObservableTest { @@ -439,10 +440,10 @@ public void boundaryDispose2() { @Test public void boundaryOnError() { - TestObserver to = Observable.error(new TestException()) + TestObserverEx to = Observable.error(new TestException()) .window(Observable.never()) .flatMap(Functions.>identity(), true) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -673,7 +674,7 @@ public void mainAndBoundaryBothError() { try { final AtomicReference> ref = new AtomicReference>(); - TestObserver> to = Observable.error(new TestException("main")) + TestObserverEx> to = Observable.error(new TestException("main")) .window(new Observable() { @Override protected void subscribeActual(Observer observer) { @@ -681,7 +682,7 @@ protected void subscribeActual(Observer observer) { ref.set(observer); } }) - .test(); + .to(TestHelper.>testConsumer()); to .assertValueCount(1) @@ -707,7 +708,7 @@ public void mainCompleteBoundaryErrorRace() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestObserver> to = new Observable() { + TestObserverEx> to = new Observable() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); @@ -721,7 +722,7 @@ protected void subscribeActual(Observer observer) { ref.set(observer); } }) - .test(); + .to(TestHelper.>testConsumer()); Runnable r1 = new Runnable() { @Override @@ -800,7 +801,7 @@ public void takeOneAnotherBoundary() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestObserver> to = new Observable() { + TestObserverEx> to = new Observable() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); @@ -814,11 +815,11 @@ protected void subscribeActual(Observer observer) { ref.set(observer); } }) - .test(); + .to(TestHelper.>testConsumer()); to.assertValueCount(1) .assertNotTerminated() - .cancel(); + .dispose(); ref.get().onNext(1); @@ -866,7 +867,7 @@ public boolean isDisposed() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; Runnable r2 = new Runnable() { @@ -924,7 +925,7 @@ public boolean isDisposed() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; Runnable r2 = new Runnable() { @@ -981,7 +982,7 @@ public void supplierMainAndBoundaryBothError() { try { final AtomicReference> ref = new AtomicReference>(); - TestObserver> to = Observable.error(new TestException("main")) + TestObserverEx> to = Observable.error(new TestException("main")) .window(Functions.justSupplier(new Observable() { @Override protected void subscribeActual(Observer observer) { @@ -989,7 +990,7 @@ protected void subscribeActual(Observer observer) { ref.set(observer); } })) - .test(); + .to(TestHelper.>testConsumer()); to .assertValueCount(1) @@ -1015,7 +1016,7 @@ public void supplierMainCompleteBoundaryErrorRace() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestObserver> to = new Observable() { + TestObserverEx> to = new Observable() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); @@ -1029,7 +1030,7 @@ protected void subscribeActual(Observer observer) { ref.set(observer); } })) - .test(); + .to(TestHelper.>testConsumer()); Runnable r1 = new Runnable() { @Override @@ -1108,7 +1109,7 @@ public void supplierTakeOneAnotherBoundary() { final AtomicReference> refMain = new AtomicReference>(); final AtomicReference> ref = new AtomicReference>(); - TestObserver> to = new Observable() { + TestObserverEx> to = new Observable() { @Override protected void subscribeActual(Observer observer) { observer.onSubscribe(Disposables.empty()); @@ -1122,11 +1123,11 @@ protected void subscribeActual(Observer observer) { ref.set(observer); } })) - .test(); + .to(TestHelper.>testConsumer()); to.assertValueCount(1) .assertNotTerminated() - .cancel(); + .dispose(); ref.get().onNext(1); @@ -1174,7 +1175,7 @@ public boolean isDisposed() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; Runnable r2 = new Runnable() { @@ -1243,7 +1244,7 @@ public boolean isDisposed() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; Runnable r2 = new Runnable() { diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java index af1503e8a7..184da76ac9 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithSizeTest.java @@ -21,8 +21,8 @@ import org.junit.Test; -import io.reactivex.*; import io.reactivex.Observable; +import io.reactivex.ObservableSource; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; @@ -30,6 +30,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableWindowWithSizeTest { @@ -105,7 +106,8 @@ public void testSkipAndCountWindowsWithGaps() { @Test public void testWindowUnsubscribeNonOverlapping() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + final AtomicInteger count = new AtomicInteger(); Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer() { @@ -114,8 +116,10 @@ public void accept(Integer t1) { count.incrementAndGet(); } - }).window(5).take(2)).subscribe(to); - to.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + }).window(5).take(2)) + .subscribe(to); + + to.awaitDone(500, TimeUnit.MILLISECONDS); to.assertTerminated(); to.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // System.out.println(ts.getOnNextEvents()); @@ -124,7 +128,8 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeNonOverlappingAsyncSource() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + final AtomicInteger count = new AtomicInteger(); Observable.merge(Observable.range(1, 100000) .doOnNext(new Consumer() { @@ -146,7 +151,8 @@ public void accept(Integer t1) { .window(5) .take(2)) .subscribe(to); - to.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + + to.awaitDone(500, TimeUnit.MILLISECONDS); to.assertTerminated(); to.assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); // make sure we don't emit all values ... the unsubscribe should propagate @@ -155,7 +161,8 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeOverlapping() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + final AtomicInteger count = new AtomicInteger(); Observable.merge(Observable.range(1, 10000).doOnNext(new Consumer() { @@ -164,8 +171,10 @@ public void accept(Integer t1) { count.incrementAndGet(); } - }).window(5, 4).take(2)).subscribe(to); - to.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + }).window(5, 4).take(2)) + .subscribe(to); + + to.awaitDone(500, TimeUnit.MILLISECONDS); to.assertTerminated(); // System.out.println(ts.getOnNextEvents()); to.assertValues(1, 2, 3, 4, 5, 5, 6, 7, 8, 9); @@ -174,7 +183,8 @@ public void accept(Integer t1) { @Test public void testWindowUnsubscribeOverlappingAsyncSource() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + final AtomicInteger count = new AtomicInteger(); Observable.merge(Observable.range(1, 100000) .doOnNext(new Consumer() { @@ -189,7 +199,8 @@ public void accept(Integer t1) { .window(5, 4) .take(2), 128) .subscribe(to); - to.awaitTerminalEvent(500, TimeUnit.MILLISECONDS); + + to.awaitDone(500, TimeUnit.MILLISECONDS); to.assertTerminated(); to.assertValues(1, 2, 3, 4, 5, 5, 6, 7, 8, 9); // make sure we don't emit all values ... the unsubscribe should propagate @@ -244,7 +255,7 @@ public Observable apply(Observable w) { } }).subscribe(to); - to.awaitTerminalEvent(2, TimeUnit.SECONDS); + to.awaitDone(2, TimeUnit.SECONDS); to.assertComplete(); to.assertValueCount(22); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java index 1186667b98..0f431fa878 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithStartEndObservableTest.java @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableWindowWithStartEndObservableTest { @@ -448,7 +449,7 @@ public ObservableSource apply(Integer v) throws Exception { return observableDisposed(closeDisposed); } }) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .assertNoErrors() .assertNotComplete() diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java index 4eb90f4e50..6de2bed385 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWindowWithTimeTest.java @@ -31,6 +31,7 @@ import io.reactivex.observers.*; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class ObservableWindowWithTimeTest { @@ -217,9 +218,9 @@ public void accept(Integer pv) { }) .subscribe(to); - to.awaitTerminalEvent(5, TimeUnit.SECONDS); + to.awaitDone(5, TimeUnit.SECONDS); to.assertComplete(); - Assert.assertTrue(to.valueCount() != 0); + Assert.assertTrue(to.values().size() != 0); } @Test @@ -434,7 +435,7 @@ public void restartTimer() { public void exactBoundaryError() { Observable.error(new TestException()) .window(1, TimeUnit.DAYS, Schedulers.single(), 2, true) - .test() + .to(TestHelper.>testConsumer()) .assertSubscribed() .assertError(TestException.class) .assertNotComplete(); @@ -446,7 +447,7 @@ public void restartTimerMany() { .window(1, TimeUnit.MILLISECONDS, Schedulers.single(), 2, true) .flatMap(Functions.>identity()) .take(500) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500) diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java index 713772c535..e501865f0e 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableWithLatestFromTest.java @@ -14,6 +14,7 @@ package io.reactivex.internal.operators.observable; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.*; import java.util.*; @@ -21,7 +22,6 @@ import org.junit.*; import org.mockito.InOrder; -import io.reactivex.*; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.disposables.Disposables; @@ -32,6 +32,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class ObservableWithLatestFromTest { static final BiFunction COMBINER = new BiFunction() { @@ -89,7 +90,7 @@ public void testEmptySource() { Observable result = source.withLatestFrom(other, COMBINER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); result.subscribe(to); @@ -115,7 +116,7 @@ public void testEmptyOther() { Observable result = source.withLatestFrom(other, COMBINER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); result.subscribe(to); @@ -168,7 +169,7 @@ public void testSourceThrows() { Observable result = source.withLatestFrom(other, COMBINER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); result.subscribe(to); @@ -196,7 +197,7 @@ public void testOtherThrows() { Observable result = source.withLatestFrom(other, COMBINER); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); result.subscribe(to); @@ -224,7 +225,7 @@ public void testFunctionThrows() { Observable result = source.withLatestFrom(other, COMBINER_ERROR); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); result.subscribe(to); @@ -577,7 +578,7 @@ public Object apply(Object[] a) throws Exception { return a; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -612,7 +613,7 @@ public Object apply(Integer a, Integer b, Integer c) throws Exception { return a; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Second"); @@ -652,7 +653,7 @@ public Object apply(Object[] o) throws Exception { public void zeroOtherCombinerReturnsNull() { Observable.just(1) .withLatestFrom(new Observable[0], Functions.justFunction(null)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The combiner returned a null value"); } } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipCompletionTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipCompletionTest.java index 63949fdde1..931d37cf3d 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipCompletionTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipCompletionTest.java @@ -21,6 +21,7 @@ import io.reactivex.*; import io.reactivex.functions.BiFunction; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; /** * Systematically tests that when zipping an infinite and a finite Observable, diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java index 971359d8ad..8bd99ac574 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipIterableTest.java @@ -32,6 +32,7 @@ import io.reactivex.internal.util.CrashingIterable; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableZipIterableTest { BiFunction concat2Strings; @@ -397,7 +398,7 @@ public Object apply(Integer a, Integer b) throws Exception { return a + b; } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } diff --git a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java index ba86f16175..00ddb0ecea 100644 --- a/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java +++ b/src/test/java/io/reactivex/internal/operators/observable/ObservableZipTest.java @@ -34,6 +34,7 @@ import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableZipTest { BiFunction concat2Strings; @@ -797,10 +798,10 @@ public String apply(Integer a, Integer b) { TestObserver to = new TestObserver(); os.subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(5, to.valueCount()); + assertEquals(5, to.values().size()); assertEquals("1-1", to.values().get(0)); assertEquals("2-2", to.values().get(1)); assertEquals("5-5", to.values().get(4)); @@ -971,7 +972,7 @@ public Object apply(final Object[] args) { TestObserver to = new TestObserver(); o.subscribe(to); - to.awaitTerminalEvent(200, TimeUnit.MILLISECONDS); + to.awaitDone(200, TimeUnit.MILLISECONDS); to.assertNoValues(); } @@ -1013,9 +1014,9 @@ public String apply(Integer t1, Integer t2) { }).observeOn(Schedulers.computation()).take(Observable.bufferSize() * 2).subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertNoErrors(); - assertEquals(Observable.bufferSize() * 2, to.valueCount()); + assertEquals(Observable.bufferSize() * 2, to.values().size()); System.out.println("Generated => A: " + generatedA.get() + " B: " + generatedB.get()); assertTrue(generatedA.get() < (Observable.bufferSize() * 3)); assertTrue(generatedB.get() < (Observable.bufferSize() * 3)); @@ -1404,7 +1405,7 @@ public void eagerDispose() { @Override public void onNext(Integer t) { super.onNext(t); - cancel(); + dispose(); if (ps1.hasObservers()) { onError(new IllegalStateException("ps1 not disposed")); } else diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java index 18f4f3be65..bfa53119ff 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleAmbTest.java @@ -29,6 +29,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class SingleAmbTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleCacheTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleCacheTest.java index ce348eebeb..dfbcb39f3e 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleCacheTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleCacheTest.java @@ -19,6 +19,7 @@ import io.reactivex.disposables.Disposable; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class SingleCacheTest { @@ -50,7 +51,7 @@ public void addRemoveRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java index 09a29e55ff..a89f6cea03 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleConcatTest.java @@ -20,6 +20,8 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import io.reactivex.*; @@ -62,7 +64,7 @@ public void concatArray() { Arrays.fill(array, Single.just(1)); Single.concatArray(array) - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(i) .assertNoErrors() @@ -135,7 +137,7 @@ public void concatObservable() { Arrays.fill(array, Single.just(1)); Single.concat(Observable.fromArray(array)) - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(i) .assertNoErrors() diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleCreateTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleCreateTest.java index 2aee2b0f6f..9740a52613 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleCreateTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleCreateTest.java @@ -25,6 +25,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Cancellable; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SingleCreateTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java index 8f0967d8b8..306147313a 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDelayTest.java @@ -31,6 +31,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleDelayTest { @Test diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java index abfbe2151a..5dd6463780 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDematerializeTest.java @@ -20,6 +20,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; import io.reactivex.subjects.SingleSubject; +import io.reactivex.testsupport.TestHelper; public class SingleDematerializeTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDetachTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDetachTest.java index 0b5c5bb3fa..21cf14d838 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDetachTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDetachTest.java @@ -26,6 +26,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class SingleDetachTest { @@ -77,7 +78,7 @@ protected void subscribeActual(SingleObserver observer) { d = null; - to.cancel(); + to.dispose(); System.gc(); Thread.sleep(200); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterSuccessTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterSuccessTest.java index d0e3376307..ce4854e42e 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterSuccessTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterSuccessTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleDoAfterSuccessTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterTerminateTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterTerminateTest.java index b7566cce30..b9e64f41a7 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoAfterTerminateTest.java @@ -13,9 +13,7 @@ package io.reactivex.internal.operators.single; -import io.reactivex.Single; -import io.reactivex.SingleSource; -import io.reactivex.TestHelper; +import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; import io.reactivex.functions.Function; @@ -23,6 +21,8 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import java.util.List; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoFinallyTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoFinallyTest.java index 0e24a53a50..33482bac47 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoFinallyTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoFinallyTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleDoFinallyTest implements Action { @@ -82,7 +83,7 @@ public void run() throws Exception { }) .test() .assertResult(1) - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java index 425ee84205..0e83ac7327 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTerminateTest.java @@ -13,18 +13,17 @@ package io.reactivex.internal.operators.single; -import io.reactivex.Single; -import io.reactivex.TestHelper; -import io.reactivex.exceptions.CompositeException; -import io.reactivex.exceptions.TestException; -import io.reactivex.functions.Action; -import io.reactivex.observers.TestObserver; -import org.junit.Test; +import static org.junit.Assert.assertTrue; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import static org.junit.Assert.assertTrue; +import org.junit.Test; + +import io.reactivex.Single; +import io.reactivex.exceptions.*; +import io.reactivex.functions.Action; +import io.reactivex.testsupport.*; public class SingleDoOnTerminateTest { @@ -78,13 +77,13 @@ public void run() throws Exception { @Test public void doOnTerminateErrorCrash() { - TestObserver to = Single.error(new TestException("Outer")).doOnTerminate(new Action() { + TestObserverEx to = Single.error(new TestException("Outer")).doOnTerminate(new Action() { @Override public void run() { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java index ff524df77a..5a4e70c3bc 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleDoOnTest.java @@ -24,9 +24,9 @@ import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.*; public class SingleDoOnTest { @@ -144,7 +144,7 @@ public void accept(Disposable d) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Inner"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Outer"); @@ -173,14 +173,14 @@ public void accept(Throwable v) throws Exception { @Test public void onErrorCrashes() { - TestObserver to = Single.error(new TestException("Outer")) + TestObserverEx to = Single.error(new TestException("Outer")) .doOnError(new Consumer() { @Override public void accept(Throwable v) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -204,14 +204,14 @@ public void accept(Integer v, Throwable e) throws Exception { @Test public void doOnEventThrowsError() { - TestObserver to = Single.error(new TestException("Main")) + TestObserverEx to = Single.error(new TestException("Main")) .doOnEvent(new BiConsumer() { @Override public void accept(Integer v, Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -290,7 +290,7 @@ public void run() throws Exception { } }) .test() - .cancel(); + .dispose(); TestHelper.assertUndeliverable(errors, 0, TestException.class); } finally { @@ -348,7 +348,7 @@ public void accept(Disposable d) throws Exception { throw new TestException("First"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(bs.isDisposed()); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleEqualsTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleEqualsTest.java index 796e9621ea..18ba3850b3 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleEqualsTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleEqualsTest.java @@ -20,6 +20,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SingleEqualsTest { @@ -28,7 +29,7 @@ public void bothError() { List errors = TestHelper.trackPluginErrors(); try { Single.equals(Single.error(new TestException("One")), Single.error(new TestException("Two"))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "One"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Two"); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapCompletableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapCompletableTest.java index 46d1de6e3e..65048d231f 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapCompletableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapCompletableTest.java @@ -17,6 +17,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class SingleFlatMapCompletableTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java index 1839772b67..1fc2b3b56d 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableFlowableTest.java @@ -28,7 +28,8 @@ import io.reactivex.internal.util.CrashingIterable; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class SingleFlatMapIterableFlowableTest { @@ -108,7 +109,7 @@ public Iterable apply(Integer v) throws Exception { @Test public void fused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Single.just(1).flattenAsFlowable(new Function>() { @Override @@ -118,15 +119,15 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2); ; } @Test public void fusedNoSync() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); Single.just(1).flattenAsFlowable(new Function>() { @Override @@ -136,8 +137,8 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(ts); - ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.NONE)) + ts.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2); ; } @@ -151,7 +152,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(1, 100, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -164,7 +165,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 1, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -177,7 +178,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -190,7 +191,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -207,7 +208,7 @@ public Iterable apply(Object v) throws Exception { }) .hide() .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -227,7 +228,7 @@ public Iterable apply(Object v) throws Exception { } }) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -248,7 +249,7 @@ public Iterable apply(Object v) throws Exception { }) .take(500 * 1000) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) @@ -269,7 +270,7 @@ public Iterable apply(Object v) throws Exception { }) .observeOn(Schedulers.single()) .take(500 * 1000) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) @@ -325,7 +326,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -338,7 +339,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -351,7 +352,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test(2L) + .to(TestHelper.testSubscriber(2L)) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -364,7 +365,7 @@ public Iterable apply(Object v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test(2L) + .to(TestHelper.testSubscriber(2L)) .assertFailureAndMessage(TestException.class, "next()"); } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservableTest.java index 8ae89d62d0..f58f266359 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapIterableObservableTest.java @@ -27,8 +27,8 @@ import io.reactivex.functions.Function; import io.reactivex.internal.fuseable.*; import io.reactivex.internal.util.CrashingIterable; -import io.reactivex.observers.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class SingleFlatMapIterableObservableTest { @@ -86,7 +86,7 @@ public Iterable apply(Integer v) throws Exception { @Test public void fused() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); Single.just(1).flattenAsObservable(new Function>() { @Override @@ -96,15 +96,15 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2); ; } @Test public void fusedNoSync() { - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); Single.just(1).flattenAsObservable(new Function>() { @Override @@ -114,8 +114,8 @@ public Iterable apply(Integer v) throws Exception { }) .subscribe(to); - to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertResult(1, 2); ; } @@ -129,7 +129,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(1, 100, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -142,7 +142,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 1, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -155,7 +155,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 100, 1); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -168,7 +168,7 @@ public Iterable apply(Integer v) throws Exception { return new CrashingIterable(100, 2, 100); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()", 0); } @@ -210,7 +210,7 @@ public Iterable apply(Object v) throws Exception { }) .hide() .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -230,7 +230,7 @@ public Iterable apply(Object v) throws Exception { } }) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(1000 * 1000) @@ -251,7 +251,7 @@ public Iterable apply(Object v) throws Exception { }) .take(500 * 1000) .observeOn(Schedulers.single()) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) @@ -272,7 +272,7 @@ public Iterable apply(Object v) throws Exception { }) .observeOn(Schedulers.single()) .take(500 * 1000) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() .assertValueCount(500 * 1000) diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapMaybeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapMaybeTest.java index 0dca75c5ab..a03c5bde03 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapMaybeTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapMaybeTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class SingleFlatMapMaybeTest { @Test(expected = NullPointerException.class) @@ -63,7 +64,7 @@ public void flatMapMaybeValueNull() { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(NullPointerException.class) .assertErrorMessage("The mapper returned a null MaybeSource"); @@ -76,7 +77,7 @@ public void flatMapMaybeValueErrorThrown() { throw new RuntimeException("something went terribly wrong!"); } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("something went terribly wrong!"); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java index ca586a0907..02492e007d 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFlatMapTest.java @@ -23,7 +23,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class SingleFlatMapTest { @@ -167,7 +167,7 @@ public Publisher apply(Integer v) throws Exception { @Test public void flatMapPublisherCancelDuringSingle() { final AtomicBoolean disposed = new AtomicBoolean(); - TestSubscriber ts = Single.never() + TestSubscriberEx ts = Single.never() .doOnDispose(new Action() { @Override public void run() throws Exception { @@ -180,7 +180,7 @@ public Publisher apply(Integer v) throws Exception { return Flowable.range(v, 5); } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertNotTerminated(); assertFalse(disposed.get()); @@ -192,7 +192,7 @@ public Publisher apply(Integer v) throws Exception { @Test public void flatMapPublisherCancelDuringFlowable() { final AtomicBoolean disposed = new AtomicBoolean(); - TestSubscriber ts = + TestSubscriberEx ts = Single.just(1) .flatMapPublisher(new Function>() { @Override @@ -206,7 +206,7 @@ public void run() throws Exception { }); } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertNotTerminated(); assertFalse(disposed.get()); @@ -258,7 +258,7 @@ public void flatMapValueNull() { return null; } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(NullPointerException.class) .assertErrorMessage("The single returned by the mapper is null"); @@ -271,7 +271,7 @@ public void flatMapValueErrorThrown() { throw new RuntimeException("something went terribly wrong!"); } }) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("something went terribly wrong!"); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java index 2c4ebcc321..41b9ce523e 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFromCallableTest.java @@ -13,14 +13,13 @@ package io.reactivex.internal.operators.single; -import io.reactivex.Observer; -import io.reactivex.Single; -import io.reactivex.SingleObserver; -import io.reactivex.TestHelper; +import io.reactivex.*; import io.reactivex.disposables.Disposable; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -67,8 +66,8 @@ public void fromCallableNull() { return null; } }) - .test() - .assertFailureAndMessage(NullPointerException.class, "The callable returned a null value"); + .to(TestHelper.testConsumer()) + .assertFailureAndMessage(NullPointerException.class, "The callable returned a null value"); } @Test @@ -129,7 +128,7 @@ public Integer call() throws Exception { assertTrue(cdl1.await(5, TimeUnit.SECONDS)); - to.cancel(); + to.dispose(); int timeout = 10; @@ -183,7 +182,7 @@ public String answer(InvocationOnMock invocation) throws Throwable { observerLatch.await(); // Unsubscribing before emission - outer.cancel(); + outer.dispose(); // Emitting result funcLatch.countDown(); @@ -239,7 +238,7 @@ public void disposedOnCall() { Single.fromCallable(new Callable() { @Override public Integer call() throws Exception { - to.cancel(); + to.dispose(); return 1; } }) diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleFromPublisherTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleFromPublisherTest.java index b7231738a6..531b37a7d7 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleFromPublisherTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleFromPublisherTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class SingleFromPublisherTest { @@ -67,7 +68,7 @@ public void dispose() { pp.onNext(1); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleHideTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleHideTest.java index b0510c7456..5b5305dec5 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleHideTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleHideTest.java @@ -19,6 +19,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleHideTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java index 0a6d5473f7..0a815f6521 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleInternalHelperTest.java @@ -20,6 +20,7 @@ import org.junit.Test; import io.reactivex.*; +import io.reactivex.testsupport.TestHelper; public class SingleInternalHelperTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMapTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMapTest.java index 2abc315e95..aec6579b90 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleMapTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMapTest.java @@ -18,6 +18,7 @@ import io.reactivex.Single; import io.reactivex.SingleSource; import io.reactivex.functions.Function; +import io.reactivex.testsupport.TestHelper; public class SingleMapTest { @@ -50,7 +51,7 @@ public SingleSource apply(final Integer integer) throws Exception { return null; } }) - .test() + .to(TestHelper.>testConsumer()) .assertNoValues() .assertError(NullPointerException.class) .assertErrorMessage("The mapper function returned a null value."); @@ -64,7 +65,7 @@ public SingleSource apply(final Integer integer) throws Exception { throw new RuntimeException("something went terribly wrong!"); } }) - .test() + .to(TestHelper.>testConsumer()) .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("something went terribly wrong!"); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java index 3a97155978..77b6c6491e 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMaterializeTest.java @@ -19,6 +19,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.subjects.SingleSubject; +import io.reactivex.testsupport.TestHelper; public class SingleMaterializeTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java index ef5f6de826..ac4b163db2 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleMergeTest.java @@ -22,6 +22,7 @@ import io.reactivex.*; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SingleMergeTest { @@ -62,7 +63,7 @@ public void mergeErrors() { Single source2 = Single.error(new TestException("Second")); Single.merge(source1, source2) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "First"); assertTrue(errors.toString(), errors.isEmpty()); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleObserveOnTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleObserveOnTest.java index a24e45d315..cf992ab55a 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleObserveOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleObserveOnTest.java @@ -21,6 +21,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Function; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class SingleObserveOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleOnErrorXTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleOnErrorXTest.java index 425e6ce730..aa5a4a03ea 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleOnErrorXTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleOnErrorXTest.java @@ -20,7 +20,7 @@ import io.reactivex.*; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; -import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class SingleOnErrorXTest { @@ -34,14 +34,14 @@ public void returnSuccess() { @Test public void resumeThrows() { - TestObserver to = Single.error(new TestException("Outer")) + TestObserverEx to = Single.error(new TestException("Outer")) .onErrorReturn(new Function() { @Override public Integer apply(Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List errors = TestHelper.compositeList(to.errors().get(0)); @@ -54,7 +54,7 @@ public Integer apply(Throwable e) throws Exception { public void resumeErrors() { Single.error(new TestException("Main")) .onErrorResumeNext(Single.error(new TestException("Resume"))) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Resume"); } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleSubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleSubscribeOnTest.java index 6f8b247056..5d0cac8f46 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleSubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleSubscribeOnTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.*; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleSubscribeOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java index c7a1180a30..b8feebe7d0 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleTakeUntilTest.java @@ -28,6 +28,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class SingleTakeUntilTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java index 0acbc7a9ef..31ea633d04 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleTimeoutTest.java @@ -29,6 +29,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.*; +import io.reactivex.testsupport.TestHelper; public class SingleTimeoutTest { @@ -111,7 +112,7 @@ public void fallbackDispose() { assertFalse(subj.hasObservers()); assertTrue(fallback.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(fallback.hasObservers()); } @@ -217,7 +218,7 @@ public void mainTimedOut() { Single .never() .timeout(1, TimeUnit.NANOSECONDS) - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertFailureAndMessage(TimeoutException.class, timeoutMessage(1, TimeUnit.NANOSECONDS)); } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleTimerTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleTimerTest.java index 55932efb37..ddb175ff2b 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleTimerTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleTimerTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Function; import io.reactivex.observers.TestObserver; import io.reactivex.schedulers.*; +import io.reactivex.testsupport.TestHelper; public class SingleTimerTest { @@ -54,7 +55,7 @@ public Long apply(Long v) throws Exception { Thread.sleep(500); - to.cancel(); + to.dispose(); Thread.sleep(500); diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleToFlowableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleToFlowableTest.java index 3b6766e8a8..e5122da657 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleToFlowableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleToFlowableTest.java @@ -14,9 +14,10 @@ package io.reactivex.internal.operators.single; import io.reactivex.Single; -import io.reactivex.TestHelper; import io.reactivex.functions.Function; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import org.reactivestreams.Publisher; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleToObservableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleToObservableTest.java index d78f8ca9d3..516d0e5861 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleToObservableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleToObservableTest.java @@ -18,6 +18,7 @@ import io.reactivex.*; import io.reactivex.functions.Function; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleToObservableTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleUnsubscribeOnTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleUnsubscribeOnTest.java index 5bcf01f1f6..9411a6990b 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleUnsubscribeOnTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleUnsubscribeOnTest.java @@ -25,6 +25,7 @@ import io.reactivex.functions.*; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class SingleUnsubscribeOnTest { diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleUsingTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleUsingTest.java index 563da379df..e3c994ad33 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleUsingTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleUsingTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.*; public class SingleUsingTest { @@ -100,8 +101,8 @@ public void errorNonEager() { @Test public void eagerMapperThrowsDisposerThrows() { - TestObserver to = Single.using(Functions.justSupplier(Disposables.empty()), mapperThrows, disposerThrows) - .test() + TestObserverEx to = Single.using(Functions.justSupplier(Disposables.empty()), mapperThrows, disposerThrows) + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List ce = TestHelper.compositeList(to.errors().get(0)); @@ -116,7 +117,7 @@ public void noneagerMapperThrowsDisposerThrows() { try { Single.using(Functions.justSupplier(Disposables.empty()), mapperThrows, disposerThrows, false) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "Mapper"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Disposer"); @@ -181,14 +182,14 @@ public void disposerThrowsNonEager() { @Test public void errorAndDisposerThrowsEager() { - TestObserver to = Single.using(Functions.justSupplier(Disposables.empty()), + TestObserverEx to = Single.using(Functions.justSupplier(Disposables.empty()), new Function>() { @Override public SingleSource apply(Disposable v) throws Exception { return Single.error(new TestException("Mapper-run")); } }, disposerThrows) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List ce = TestHelper.compositeList(to.errors().get(0)); @@ -242,7 +243,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -317,7 +318,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java index 7d1175bfc2..78f15159dd 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleZipArrayTest.java @@ -26,6 +26,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class SingleZipArrayTest { @@ -66,7 +67,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -192,7 +193,7 @@ public Object apply(Object[] a) throws Exception { @Test public void singleSourceZipperReturnsNull() { Single.zipArray(Functions.justFunction(null), Single.just(1)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The zipper returned a null value"); } } diff --git a/src/test/java/io/reactivex/internal/operators/single/SingleZipIterableTest.java b/src/test/java/io/reactivex/internal/operators/single/SingleZipIterableTest.java index f5ba4954a0..9de30ec530 100644 --- a/src/test/java/io/reactivex/internal/operators/single/SingleZipIterableTest.java +++ b/src/test/java/io/reactivex/internal/operators/single/SingleZipIterableTest.java @@ -27,6 +27,7 @@ import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; public class SingleZipIterableTest { @@ -63,7 +64,7 @@ public void dispose() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -161,7 +162,7 @@ public Single apply(Integer v) throws Exception { return Single.just(v); } }), addString) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "iterator()"); } @@ -173,7 +174,7 @@ public Single apply(Integer v) throws Exception { return Single.just(v); } }), addString) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "hasNext()"); } @@ -185,7 +186,7 @@ public Single apply(Integer v) throws Exception { return Single.just(v); } }), addString) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(TestException.class, "next()"); } @@ -241,7 +242,7 @@ public Object apply(Object[] a) throws Exception { @Test public void singleSourceZipperReturnsNull() { Single.zip(Arrays.asList(Single.just(1)), Functions.justFunction(null)) - .test() + .to(TestHelper.testConsumer()) .assertFailureAndMessage(NullPointerException.class, "The zipper returned a null value"); } } diff --git a/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java b/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java index 17a69ab93d..6af5b6df28 100644 --- a/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/AbstractDirectTaskTest.java @@ -19,8 +19,8 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.functions.Functions; +import io.reactivex.testsupport.TestHelper; public class AbstractDirectTaskTest { diff --git a/src/test/java/io/reactivex/internal/schedulers/InstantPeriodicTaskTest.java b/src/test/java/io/reactivex/internal/schedulers/InstantPeriodicTaskTest.java index 286be4e33a..2b8d6ca0d4 100644 --- a/src/test/java/io/reactivex/internal/schedulers/InstantPeriodicTaskTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/InstantPeriodicTaskTest.java @@ -23,10 +23,10 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class InstantPeriodicTaskTest { diff --git a/src/test/java/io/reactivex/internal/schedulers/ScheduledDirectPeriodicTaskTest.java b/src/test/java/io/reactivex/internal/schedulers/ScheduledDirectPeriodicTaskTest.java index cbdc2b7959..b5ee68cbc5 100644 --- a/src/test/java/io/reactivex/internal/schedulers/ScheduledDirectPeriodicTaskTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/ScheduledDirectPeriodicTaskTest.java @@ -17,9 +17,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ScheduledDirectPeriodicTaskTest { diff --git a/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java b/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java index 9d1718f7d0..6e3f8e554d 100644 --- a/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/ScheduledRunnableTest.java @@ -22,11 +22,11 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.exceptions.TestException; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ScheduledRunnableTest { diff --git a/src/test/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupportTest.java b/src/test/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupportTest.java index 23980da892..a54e9bdf31 100644 --- a/src/test/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupportTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/SchedulerMultiWorkerSupportTest.java @@ -21,10 +21,10 @@ import org.junit.Test; import io.reactivex.Scheduler.Worker; -import io.reactivex.TestHelper; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.internal.schedulers.SchedulerMultiWorkerSupport.WorkerCallback; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class SchedulerMultiWorkerSupportTest { diff --git a/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java b/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java index 603929ddb4..9f7ee75022 100644 --- a/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/SchedulerPoolFactoryTest.java @@ -22,9 +22,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.schedulers.SchedulerPoolFactory.PurgeProperties; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class SchedulerPoolFactoryTest { diff --git a/src/test/java/io/reactivex/internal/schedulers/SchedulerWhenTest.java b/src/test/java/io/reactivex/internal/schedulers/SchedulerWhenTest.java index 380ea91f0a..d5cf6506fb 100644 --- a/src/test/java/io/reactivex/internal/schedulers/SchedulerWhenTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/SchedulerWhenTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.*; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class SchedulerWhenTest { @Test diff --git a/src/test/java/io/reactivex/internal/schedulers/SingleSchedulerTest.java b/src/test/java/io/reactivex/internal/schedulers/SingleSchedulerTest.java index e7b79d21bd..5eb8dbcfad 100644 --- a/src/test/java/io/reactivex/internal/schedulers/SingleSchedulerTest.java +++ b/src/test/java/io/reactivex/internal/schedulers/SingleSchedulerTest.java @@ -26,6 +26,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.schedulers.SingleScheduler.ScheduledWorker; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class SingleSchedulerTest extends AbstractSchedulerTests { diff --git a/src/test/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriberTest.java index f3c98110b4..c8cc7cc40a 100644 --- a/src/test/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/BasicFuseableConditionalSubscriberTest.java @@ -19,9 +19,9 @@ import org.junit.Test; import org.reactivestreams.Subscription; -import io.reactivex.TestHelper; import io.reactivex.internal.fuseable.ConditionalSubscriber; import io.reactivex.internal.subscriptions.ScalarSubscription; +import io.reactivex.testsupport.TestHelper; public class BasicFuseableConditionalSubscriberTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/BasicFuseableSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/BasicFuseableSubscriberTest.java index fb241bbb67..ae0f402b3c 100644 --- a/src/test/java/io/reactivex/internal/subscribers/BasicFuseableSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/BasicFuseableSubscriberTest.java @@ -18,9 +18,9 @@ import io.reactivex.annotations.Nullable; import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.subscriptions.ScalarSubscription; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class BasicFuseableSubscriberTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java index 3d6017bad4..e407a18a1e 100644 --- a/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/BlockingSubscriberTest.java @@ -21,8 +21,8 @@ import org.junit.Test; import org.reactivestreams.Subscription; -import io.reactivex.TestHelper; import io.reactivex.internal.subscriptions.BooleanSubscription; +import io.reactivex.testsupport.TestHelper; public class BlockingSubscriberTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java index 17e12986b4..db54a05bae 100644 --- a/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/BoundedSubscriberTest.java @@ -14,7 +14,6 @@ package io.reactivex.internal.subscribers; import io.reactivex.Flowable; -import io.reactivex.TestHelper; import io.reactivex.exceptions.CompositeException; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Action; @@ -23,6 +22,8 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; diff --git a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java index 726828bbd7..013be4bf83 100644 --- a/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/DeferredScalarSubscriberTest.java @@ -33,6 +33,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class DeferredScalarSubscriberTest { @@ -331,7 +332,7 @@ public void run() { ds.onComplete(); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValues(1); ts.assertNoErrors(); ts.assertComplete(); @@ -385,7 +386,7 @@ public void run() { ds.onComplete(); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValues(1); ts.assertNoErrors(); ts.assertComplete(); diff --git a/src/test/java/io/reactivex/internal/subscribers/EmptyComponentTest.java b/src/test/java/io/reactivex/internal/subscribers/EmptyComponentTest.java index 750b09663d..f14f9706ce 100644 --- a/src/test/java/io/reactivex/internal/subscribers/EmptyComponentTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/EmptyComponentTest.java @@ -19,12 +19,12 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.internal.util.EmptyComponent; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class EmptyComponentTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java index 2aa9ec7a25..6f9f9a9436 100644 --- a/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/FutureSubscriberTest.java @@ -21,12 +21,12 @@ import org.junit.*; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscribers.FutureSubscriber; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class FutureSubscriberTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java index f8090a27a9..5e25125950 100644 --- a/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/LambdaSubscriberTest.java @@ -21,6 +21,8 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import org.reactivestreams.*; diff --git a/src/test/java/io/reactivex/internal/subscribers/QueueDrainSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/QueueDrainSubscriberTest.java index d0360d6cd9..bb2b7e46a4 100644 --- a/src/test/java/io/reactivex/internal/subscribers/QueueDrainSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/QueueDrainSubscriberTest.java @@ -20,13 +20,13 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.MissingBackpressureException; import io.reactivex.internal.queue.SpscArrayQueue; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class QueueDrainSubscriberTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriberTest.java index 825e08d4fe..d09e4d7f5a 100644 --- a/src/test/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/SinglePostCompleteSubscriberTest.java @@ -15,9 +15,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class SinglePostCompleteSubscriberTest { diff --git a/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java b/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java index f8a3ccdb21..07ca7ef9b2 100644 --- a/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/StrictSubscriberTest.java @@ -23,7 +23,7 @@ import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; public class StrictSubscriberTest { @@ -65,9 +65,9 @@ protected void subscribeActual(Subscriber s) { } static final class SubscriberWrapper implements Subscriber { - final TestSubscriber tester; + final TestSubscriberEx tester; - SubscriberWrapper(TestSubscriber tester) { + SubscriberWrapper(TestSubscriberEx tester) { this.tester = tester; } @@ -94,7 +94,7 @@ public void onComplete() { @Test public void normalOnNext() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); SubscriberWrapper wrapper = new SubscriberWrapper(ts); Flowable.range(1, 5).subscribe(wrapper); @@ -104,7 +104,7 @@ public void normalOnNext() { @Test public void normalOnNextBackpressured() { - TestSubscriber ts = new TestSubscriber(0); + TestSubscriberEx ts = new TestSubscriberEx(0); SubscriberWrapper wrapper = new SubscriberWrapper(ts); Flowable.range(1, 5).subscribe(wrapper); @@ -120,7 +120,7 @@ public void normalOnNextBackpressured() { @Test public void normalOnError() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); SubscriberWrapper wrapper = new SubscriberWrapper(ts); Flowable.range(1, 5).concatWith(Flowable.error(new TestException())) @@ -311,7 +311,7 @@ protected void subscribeActual(Subscriber s) { @Test public void doubleOnSubscribe() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); SubscriberWrapper wrapper = new SubscriberWrapper(ts); new Flowable() { diff --git a/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java b/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java index 6841d5bffd..879517fbde 100644 --- a/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java +++ b/src/test/java/io/reactivex/internal/subscribers/SubscriberResourceWrapperTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class SubscriberResourceWrapperTest { diff --git a/src/test/java/io/reactivex/internal/subscriptions/ArrayCompositeSubscriptionTest.java b/src/test/java/io/reactivex/internal/subscriptions/ArrayCompositeSubscriptionTest.java index 6861f9cb0e..44d2bf06fa 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/ArrayCompositeSubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/ArrayCompositeSubscriptionTest.java @@ -17,7 +17,7 @@ import org.junit.Test; -import io.reactivex.TestHelper; +import io.reactivex.testsupport.TestHelper; public class ArrayCompositeSubscriptionTest { diff --git a/src/test/java/io/reactivex/internal/subscriptions/DeferredScalarSubscriptionTest.java b/src/test/java/io/reactivex/internal/subscriptions/DeferredScalarSubscriptionTest.java index 430e3c71c5..1aa7cb6ef0 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/DeferredScalarSubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/DeferredScalarSubscriptionTest.java @@ -17,9 +17,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class DeferredScalarSubscriptionTest { @@ -99,7 +99,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.valueCount() >= 1) { + if (ts.values().size() >= 1) { ts.assertValue(1); } } @@ -130,7 +130,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.valueCount() >= 1) { + if (ts.values().size() >= 1) { ts.assertValue(1); } } diff --git a/src/test/java/io/reactivex/internal/subscriptions/QueueSubscriptionTest.java b/src/test/java/io/reactivex/internal/subscriptions/QueueSubscriptionTest.java index a098b99d44..b99f29605a 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/QueueSubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/QueueSubscriptionTest.java @@ -14,10 +14,11 @@ package io.reactivex.internal.subscriptions; import io.reactivex.annotations.Nullable; +import io.reactivex.testsupport.TestHelper; + import org.junit.Test; import static org.junit.Assert.*; -import io.reactivex.TestHelper; public class QueueSubscriptionTest { static final class EmptyQS extends BasicQueueSubscription { diff --git a/src/test/java/io/reactivex/internal/subscriptions/ScalarSubscriptionTest.java b/src/test/java/io/reactivex/internal/subscriptions/ScalarSubscriptionTest.java index 5bf909ce34..8ca273f0a1 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/ScalarSubscriptionTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/ScalarSubscriptionTest.java @@ -17,9 +17,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class ScalarSubscriptionTest { diff --git a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java index 426d1779e1..8e1a08830c 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionArbiterTest.java @@ -19,8 +19,8 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SubscriptionArbiterTest { diff --git a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java index dd010ca100..0750605baa 100644 --- a/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java +++ b/src/test/java/io/reactivex/internal/subscriptions/SubscriptionHelperTest.java @@ -21,9 +21,9 @@ import org.junit.Test; import org.reactivestreams.Subscription; -import io.reactivex.TestHelper; import io.reactivex.exceptions.ProtocolViolationException; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SubscriptionHelperTest { diff --git a/src/test/java/io/reactivex/internal/util/BackpressureHelperTest.java b/src/test/java/io/reactivex/internal/util/BackpressureHelperTest.java index fbcff0ab95..435dcf30c4 100644 --- a/src/test/java/io/reactivex/internal/util/BackpressureHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/BackpressureHelperTest.java @@ -22,8 +22,8 @@ import org.junit.*; -import io.reactivex.TestHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class BackpressureHelperTest { @Ignore("BackpressureHelper is an enum") diff --git a/src/test/java/io/reactivex/internal/util/BlockingHelperTest.java b/src/test/java/io/reactivex/internal/util/BlockingHelperTest.java index ad19fe8a1c..c03505c35b 100644 --- a/src/test/java/io/reactivex/internal/util/BlockingHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/BlockingHelperTest.java @@ -19,9 +19,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class BlockingHelperTest { diff --git a/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java b/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java index 13a672f566..fb7f0107f8 100644 --- a/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/EndConsumerHelperTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class EndConsumerHelperTest { diff --git a/src/test/java/io/reactivex/internal/util/ExceptionHelperTest.java b/src/test/java/io/reactivex/internal/util/ExceptionHelperTest.java index de401c0df7..6dccb955dc 100644 --- a/src/test/java/io/reactivex/internal/util/ExceptionHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/ExceptionHelperTest.java @@ -19,8 +19,8 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; +import io.reactivex.testsupport.TestHelper; public class ExceptionHelperTest { @Test diff --git a/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java b/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java index dcf4981856..b200a461eb 100644 --- a/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java +++ b/src/test/java/io/reactivex/internal/util/HalfSerializerObserverTest.java @@ -19,10 +19,11 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class HalfSerializerObserverTest { @@ -228,7 +229,7 @@ public void run() { to.assertComplete().assertNoErrors(); - assertTrue(to.valueCount() <= 1); + assertTrue(to.values().size() <= 1); } } @@ -239,7 +240,7 @@ public void onErrorOnCompleteRace() { final AtomicInteger wip = new AtomicInteger(); final AtomicThrowable error = new AtomicThrowable(); - final TestObserver to = new TestObserver(); + final TestObserverEx to = new TestObserverEx(); to.onSubscribe(Disposables.empty()); diff --git a/src/test/java/io/reactivex/internal/util/HalfSerializerSubscriberTest.java b/src/test/java/io/reactivex/internal/util/HalfSerializerSubscriberTest.java index 4cfbf4bb91..966db81692 100644 --- a/src/test/java/io/reactivex/internal/util/HalfSerializerSubscriberTest.java +++ b/src/test/java/io/reactivex/internal/util/HalfSerializerSubscriberTest.java @@ -20,10 +20,11 @@ import org.junit.Test; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.FlowableSubscriber; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class HalfSerializerSubscriberTest { @@ -234,7 +235,7 @@ public void run() { ts.assertComplete().assertNoErrors(); - assertTrue(ts.valueCount() <= 1); + assertTrue(ts.values().size() <= 1); } } @@ -245,7 +246,7 @@ public void onErrorOnCompleteRace() { final AtomicInteger wip = new AtomicInteger(); final AtomicThrowable error = new AtomicThrowable(); - final TestSubscriber ts = new TestSubscriber(); + final TestSubscriberEx ts = new TestSubscriberEx(); ts.onSubscribe(new BooleanSubscription()); diff --git a/src/test/java/io/reactivex/internal/util/MiscUtilTest.java b/src/test/java/io/reactivex/internal/util/MiscUtilTest.java index ae767ddde2..d2aeb48b95 100644 --- a/src/test/java/io/reactivex/internal/util/MiscUtilTest.java +++ b/src/test/java/io/reactivex/internal/util/MiscUtilTest.java @@ -19,9 +19,9 @@ import org.junit.Test; -import io.reactivex.TestHelper; import io.reactivex.functions.*; import io.reactivex.internal.util.AppendOnlyLinkedArrayList.NonThrowingPredicate; +import io.reactivex.testsupport.TestHelper; public class MiscUtilTest { @Test diff --git a/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java b/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java index 36bfe52566..9fd5935e35 100644 --- a/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java +++ b/src/test/java/io/reactivex/internal/util/NotificationLiteTest.java @@ -19,13 +19,13 @@ import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestObserverEx; public class NotificationLiteTest { @Test public void acceptFullObserver() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Disposable d = Disposables.empty(); @@ -33,7 +33,7 @@ public void acceptFullObserver() { to.assertSubscribed(); - to.cancel(); + to.dispose(); assertTrue(d.isDisposed()); } diff --git a/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java b/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java index 6be3075191..f48e82e8a3 100644 --- a/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java +++ b/src/test/java/io/reactivex/internal/util/QueueDrainHelperTest.java @@ -23,7 +23,6 @@ import org.reactivestreams.*; import io.reactivex.Observer; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.BooleanSupplier; @@ -31,6 +30,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.observers.TestObserver; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class QueueDrainHelperTest { diff --git a/src/test/java/io/reactivex/maybe/MaybeCreateTest.java b/src/test/java/io/reactivex/maybe/MaybeCreateTest.java index 90689133d5..2ee894b347 100644 --- a/src/test/java/io/reactivex/maybe/MaybeCreateTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeCreateTest.java @@ -24,6 +24,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.Cancellable; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class MaybeCreateTest { @Test(expected = NullPointerException.class) diff --git a/src/test/java/io/reactivex/maybe/MaybeTest.java b/src/test/java/io/reactivex/maybe/MaybeTest.java index be114d4495..199511e48a 100644 --- a/src/test/java/io/reactivex/maybe/MaybeTest.java +++ b/src/test/java/io/reactivex/maybe/MaybeTest.java @@ -38,7 +38,8 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class MaybeTest { @Test @@ -93,7 +94,7 @@ public void fromFlowableDisposeComposesThrough() { assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); } @@ -150,7 +151,7 @@ public void fromObservableDisposeComposesThrough() { assertTrue(ps.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); } @@ -186,7 +187,7 @@ public void empty() { @Test public void never() { Maybe.never() - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertNoValues() .assertNoErrors() @@ -559,7 +560,7 @@ public void subscribeOnNull() { @Test public void observeOnSuccess() { String main = Thread.currentThread().getName(); - Maybe.just(1) + TestObserver to = Maybe.just(1) .observeOn(Schedulers.single()) .map(new Function() { @Override @@ -569,8 +570,10 @@ public String apply(Integer v) throws Exception { }) .test() .awaitDone(5, TimeUnit.SECONDS) - .assertOf(TestHelper.observerSingleNot("1: " + main)) + .assertValueCount(1) ; + + assertNotEquals("1: " + main, to.values().get(0)); } @Test @@ -611,7 +614,7 @@ public MaybeSource apply(Maybe m) throws Exception { @Test public void subscribeOnSuccess() { String main = Thread.currentThread().getName(); - Maybe.fromCallable(new Callable() { + TestObserver to = Maybe.fromCallable(new Callable() { @Override public String call() throws Exception { return Thread.currentThread().getName(); @@ -620,8 +623,10 @@ public String call() throws Exception { .subscribeOn(Schedulers.single()) .test() .awaitDone(5, TimeUnit.SECONDS) - .assertOf(TestHelper.observerSingleNot(main)) + .assertValueCount(1) ; + + assertNotEquals(main, to.values().get(0)); } @Test @@ -848,7 +853,7 @@ public void run() throws Exception { call[0]++; } }) - .test(true) + .to(TestHelper.testConsumer(true)) .assertSubscribed() .assertNoValues() .assertNoErrors() @@ -864,17 +869,17 @@ public void doOnDisposeThrows() { try { PublishProcessor pp = PublishProcessor.create(); - TestObserver to = pp.singleElement().doOnDispose(new Action() { + TestObserverEx to = pp.singleElement().doOnDispose(new Action() { @Override public void run() throws Exception { throw new TestException(); } }) - .test(); + .to(TestHelper.testConsumer()); assertTrue(pp.hasSubscribers()); - to.cancel(); + to.dispose(); assertFalse(pp.hasSubscribers()); @@ -1887,8 +1892,8 @@ public void ambIterable2SignalsErrorWithOverlap() { PublishProcessor pp1 = PublishProcessor.create(); PublishProcessor pp2 = PublishProcessor.create(); - TestObserver to = Maybe.amb(Arrays.asList(pp1.singleElement(), pp2.singleElement())) - .test(); + TestObserverEx to = Maybe.amb(Arrays.asList(pp1.singleElement(), pp2.singleElement())) + .to(TestHelper.testConsumer()); to.assertEmpty(); @@ -2092,13 +2097,13 @@ public void mergeArrayBackpressuredMixed3() { @SuppressWarnings("unchecked") @Test public void mergeArrayFused() { - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Maybe.mergeArray(Maybe.just(1), Maybe.just(2), Maybe.just(3)).subscribe(ts); ts.assertSubscribed() - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1, 2, 3); } @@ -2109,13 +2114,13 @@ public void mergeArrayFusedRace() { final PublishProcessor pp1 = PublishProcessor.create(); final PublishProcessor pp2 = PublishProcessor.create(); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Maybe.mergeArray(pp1.singleElement(), pp2.singleElement()).subscribe(ts); ts.assertSubscribed() - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) ; TestHelper.race(new Runnable() { @@ -2198,7 +2203,7 @@ public void mergeALot() { Arrays.fill(sources, Maybe.just(1)); Maybe.mergeArray(sources) - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(sources.length) .assertNoErrors() @@ -2213,7 +2218,7 @@ public void mergeALotLastEmpty() { sources[sources.length - 1] = Maybe.empty(); Maybe.mergeArray(sources) - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(sources.length - 1) .assertNoErrors() @@ -2226,14 +2231,14 @@ public void mergeALotFused() { Maybe[] sources = new Maybe[Flowable.bufferSize() * 2]; Arrays.fill(sources, Maybe.just(1)); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); Maybe.mergeArray(sources).subscribe(ts); ts .assertSubscribed() - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertValueCount(sources.length) .assertNoErrors() .assertComplete(); @@ -2443,14 +2448,14 @@ public void accept(Integer v, Throwable e) throws Exception { @Test public void doOnEventErrorThrows() { - TestObserver to = Maybe.error(new TestException("Outer")) + TestObserverEx to = Maybe.error(new TestException("Outer")) .doOnEvent(new BiConsumer() { @Override public void accept(Integer v, Throwable e) throws Exception { throw new TestException("Inner"); } }) - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List list = TestHelper.compositeList(to.errors().get(0)); @@ -2716,7 +2721,9 @@ public void sequenceEqual() { List errors = TestHelper.trackPluginErrors(); try { - Maybe.sequenceEqual(Maybe.error(new TestException("One")), Maybe.error(new TestException("Two"))).test().assertFailureAndMessage(TestException.class, "One"); + Maybe.sequenceEqual(Maybe.error(new TestException("One")), Maybe.error(new TestException("Two"))) + .to(TestHelper.testConsumer()) + .assertFailureAndMessage(TestException.class, "One"); TestHelper.assertUndeliverable(errors, 0, TestException.class, "Two"); } finally { @@ -3234,7 +3241,7 @@ public void valueConcatWithValue() { public void errorConcatWithValue() { Maybe.error(new RuntimeException("error")) .concatWith(Maybe.just(2)) - .test() + .to(TestHelper.testConsumer()) .assertError(RuntimeException.class) .assertErrorMessage("error") .assertNoValues(); @@ -3244,7 +3251,7 @@ public void errorConcatWithValue() { public void valueConcatWithError() { Maybe.just(1) .concatWith(Maybe.error(new RuntimeException("error"))) - .test() + .to(TestHelper.testConsumer()) .assertValue(1) .assertError(RuntimeException.class) .assertErrorMessage("error"); @@ -3264,7 +3271,7 @@ public void emptyConcatWithValue() { public void emptyConcatWithError() { Maybe.empty() .concatWith(Maybe.error(new RuntimeException("error"))) - .test() + .to(TestHelper.testConsumer()) .assertNoValues() .assertError(RuntimeException.class) .assertErrorMessage("error"); diff --git a/src/test/java/io/reactivex/observable/ObservableCovarianceTest.java b/src/test/java/io/reactivex/observable/ObservableCovarianceTest.java index 5b2206001d..e02ef09827 100644 --- a/src/test/java/io/reactivex/observable/ObservableCovarianceTest.java +++ b/src/test/java/io/reactivex/observable/ObservableCovarianceTest.java @@ -26,7 +26,7 @@ import io.reactivex.ObservableTransformer; import io.reactivex.functions.*; import io.reactivex.observables.GroupedObservable; -import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.TestObserverEx; /** * Test super/extends of generics. @@ -66,7 +66,7 @@ public int compare(Media t1, Media t2) { @Test public void testGroupByCompose() { Observable movies = Observable.just(new HorrorMovie(), new ActionMovie(), new Movie()); - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); movies .groupBy(new Function() { @Override @@ -109,7 +109,7 @@ public String apply(Movie v) { to.assertTerminated(); to.assertNoErrors(); // System.out.println(ts.getOnNextEvents()); - assertEquals(6, to.valueCount()); + assertEquals(6, to.values().size()); } @SuppressWarnings("unused") diff --git a/src/test/java/io/reactivex/observable/ObservableFuseableTest.java b/src/test/java/io/reactivex/observable/ObservableFuseableTest.java index 070810461c..3105c53e7c 100644 --- a/src/test/java/io/reactivex/observable/ObservableFuseableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableFuseableTest.java @@ -18,7 +18,7 @@ import io.reactivex.Observable; import io.reactivex.internal.fuseable.QueueFuseable; -import io.reactivex.observers.ObserverFusion; +import io.reactivex.testsupport.TestHelper; public class ObservableFuseableTest { @@ -26,8 +26,8 @@ public class ObservableFuseableTest { public void syncRange() { Observable.range(1, 10) - .to(ObserverFusion.test(QueueFuseable.ANY, false)) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testConsumer(QueueFuseable.ANY, false)) + .assertFusionMode(QueueFuseable.SYNC) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -37,8 +37,8 @@ public void syncRange() { public void syncArray() { Observable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) - .to(ObserverFusion.test(QueueFuseable.ANY, false)) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testConsumer(QueueFuseable.ANY, false)) + .assertFusionMode(QueueFuseable.SYNC) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -48,8 +48,8 @@ public void syncArray() { public void syncIterable() { Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) - .to(ObserverFusion.test(QueueFuseable.ANY, false)) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC)) + .to(TestHelper.testConsumer(QueueFuseable.ANY, false)) + .assertFusionMode(QueueFuseable.SYNC) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -59,9 +59,9 @@ public void syncIterable() { public void syncRangeHidden() { Observable.range(1, 10).hide() - .to(ObserverFusion.test(QueueFuseable.ANY, false)) - .assertOf(ObserverFusion.assertNotFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)) + .to(TestHelper.testConsumer(QueueFuseable.ANY, false)) + .assertNotFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -71,9 +71,9 @@ public void syncRangeHidden() { public void syncArrayHidden() { Observable.fromArray(new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }) .hide() - .to(ObserverFusion.test(QueueFuseable.ANY, false)) - .assertOf(ObserverFusion.assertNotFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)) + .to(TestHelper.testConsumer(QueueFuseable.ANY, false)) + .assertNotFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); @@ -83,9 +83,9 @@ public void syncArrayHidden() { public void syncIterableHidden() { Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .hide() - .to(ObserverFusion.test(QueueFuseable.ANY, false)) - .assertOf(ObserverFusion.assertNotFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.NONE)) + .to(TestHelper.testConsumer(QueueFuseable.ANY, false)) + .assertNotFuseable() + .assertFusionMode(QueueFuseable.NONE) .assertValues(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) .assertNoErrors() .assertComplete(); diff --git a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java index 848d6128e1..048b2fd506 100644 --- a/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java +++ b/src/test/java/io/reactivex/observable/ObservableSubscriberTest.java @@ -28,6 +28,7 @@ import io.reactivex.observers.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableSubscriberTest { @Test diff --git a/src/test/java/io/reactivex/observable/ObservableTest.java b/src/test/java/io/reactivex/observable/ObservableTest.java index 2d49e5f6d4..f6a011054e 100644 --- a/src/test/java/io/reactivex/observable/ObservableTest.java +++ b/src/test/java/io/reactivex/observable/ObservableTest.java @@ -34,6 +34,7 @@ import io.reactivex.observers.*; import io.reactivex.schedulers.*; import io.reactivex.subjects.*; +import io.reactivex.testsupport.*; public class ObservableTest { @@ -1074,7 +1075,8 @@ public void accept(List booleans) { @Test public void testCompose() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); + Observable.just(1, 2, 3).compose(new ObservableTransformer() { @Override public Observable apply(Observable t1) { @@ -1087,6 +1089,7 @@ public String apply(Integer v) { } }) .subscribe(to); + to.assertTerminated(); to.assertNoErrors(); to.assertValues("1", "2", "3"); diff --git a/src/test/java/io/reactivex/observable/ObservableThrottleLastTests.java b/src/test/java/io/reactivex/observable/ObservableThrottleLastTests.java index 38cb2025f9..2ebce7a70a 100644 --- a/src/test/java/io/reactivex/observable/ObservableThrottleLastTests.java +++ b/src/test/java/io/reactivex/observable/ObservableThrottleLastTests.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableThrottleLastTests { diff --git a/src/test/java/io/reactivex/observable/ObservableThrottleWithTimeoutTests.java b/src/test/java/io/reactivex/observable/ObservableThrottleWithTimeoutTests.java index 39ae580c0c..f20001122f 100644 --- a/src/test/java/io/reactivex/observable/ObservableThrottleWithTimeoutTests.java +++ b/src/test/java/io/reactivex/observable/ObservableThrottleWithTimeoutTests.java @@ -23,6 +23,7 @@ import io.reactivex.*; import io.reactivex.schedulers.TestScheduler; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class ObservableThrottleWithTimeoutTests { diff --git a/src/test/java/io/reactivex/observers/DisposableCompletableObserverTest.java b/src/test/java/io/reactivex/observers/DisposableCompletableObserverTest.java index 035b9ef6c6..3f63b79ead 100644 --- a/src/test/java/io/reactivex/observers/DisposableCompletableObserverTest.java +++ b/src/test/java/io/reactivex/observers/DisposableCompletableObserverTest.java @@ -24,6 +24,7 @@ import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.observers.DisposableCompletableObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableCompletableObserverTest { diff --git a/src/test/java/io/reactivex/observers/DisposableMaybeObserverTest.java b/src/test/java/io/reactivex/observers/DisposableMaybeObserverTest.java index 547d8314bc..dd8de69196 100644 --- a/src/test/java/io/reactivex/observers/DisposableMaybeObserverTest.java +++ b/src/test/java/io/reactivex/observers/DisposableMaybeObserverTest.java @@ -24,6 +24,7 @@ import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.observers.DisposableMaybeObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableMaybeObserverTest { diff --git a/src/test/java/io/reactivex/observers/DisposableObserverTest.java b/src/test/java/io/reactivex/observers/DisposableObserverTest.java index cfefc99fea..5d49d12db6 100644 --- a/src/test/java/io/reactivex/observers/DisposableObserverTest.java +++ b/src/test/java/io/reactivex/observers/DisposableObserverTest.java @@ -20,10 +20,10 @@ import org.junit.Test; import io.reactivex.Observable; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableObserverTest { diff --git a/src/test/java/io/reactivex/observers/DisposableSingleObserverTest.java b/src/test/java/io/reactivex/observers/DisposableSingleObserverTest.java index a1dfd2a299..16da0f4e0d 100644 --- a/src/test/java/io/reactivex/observers/DisposableSingleObserverTest.java +++ b/src/test/java/io/reactivex/observers/DisposableSingleObserverTest.java @@ -24,6 +24,7 @@ import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.observers.DisposableSingleObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableSingleObserverTest { diff --git a/src/test/java/io/reactivex/observers/ObserverFusion.java b/src/test/java/io/reactivex/observers/ObserverFusion.java deleted file mode 100644 index 7137a47f05..0000000000 --- a/src/test/java/io/reactivex/observers/ObserverFusion.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * Copyright (c) 2016-present, RxJava Contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.observers; - -import io.reactivex.*; -import io.reactivex.functions.*; -import io.reactivex.internal.fuseable.*; - -/** - * Utility methods that return functional interfaces to support assertions regarding fusion - * in a TestObserver. - *

Don't move this class as it needs package-private access to TestObserver's internals. - */ -public enum ObserverFusion { - ; - - /** - * Returns a function that takes a Flowable and returns a TestObserver that - * is set up according to the parameters and is subscribed to the Flowable. - *

- * Use this as follows: - *

-     * source
-     * .to(ObserverFusion.test(QueueFuseable.ANY, false))
-     * .assertResult(0);
-     * 
- * @param the value type - * @param mode the fusion mode to request, see {@link QueueDisposable} constants. - * @param cancelled should the TestObserver cancelled before the subscription even happens? - * @return the new Function instance - */ - public static ObservableConverter> test( - final int mode, final boolean cancelled) { - return new TestFunctionCallback(mode, cancelled); - } - - /** - * Returns a Consumer that asserts on its TestObserver parameter that - * the upstream is Fuseable (sent a QueueDisposable subclass in onSubscribe). - *

- * Use this as follows: - *

-     * source
-     * .to(ObserverFusion.test(0, QueueFuseable.ANY, false))
-     * .assertOf(ObserverFusion.assertFuseable());
-     * 
- * @param the value type - * @return the new Consumer instance - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Consumer> assertFuseable() { - return (Consumer)AssertFuseable.INSTANCE; - } - - static final class AssertFusionConsumer implements Consumer> { - private final int mode; - - AssertFusionConsumer(int mode) { - this.mode = mode; - } - - @Override - public void accept(TestObserver to) throws Exception { - to.assertFusionMode(mode); - } - } - - static final class TestFunctionCallback implements ObservableConverter> { - private final int mode; - private final boolean cancelled; - - TestFunctionCallback(int mode, boolean cancelled) { - this.mode = mode; - this.cancelled = cancelled; - } - - @Override - public TestObserver apply(Observable t) { - TestObserver to = new TestObserver(); - to.setInitialFusionMode(mode); - if (cancelled) { - to.cancel(); - } - t.subscribe(to); - return to; - } - } - - enum AssertFuseable implements Consumer> { - INSTANCE; - @Override - public void accept(TestObserver to) throws Exception { - to.assertFuseable(); - } - } - - /** - * Returns a Consumer that asserts on its TestObserver parameter that - * the upstream is not Fuseable (didn't sent a QueueDisposable subclass in onSubscribe). - *

- * Use this as follows: - *

-     * source
-     * .to(ObserverFusion.test(0, QueueFuseable.ANY, false))
-     * .assertOf(ObserverFusion.assertNotFuseable());
-     * 
- * @param the value type - * @return the new Consumer instance - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Consumer> assertNotFuseable() { - return (Consumer)AssertNotFuseable.INSTANCE; - } - - enum AssertNotFuseable implements Consumer> { - INSTANCE; - @Override - public void accept(TestObserver to) throws Exception { - to.assertNotFuseable(); - } - } - - /** - * Returns a Consumer that asserts on its TestObserver parameter that - * the upstream is Fuseable (sent a QueueDisposable subclass in onSubscribe) - * and the established the given fusion mode. - *

- * Use this as follows: - *

-     * source
-     * .to(ObserverFusion.test(0, QueueFuseable.ANY, false))
-     * .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.SYNC));
-     * 
- * @param the value type - * @param mode the expected established fusion mode, see {@link QueueFuseable} constants. - * @return the new Consumer instance - */ - public static Consumer> assertFusionMode(final int mode) { - return new AssertFusionConsumer(mode); - } - - /** - * Constructs a TestObserver with the given required fusion mode. - * @param the value type - * @param mode the requested fusion mode, see {@link QueueFuseable} constants - * @return the new TestSubscriber - */ - public static TestObserver newTest(int mode) { - TestObserver to = new TestObserver(); - to.setInitialFusionMode(mode); - return to; - } - - /** - * Assert that the TestSubscriber received a fuseabe QueueFuseable.and - * is in the given fusion mode. - * @param the value type - * @param to the TestSubscriber instance - * @param mode the expected mode - * @return the TestSubscriber - */ - public static TestObserver assertFusion(TestObserver to, int mode) { - return to.assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(mode)); - } -} diff --git a/src/test/java/io/reactivex/observers/ResourceCompletableObserverTest.java b/src/test/java/io/reactivex/observers/ResourceCompletableObserverTest.java index 66669e5f2d..e9e733b1c9 100644 --- a/src/test/java/io/reactivex/observers/ResourceCompletableObserverTest.java +++ b/src/test/java/io/reactivex/observers/ResourceCompletableObserverTest.java @@ -19,12 +19,12 @@ import java.util.List; import io.reactivex.Completable; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/io/reactivex/observers/ResourceMaybeObserverTest.java b/src/test/java/io/reactivex/observers/ResourceMaybeObserverTest.java index af466153ec..7b951360d8 100644 --- a/src/test/java/io/reactivex/observers/ResourceMaybeObserverTest.java +++ b/src/test/java/io/reactivex/observers/ResourceMaybeObserverTest.java @@ -19,12 +19,12 @@ import java.util.List; import io.reactivex.Maybe; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/io/reactivex/observers/ResourceObserverTest.java b/src/test/java/io/reactivex/observers/ResourceObserverTest.java index 76f50c7bf5..476a347ce7 100644 --- a/src/test/java/io/reactivex/observers/ResourceObserverTest.java +++ b/src/test/java/io/reactivex/observers/ResourceObserverTest.java @@ -19,12 +19,12 @@ import java.util.List; import io.reactivex.Observable; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/io/reactivex/observers/ResourceSingleObserverTest.java b/src/test/java/io/reactivex/observers/ResourceSingleObserverTest.java index 0c3a50de7c..3f10cffd5a 100644 --- a/src/test/java/io/reactivex/observers/ResourceSingleObserverTest.java +++ b/src/test/java/io/reactivex/observers/ResourceSingleObserverTest.java @@ -19,12 +19,12 @@ import java.util.List; import io.reactivex.Single; -import io.reactivex.TestHelper; import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposables; import io.reactivex.exceptions.TestException; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/io/reactivex/observers/SafeObserverTest.java b/src/test/java/io/reactivex/observers/SafeObserverTest.java index edd725b7ed..2ac4045ca0 100644 --- a/src/test/java/io/reactivex/observers/SafeObserverTest.java +++ b/src/test/java/io/reactivex/observers/SafeObserverTest.java @@ -20,10 +20,11 @@ import org.junit.*; -import io.reactivex.*; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class SafeObserverTest { @@ -547,7 +548,7 @@ public void onNextNull() { @Test public void onNextWithoutOnSubscribe() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); SafeObserver so = new SafeObserver(to); @@ -558,7 +559,7 @@ public void onNextWithoutOnSubscribe() { @Test public void onErrorWithoutOnSubscribe() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); SafeObserver so = new SafeObserver(to); @@ -572,7 +573,7 @@ public void onErrorWithoutOnSubscribe() { @Test public void onCompleteWithoutOnSubscribe() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); SafeObserver so = new SafeObserver(to); diff --git a/src/test/java/io/reactivex/observers/SerializedObserverTest.java b/src/test/java/io/reactivex/observers/SerializedObserverTest.java index f094ad7fc7..e62eeb1818 100644 --- a/src/test/java/io/reactivex/observers/SerializedObserverTest.java +++ b/src/test/java/io/reactivex/observers/SerializedObserverTest.java @@ -14,6 +14,7 @@ package io.reactivex.observers; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; @@ -27,6 +28,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class SerializedObserverTest { @@ -272,7 +274,7 @@ public void testNotificationDelay() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch running = new CountDownLatch(2); - TestObserver to = new TestObserver(new DefaultObserver() { + TestObserverEx to = new TestObserverEx(new DefaultObserver() { @Override public void onComplete() { @@ -312,7 +314,7 @@ public void onNext(String t) { waitOnThreads(f1, f2); // not completed yet - assertEquals(2, to.valueCount()); + assertEquals(2, to.values().size()); Thread t2 = to.lastThread(); System.out.println("second onNext on thread: " + t2); @@ -1024,7 +1026,7 @@ public void dispose() { assertFalse(so.isDisposed()); - to.cancel(); + to.dispose(); assertTrue(so.isDisposed()); @@ -1088,7 +1090,7 @@ public void run() { .assertNoErrors() .assertComplete(); - assertTrue(to.valueCount() <= 1); + assertTrue(to.values().size() <= 1); } } @@ -1126,7 +1128,7 @@ public void run() { .assertError(ex) .assertNotComplete(); - assertTrue(to.valueCount() <= 1); + assertTrue(to.values().size() <= 1); } } @@ -1164,7 +1166,7 @@ public void run() { .assertError(ex) .assertNotComplete(); - assertTrue(to.valueCount() <= 1); + assertTrue(to.values().size() <= 1); } } @@ -1199,7 +1201,7 @@ public void onCompleteOnErrorRace() { List errors = TestHelper.trackPluginErrors(); try { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final SerializedObserver so = new SerializedObserver(to); @@ -1246,7 +1248,7 @@ public void run() { @Test public void nullOnNext() { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); final SerializedObserver so = new SerializedObserver(to); diff --git a/src/test/java/io/reactivex/observers/TestObserverTest.java b/src/test/java/io/reactivex/observers/TestObserverTest.java index d2d81dc77c..94260d1dbe 100644 --- a/src/test/java/io/reactivex/observers/TestObserverTest.java +++ b/src/test/java/io/reactivex/observers/TestObserverTest.java @@ -25,20 +25,18 @@ import org.mockito.InOrder; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.Observable; import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.functions.*; +import io.reactivex.functions.Predicate; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.*; import io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable; -import io.reactivex.internal.subscriptions.EmptySubscription; import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subjects.UnicastSubject; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class TestObserverTest { @@ -53,7 +51,7 @@ public void testAssert() { subscriber.assertValues(1, 2); subscriber.assertValueCount(2); - subscriber.assertTerminated(); + subscriber.assertComplete().assertNoErrors(); } @Test @@ -68,7 +66,7 @@ public void testAssertNotMatchCount() { subscriber.assertValue(1); subscriber.assertValueCount(2); - subscriber.assertTerminated(); + subscriber.assertComplete().assertNoErrors(); } @Test @@ -83,65 +81,7 @@ public void testAssertNotMatchValue() { subscriber.assertValues(1, 3); subscriber.assertValueCount(2); - subscriber.assertTerminated(); - } - - @Test - public void assertNeverAtNotMatchingValue() { - Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber subscriber = new TestSubscriber(); - oi.subscribe(subscriber); - - subscriber.assertNever(3); - subscriber.assertValueCount(2); - subscriber.assertTerminated(); - } - - @Test - public void assertNeverAtMatchingValue() { - Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber subscriber = new TestSubscriber(); - oi.subscribe(subscriber); - - subscriber.assertValues(1, 2); - - thrown.expect(AssertionError.class); - - subscriber.assertNever(2); - subscriber.assertValueCount(2); - subscriber.assertTerminated(); - } - - @Test - public void assertNeverAtMatchingPredicate() { - TestSubscriber ts = new TestSubscriber(); - - Flowable.just(1, 2).subscribe(ts); - - ts.assertValues(1, 2); - - thrown.expect(AssertionError.class); - - ts.assertNever(new Predicate() { - @Override - public boolean test(final Integer o) throws Exception { - return o == 1; - } - }); - } - - @Test - public void assertNeverAtNotMatchingPredicate() { - TestSubscriber ts = new TestSubscriber(); - - Flowable.just(2, 3).subscribe(ts); - - ts.assertNever(new Predicate() { - @Override - public boolean test(final Integer o) throws Exception { - return o == 1; - } - }); + subscriber.assertComplete().assertNoErrors(); } @Test @@ -159,7 +99,7 @@ public void testAssertTerminalEventNotReceived() { subscriber.assertValues(1, 2); subscriber.assertValueCount(2); - subscriber.assertTerminated(); + subscriber.assertComplete().assertNoErrors(); } @Test @@ -195,41 +135,6 @@ public void testErrorSwallowed() { Flowable.error(new RuntimeException()).subscribe(new TestSubscriber()); } - @Test - public void testGetEvents() { - TestSubscriber ts = new TestSubscriber(); - ts.onSubscribe(EmptySubscription.INSTANCE); - ts.onNext(1); - ts.onNext(2); - - assertEquals(Arrays.asList(Arrays.asList(1, 2), - Collections.emptyList(), - Collections.emptyList()), ts.getEvents()); - - ts.onComplete(); - - assertEquals(Arrays.asList(Arrays.asList(1, 2), Collections.emptyList(), - Collections.singletonList(Notification.createOnComplete())), ts.getEvents()); - - TestException ex = new TestException(); - TestSubscriber ts2 = new TestSubscriber(); - ts2.onSubscribe(EmptySubscription.INSTANCE); - ts2.onNext(1); - ts2.onNext(2); - - assertEquals(Arrays.asList(Arrays.asList(1, 2), - Collections.emptyList(), - Collections.emptyList()), ts2.getEvents()); - - ts2.onError(ex); - - assertEquals(Arrays.asList( - Arrays.asList(1, 2), - Collections.singletonList(ex), - Collections.emptyList()), - ts2.getEvents()); - } - @Test public void testNullExpected() { TestSubscriber ts = new TestSubscriber(); @@ -258,70 +163,16 @@ public void testNullActual() { fail("Null element check assertion didn't happen!"); } - @Test - public void testTerminalErrorOnce() { - TestSubscriber ts = new TestSubscriber(); - ts.onError(new TestException()); - ts.onError(new TestException()); - - try { - ts.assertTerminated(); - } catch (AssertionError ex) { - // this is expected - return; - } - fail("Failed to report multiple onError terminal events!"); - } - - @Test - public void testTerminalCompletedOnce() { - TestSubscriber ts = new TestSubscriber(); - ts.onComplete(); - ts.onComplete(); - - try { - ts.assertTerminated(); - } catch (AssertionError ex) { - // this is expected - return; - } - fail("Failed to report multiple onComplete terminal events!"); - } - - @Test - public void testTerminalOneKind() { - TestSubscriber ts = new TestSubscriber(); - ts.onError(new TestException()); - ts.onComplete(); - - try { - ts.assertTerminated(); - } catch (AssertionError ex) { - // this is expected - return; - } - fail("Failed to report multiple kinds of events!"); - } - @Test public void createDelegate() { TestObserver to1 = TestObserver.create(); TestObserver to = TestObserver.create(to1); - to.assertNotSubscribed(); - assertFalse(to.hasSubscription()); to.onSubscribe(Disposables.empty()); - try { - to.assertNotSubscribed(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - assertTrue(to.hasSubscription()); assertFalse(to.isDisposed()); @@ -336,10 +187,6 @@ public void createDelegate() { assertTrue(to.isDisposed()); - assertTrue(to.isTerminated()); - - assertSame(Thread.currentThread(), to.lastThread()); - try { to.assertNoValues(); throw new RuntimeException("Should have thrown"); @@ -362,16 +209,6 @@ public void createDelegate() { } catch (AssertionError exc) { // expected } - - to.assertValueSet(Collections.singleton(1)); - - try { - to.assertValueSet(Collections.singleton(2)); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - } @Test @@ -399,13 +236,6 @@ public void assertError() { // expected } - try { - to.assertErrorMessage(""); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - try { to.assertSubscribed(); throw new RuntimeException("Should have thrown"); @@ -413,13 +243,6 @@ public void assertError() { // expected } - try { - to.assertTerminated(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - to.onSubscribe(Disposables.empty()); to.assertSubscribed(); @@ -443,15 +266,6 @@ public boolean test(Throwable t) throws Exception { } }); - to.assertErrorMessage("Forced failure"); - - try { - to.assertErrorMessage(""); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - try { to.assertError(new RuntimeException()); throw new RuntimeException("Should have thrown"); @@ -480,8 +294,6 @@ public boolean test(Throwable t) throws Exception { // expected } - to.assertTerminated(); - to.assertValueCount(0); to.assertNoValues(); @@ -509,17 +321,9 @@ public void assertFailure() { to.assertFailure(TestException.class); - to.assertFailure(Functions.alwaysTrue()); - - to.assertFailureAndMessage(TestException.class, "Forced failure"); - to.onNext(1); to.assertFailure(TestException.class, 1); - - to.assertFailure(Functions.alwaysTrue(), 1); - - to.assertFailureAndMessage(TestException.class, "Forced failure", 1); } @Test @@ -528,97 +332,9 @@ public void assertFuseable() { to.onSubscribe(Disposables.empty()); - to.assertNotFuseable(); - - try { - to.assertFuseable(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - try { - to.assertFusionMode(QueueFuseable.SYNC); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - to = TestObserver.create(); - to.setInitialFusionMode(QueueFuseable.ANY); to.onSubscribe(new ScalarDisposable(to, 1)); - - to.assertFuseable(); - - to.assertFusionMode(QueueFuseable.SYNC); - - try { - to.assertFusionMode(QueueFuseable.NONE); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - try { - to.assertNotFuseable(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - } - - @Test - public void assertTerminated() { - TestObserver to = TestObserver.create(); - - to.assertNotTerminated(); - - to.onError(null); - - try { - to.assertNotTerminated(); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertOf() { - TestObserver to = TestObserver.create(); - - to.assertOf(new Consumer>() { - @Override - public void accept(TestObserver f) throws Exception { - f.assertNotSubscribed(); - } - }); - - try { - to.assertOf(new Consumer>() { - @Override - public void accept(TestObserver f) throws Exception { - f.assertSubscribed(); - } - }); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - try { - to.assertOf(new Consumer>() { - @Override - public void accept(TestObserver f) throws Exception { - throw new IllegalArgumentException(); - } - }); - throw new RuntimeException("Should have thrown"); - } catch (IllegalArgumentException ex) { - // expected - } } @Test @@ -670,10 +386,10 @@ public void await() throws Exception { assertTrue(to.isDisposed()); - assertFalse(to.awaitTerminalEvent(100, TimeUnit.MILLISECONDS)); + assertFalse(to.await(100, TimeUnit.MILLISECONDS)); - assertEquals(0, to.completions()); - assertEquals(0, to.errorCount()); + to.assertNotComplete(); + to.assertNoErrors(); to.onComplete(); @@ -683,10 +399,10 @@ public void await() throws Exception { to.awaitDone(5, TimeUnit.SECONDS); - assertEquals(1, to.completions()); - assertEquals(0, to.errorCount()); + to.assertComplete(); + to.assertNoErrors(); - assertTrue(to.awaitTerminalEvent()); + assertTrue(to.await(5, TimeUnit.SECONDS)); final TestObserver to1 = TestObserver.create(); @@ -700,33 +416,15 @@ public void run() { }, 200, TimeUnit.MILLISECONDS); to1.await(); - - to1.assertValueSet(Collections.emptySet()); - } - - @Test - public void errors() { - TestObserver to = TestObserver.create(); - - to.onSubscribe(Disposables.empty()); - - assertEquals(0, to.errors().size()); - - to.onError(new TestException()); - - assertEquals(1, to.errors().size()); - - TestHelper.assertError(to.errors(), 0, TestException.class); } - @SuppressWarnings("unchecked") @Test public void onNext() { TestObserver to = TestObserver.create(); to.onSubscribe(Disposables.empty()); - assertEquals(0, to.valueCount()); + assertEquals(0, to.values().size()); assertEquals(Collections.emptyList(), to.values()); @@ -734,26 +432,13 @@ public void onNext() { assertEquals(Collections.singletonList(1), to.values()); - to.cancel(); + to.dispose(); - assertTrue(to.isCancelled()); assertTrue(to.isDisposed()); to.assertValue(1); - assertEquals(Arrays.asList(Collections.singletonList(1), Collections.emptyList(), Collections.emptyList()), to.getEvents()); - to.onComplete(); - - assertEquals(Arrays.asList(Collections.singletonList(1), Collections.emptyList(), Collections.singletonList(Notification.createOnComplete())), to.getEvents()); - } - - @Test - public void fusionModeToString() { - assertEquals("NONE", TestObserver.fusionModeToString(QueueFuseable.NONE)); - assertEquals("SYNC", TestObserver.fusionModeToString(QueueFuseable.SYNC)); - assertEquals("ASYNC", TestObserver.fusionModeToString(QueueFuseable.ASYNC)); - assertEquals("Unknown(100)", TestObserver.fusionModeToString(100)); } @Test @@ -773,8 +458,6 @@ public void multipleTerminals() { // expected } - to.assertTerminated(); - to.onComplete(); try { @@ -784,13 +467,6 @@ public void multipleTerminals() { // expected } - try { - to.assertTerminated(); - throw new RuntimeException("Should have thrown"); - } catch (Throwable ex) { - // expected - } - try { to.assertNotComplete(); throw new RuntimeException("Should have thrown"); @@ -858,15 +534,25 @@ public void awaitTerminalEventInterrupt() { Thread.currentThread().interrupt(); - to.awaitTerminalEvent(); + try { + to.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } - assertTrue(Thread.interrupted()); + // FIXME ? catch consumes this flag + // assertTrue(Thread.interrupted()); Thread.currentThread().interrupt(); - to.awaitTerminalEvent(5, TimeUnit.SECONDS); + try { + to.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } - assertTrue(Thread.interrupted()); + // FIXME ? catch consumes this flag + // assertTrue(Thread.interrupted()); } @Test @@ -875,20 +561,9 @@ public void assertTerminated2() { to.onSubscribe(Disposables.empty()); - assertFalse(to.isTerminated()); - to.onError(new TestException()); to.onError(new IOException()); - assertTrue(to.isTerminated()); - - try { - to.assertTerminated(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - try { to.assertError(TestException.class); throw new RuntimeException("Should have thrown"); @@ -902,13 +577,6 @@ public void assertTerminated2() { to.onError(new TestException()); to.onComplete(); - - try { - to.assertTerminated(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } } @Test @@ -1013,29 +681,13 @@ public void awaitDoneTimed() { } } - @Test - public void assertNotSubscribed() { - TestObserver to = new TestObserver(); - - to.assertNotSubscribed(); - - to.errors().add(new TestException()); - - try { - to.assertNotSubscribed(); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - // expected - } - } - @Test public void assertErrorMultiple() { TestObserver to = new TestObserver(); TestException e = new TestException(); - to.errors().add(e); - to.errors().add(new TestException()); + to.onError(e); + to.onError(new TestException()); try { to.assertError(TestException.class); @@ -1055,12 +707,6 @@ public void assertErrorMultiple() { } catch (AssertionError ex) { // expected } - try { - to.assertErrorMessage(""); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - // expected - } } @Test @@ -1149,7 +795,7 @@ public void onComplete() { to.onComplete(); throw new RuntimeException("Should have thrown!"); } catch (TestException ex) { - assertTrue(to.isTerminated()); + to.assertComplete().assertNoErrors(); } } @@ -1185,50 +831,10 @@ public void onComplete() { to.onError(new IOException()); throw new RuntimeException("Should have thrown!"); } catch (TestException ex) { - assertTrue(to.isTerminated()); + to.assertNotComplete().assertError(Throwable.class); } } - @Test - public void syncQueueThrows() { - TestObserver to = new TestObserver(); - to.setInitialFusionMode(QueueFuseable.SYNC); - - Observable.range(1, 5) - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { throw new TestException(); } - }) - .subscribe(to); - - to.assertSubscribed() - .assertFuseable() - .assertFusionMode(QueueFuseable.SYNC) - .assertFailure(TestException.class); - } - - @Test - public void asyncQueueThrows() { - TestObserver to = new TestObserver(); - to.setInitialFusionMode(QueueFuseable.ANY); - - UnicastSubject up = UnicastSubject.create(); - - up - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { throw new TestException(); } - }) - .subscribe(to); - - up.onNext(1); - - to.assertSubscribed() - .assertFuseable() - .assertFusionMode(QueueFuseable.ASYNC) - .assertFailure(TestException.class); - } - @Test public void completedMeansDisposed() { // 2.0.2 - a terminated TestObserver no longer reports isDisposed @@ -1245,25 +851,6 @@ public void errorMeansDisposed() { .assertFailure(TestException.class).isDisposed()); } - @Test - public void asyncFusion() { - TestObserver to = new TestObserver(); - to.setInitialFusionMode(QueueFuseable.ANY); - - UnicastSubject up = UnicastSubject.create(); - - up - .subscribe(to); - - up.onNext(1); - up.onComplete(); - - to.assertSubscribed() - .assertFuseable() - .assertFusionMode(QueueFuseable.ASYNC) - .assertResult(1); - } - @Test public void assertValuePredicateEmpty() { TestObserver to = new TestObserver(); @@ -1499,162 +1086,4 @@ public void assertValuesOnlyThrowsWhenErrored() { // expected } } - - @Test - public void assertValueSetOnly() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - to.assertValueSetOnly(Collections.emptySet()); - - to.onNext(5); - to.assertValueSetOnly(Collections.singleton(5)); - - to.onNext(-1); - to.assertValueSetOnly(new HashSet(Arrays.asList(5, -1))); - } - - @Test - public void assertValueSetOnlyThrowsOnUnexpectedValue() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - to.assertValueSetOnly(Collections.emptySet()); - - to.onNext(5); - to.assertValueSetOnly(Collections.singleton(5)); - - to.onNext(-1); - - try { - to.assertValueSetOnly(Collections.singleton(5)); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSetOnlyThrowsWhenCompleted() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - - to.onComplete(); - - try { - to.assertValueSetOnly(Collections.emptySet()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSetOnlyThrowsWhenErrored() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - - to.onError(new TestException()); - - try { - to.assertValueSetOnly(Collections.emptySet()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSequenceOnly() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - to.assertValueSequenceOnly(Collections.emptyList()); - - to.onNext(5); - to.assertValueSequenceOnly(Collections.singletonList(5)); - - to.onNext(-1); - to.assertValueSequenceOnly(Arrays.asList(5, -1)); - } - - @Test - public void assertValueSequenceOnlyThrowsOnUnexpectedValue() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - to.assertValueSequenceOnly(Collections.emptyList()); - - to.onNext(5); - to.assertValueSequenceOnly(Collections.singletonList(5)); - - to.onNext(-1); - - try { - to.assertValueSequenceOnly(Collections.singletonList(5)); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSequenceOnlyThrowsWhenCompleted() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - - to.onComplete(); - - try { - to.assertValueSequenceOnly(Collections.emptyList()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSequenceOnlyThrowsWhenErrored() { - TestObserver to = TestObserver.create(); - to.onSubscribe(Disposables.empty()); - - to.onError(new TestException()); - - try { - to.assertValueSequenceOnly(Collections.emptyList()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSetWiderSet() { - Set set = new HashSet(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7)); - - Observable.just(4, 5, 1, 3, 2) - .test() - .assertValueSet(set); - } - - @Test - public void assertValueSetExact() { - Set set = new HashSet(Arrays.asList(1, 2, 3, 4, 5)); - - Observable.just(4, 5, 1, 3, 2) - .test() - .assertValueSet(set) - .assertValueCount(set.size()); - } - - @Test - public void assertValueSetMissing() { - Set set = new HashSet(Arrays.asList(0, 1, 2, 4, 5, 6, 7)); - - try { - Observable.range(1, 5) - .test() - .assertValueSet(set); - - throw new RuntimeException("Should have failed"); - } catch (AssertionError ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3)); - } - } } diff --git a/src/test/java/io/reactivex/parallel/ParallelCollectTest.java b/src/test/java/io/reactivex/parallel/ParallelCollectTest.java index 088a0714f0..6144acf933 100644 --- a/src/test/java/io/reactivex/parallel/ParallelCollectTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelCollectTest.java @@ -25,6 +25,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class ParallelCollectTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java b/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java index 41f82363d6..432c2823e6 100644 --- a/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelDoOnNextTryTest.java @@ -19,12 +19,12 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class ParallelDoOnNextTryTest implements Consumer { @@ -192,7 +192,7 @@ public void accept(Integer v) throws Exception { @SuppressWarnings("unchecked") @Test public void doOnNextFailHandlerThrows() { - TestSubscriber ts = Flowable.range(0, 2) + TestSubscriberEx ts = Flowable.range(0, 2) .parallel(1) .doOnNext(new Consumer() { @Override @@ -208,7 +208,7 @@ public ParallelFailureHandling apply(Long n, Throwable e) throws Exception { } }) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertCompositeExceptions(ts, ArithmeticException.class, TestException.class); @@ -339,7 +339,7 @@ public void accept(Integer v) throws Exception { @SuppressWarnings("unchecked") @Test public void doOnNextFailHandlerThrowsConditional() { - TestSubscriber ts = Flowable.range(0, 2) + TestSubscriberEx ts = Flowable.range(0, 2) .parallel(1) .doOnNext(new Consumer() { @Override @@ -356,7 +356,7 @@ public ParallelFailureHandling apply(Long n, Throwable e) throws Exception { }) .filter(Functions.alwaysTrue()) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertCompositeExceptions(ts, ArithmeticException.class, TestException.class); diff --git a/src/test/java/io/reactivex/parallel/ParallelFilterTest.java b/src/test/java/io/reactivex/parallel/ParallelFilterTest.java index c1a248fb7e..1d37f54c4f 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFilterTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFilterTest.java @@ -24,6 +24,7 @@ import io.reactivex.functions.Predicate; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ParallelFilterTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java b/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java index e49090acf8..6493bf847c 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFilterTryTest.java @@ -17,12 +17,12 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class ParallelFilterTryTest implements Consumer { @@ -195,7 +195,7 @@ public boolean test(Integer v) throws Exception { @SuppressWarnings("unchecked") @Test public void filterFailHandlerThrows() { - TestSubscriber ts = Flowable.range(0, 2) + TestSubscriberEx ts = Flowable.range(0, 2) .parallel(1) .filter(new Predicate() { @Override @@ -209,7 +209,7 @@ public ParallelFailureHandling apply(Long n, Throwable e) throws Exception { } }) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertCompositeExceptions(ts, ArithmeticException.class, TestException.class); @@ -330,7 +330,7 @@ public boolean test(Integer v) throws Exception { @SuppressWarnings("unchecked") @Test public void filterFailHandlerThrowsConditional() { - TestSubscriber ts = Flowable.range(0, 2) + TestSubscriberEx ts = Flowable.range(0, 2) .parallel(1) .filter(new Predicate() { @Override @@ -345,7 +345,7 @@ public ParallelFailureHandling apply(Long n, Throwable e) throws Exception { }) .filter(Functions.alwaysTrue()) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertCompositeExceptions(ts, ArithmeticException.class, TestException.class); diff --git a/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java b/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java index d9c5087547..1f8c533246 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFlowableTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.UnicastProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class ParallelFlowableTest { @@ -48,7 +49,7 @@ public Integer apply(Integer v) throws Exception { .sequential() ; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -76,7 +77,7 @@ public Integer apply(Integer v) throws Exception { .sequential() ; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -112,7 +113,7 @@ public Integer apply(Integer v) throws Exception { .sequential() ; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -153,7 +154,7 @@ public Integer apply(Integer v) throws Exception { .sequential() ; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); result.subscribe(ts); @@ -281,7 +282,7 @@ public List get() throws Exception { } }; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(1, 10) .parallel() .collect(as, new BiConsumer, Integer>() { @@ -299,28 +300,32 @@ public Iterable apply(List v) throws Exception { }) .subscribe(ts); - ts.assertValueSet(new HashSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))) + ts .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @SuppressWarnings("unchecked") @Test public void from() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); ParallelFlowable.fromArray(Flowable.range(1, 5), Flowable.range(6, 5)) .sequential() .subscribe(ts); - ts.assertValueSet(new HashSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))) + ts .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); } @Test public void concatMapUnordered() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(1, 5) .parallel() @@ -333,15 +338,16 @@ public Publisher apply(Integer v) throws Exception { .sequential() .subscribe(ts); - ts.assertValueSet(new HashSet(Arrays.asList(11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43, 51, 52, 53))) + ts .assertNoErrors() .assertComplete(); + TestHelper.assertValueSet(ts, 11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43, 51, 52, 53); } @Test public void flatMapUnordered() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.range(1, 5) .parallel() @@ -354,10 +360,11 @@ public Publisher apply(Integer v) throws Exception { .sequential() .subscribe(ts); - ts.assertValueSet(new HashSet(Arrays.asList(11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43, 51, 52, 53))) + ts .assertNoErrors() .assertComplete(); + TestHelper.assertValueSet(ts, 11, 12, 13, 21, 22, 23, 31, 32, 33, 41, 42, 43, 51, 52, 53); } @Test @@ -721,7 +728,7 @@ public void parallelismAndPrefetch() { .parallel(parallelism, prefetch) .map(Functions.identity()) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertSubscribed() .assertValueCount(1024 * 1024) .assertNoErrors() @@ -741,7 +748,7 @@ public void parallelismAndPrefetchAsync() { .runOn(Schedulers.computation()) .map(Functions.identity()) .sequential(prefetch) - .test() + .to(TestHelper.testConsumer()) .withTag("parallelism = " + parallelism + ", prefetch = " + prefetch) .awaitDone(30, TimeUnit.SECONDS) .assertSubscribed() @@ -782,7 +789,7 @@ public void badParallelismStage2() { @Test public void filter() { - Flowable.range(1, 20) + TestSubscriberEx ts = Flowable.range(1, 20) .parallel() .runOn(Schedulers.computation()) .filter(new Predicate() { @@ -792,11 +799,12 @@ public boolean test(Integer v) throws Exception { } }) .sequential() - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) - .assertValueSet(Arrays.asList(2, 4, 6, 8, 10, 12, 14, 16, 18, 20)) .assertNoErrors() .assertComplete(); + + TestHelper.assertValueSet(ts, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20); } @Test @@ -953,7 +961,7 @@ public void accept(Throwable e) throws Exception { @Test public void doOnErrorThrows() { - TestSubscriber ts = Flowable.range(1, 5) + TestSubscriberEx ts = Flowable.range(1, 5) .parallel(2) .map(new Function() { @Override @@ -973,7 +981,7 @@ public void accept(Throwable e) throws Exception { } }) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertError(CompositeException.class) .assertNotComplete(); diff --git a/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java b/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java index 202e4dd0fc..f8f0524807 100644 --- a/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelFromPublisherTest.java @@ -30,6 +30,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.processors.UnicastProcessor; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class ParallelFromPublisherTest { @@ -150,7 +151,7 @@ public void boundaryConfinement() { final Set between = new HashSet(); final ConcurrentHashMap processing = new ConcurrentHashMap(); - Flowable.range(1, 10) + TestSubscriberEx ts = Flowable.range(1, 10) .observeOn(Schedulers.single(), false, 1) .doOnNext(new Consumer() { @Override @@ -168,14 +169,15 @@ public Object apply(Integer v) throws Exception { } }) .sequential() - .test() + .to(TestHelper.testConsumer()) .awaitDone(5, TimeUnit.SECONDS) .assertSubscribed() - .assertValueSet(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)) .assertComplete() .assertNoErrors() ; + TestHelper.assertValueSet(ts, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + assertEquals(between.toString(), 1, between.size()); assertTrue(between.toString(), between.iterator().next().contains("RxSingleScheduler")); diff --git a/src/test/java/io/reactivex/parallel/ParallelJoinTest.java b/src/test/java/io/reactivex/parallel/ParallelJoinTest.java index 80ffade276..db5551f885 100644 --- a/src/test/java/io/reactivex/parallel/ParallelJoinTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelJoinTest.java @@ -18,11 +18,12 @@ import org.junit.Test; import org.reactivestreams.Subscriber; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.Function; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class ParallelJoinTest { @@ -158,7 +159,7 @@ public void emptyBackpressuredDelayError() { @Test public void delayError() { - TestSubscriber flow = Flowable.range(1, 2) + TestSubscriberEx flow = Flowable.range(1, 2) .parallel(2) .map(new Function() { @Override @@ -167,7 +168,7 @@ public Integer apply(Integer v) throws Exception { } }) .sequentialDelayError() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); List error = TestHelper.errorList(flow); diff --git a/src/test/java/io/reactivex/parallel/ParallelMapTest.java b/src/test/java/io/reactivex/parallel/ParallelMapTest.java index e739c3e925..d2092dea09 100644 --- a/src/test/java/io/reactivex/parallel/ParallelMapTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelMapTest.java @@ -26,6 +26,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class ParallelMapTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java b/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java index 09b3dbcf6d..6bf1e1cdf7 100644 --- a/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelMapTryTest.java @@ -17,12 +17,12 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class ParallelMapTryTest implements Consumer { @@ -170,7 +170,7 @@ public Integer apply(Integer v) throws Exception { @SuppressWarnings("unchecked") @Test public void mapFailHandlerThrows() { - TestSubscriber ts = Flowable.range(0, 2) + TestSubscriberEx ts = Flowable.range(0, 2) .parallel(1) .map(new Function() { @Override @@ -184,7 +184,7 @@ public ParallelFailureHandling apply(Long n, Throwable e) throws Exception { } }) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertCompositeExceptions(ts, ArithmeticException.class, TestException.class); @@ -305,7 +305,7 @@ public Integer apply(Integer v) throws Exception { @SuppressWarnings("unchecked") @Test public void mapFailHandlerThrowsConditional() { - TestSubscriber ts = Flowable.range(0, 2) + TestSubscriberEx ts = Flowable.range(0, 2) .parallel(1) .map(new Function() { @Override @@ -320,7 +320,7 @@ public ParallelFailureHandling apply(Long n, Throwable e) throws Exception { }) .filter(Functions.alwaysTrue()) .sequential() - .test() + .to(TestHelper.testConsumer()) .assertFailure(CompositeException.class); TestHelper.assertCompositeExceptions(ts, ArithmeticException.class, TestException.class); diff --git a/src/test/java/io/reactivex/parallel/ParallelPeekTest.java b/src/test/java/io/reactivex/parallel/ParallelPeekTest.java index deb5c2a6ba..c247adb1a1 100644 --- a/src/test/java/io/reactivex/parallel/ParallelPeekTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelPeekTest.java @@ -26,6 +26,7 @@ import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ParallelPeekTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelReduceFullTest.java b/src/test/java/io/reactivex/parallel/ParallelReduceFullTest.java index f296c286d7..854dc37eeb 100644 --- a/src/test/java/io/reactivex/parallel/ParallelReduceFullTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelReduceFullTest.java @@ -26,6 +26,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class ParallelReduceFullTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelReduceTest.java b/src/test/java/io/reactivex/parallel/ParallelReduceTest.java index 4a1d110bc0..62b7db4323 100644 --- a/src/test/java/io/reactivex/parallel/ParallelReduceTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelReduceTest.java @@ -25,6 +25,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class ParallelReduceTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelRunOnTest.java b/src/test/java/io/reactivex/parallel/ParallelRunOnTest.java index 53023b5790..71dd6e9380 100644 --- a/src/test/java/io/reactivex/parallel/ParallelRunOnTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelRunOnTest.java @@ -31,6 +31,7 @@ import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class ParallelRunOnTest { diff --git a/src/test/java/io/reactivex/parallel/ParallelSortedJoinTest.java b/src/test/java/io/reactivex/parallel/ParallelSortedJoinTest.java index aede8c5717..339f4ef6ec 100644 --- a/src/test/java/io/reactivex/parallel/ParallelSortedJoinTest.java +++ b/src/test/java/io/reactivex/parallel/ParallelSortedJoinTest.java @@ -28,6 +28,7 @@ import io.reactivex.processors.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class ParallelSortedJoinTest { diff --git a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java index 2fa0ab9532..ae3f6eb2ce 100644 --- a/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java +++ b/src/test/java/io/reactivex/plugins/RxJavaPluginsTest.java @@ -48,6 +48,7 @@ import io.reactivex.observables.ConnectableObservable; import io.reactivex.parallel.ParallelFlowable; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class RxJavaPluginsTest { diff --git a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java index 963171d30e..f013866101 100644 --- a/src/test/java/io/reactivex/processors/AsyncProcessorTest.java +++ b/src/test/java/io/reactivex/processors/AsyncProcessorTest.java @@ -24,12 +24,12 @@ import org.mockito.*; import org.reactivestreams.Subscriber; -import io.reactivex.TestHelper; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.subscriptions.BooleanSubscription; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class AsyncProcessorTest extends FlowableProcessorTest { @@ -158,7 +158,7 @@ public void testUnsubscribeBeforeCompleted() { processor.onNext("one"); processor.onNext("two"); - ts.dispose(); + ts.cancel(); verify(subscriber, Mockito.never()).onNext(anyString()); verify(subscriber, Mockito.never()).onError(any(Throwable.class)); @@ -391,13 +391,13 @@ public void testCurrentStateMethodsError() { public void fusionLive() { AsyncProcessor ap = new AsyncProcessor(); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); ap.subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)); + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC); ts.assertNoValues().assertNoErrors().assertNotComplete(); @@ -416,13 +416,13 @@ public void fusionOfflie() { ap.onNext(1); ap.onComplete(); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); ap.subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1); } @@ -491,7 +491,7 @@ public void onErrorCancelRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final AsyncProcessor p = AsyncProcessor.create(); - final TestSubscriber ts1 = p.test(); + final TestSubscriberEx ts1 = p.to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -511,7 +511,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts1.errorCount() != 0) { + if (ts1.errors().size() != 0) { ts1.assertFailure(TestException.class); } else { ts1.assertEmpty(); diff --git a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java index a0e3996f41..341216160b 100644 --- a/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java +++ b/src/test/java/io/reactivex/processors/BehaviorProcessorTest.java @@ -33,6 +33,7 @@ import io.reactivex.processors.BehaviorProcessor.BehaviorSubscription; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class BehaviorProcessorTest extends FlowableProcessorTest { @@ -153,7 +154,7 @@ public void testCompletedStopsEmittingData() { inOrderA.verify(observerA).onNext(42); inOrderB.verify(observerB).onNext(42); - ts.dispose(); + ts.cancel(); inOrderA.verifyNoMoreInteractions(); channel.onNext(4711); @@ -681,7 +682,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts[0].valueCount() == 1) { + if (ts[0].values().size() == 1) { ts[0].assertValue(2).assertNoErrors().assertNotComplete(); } else { ts[0].assertValues(1, 2).assertNoErrors().assertNotComplete(); @@ -836,7 +837,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.valueCount() > 0) { + if (ts.values().size() > 0) { ts.assertValuesOnly(0); } else { ts.assertEmpty(); diff --git a/src/test/java/io/reactivex/processors/MulticastProcessorTest.java b/src/test/java/io/reactivex/processors/MulticastProcessorTest.java index 63a7b1a60b..129828db5b 100644 --- a/src/test/java/io/reactivex/processors/MulticastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/MulticastProcessorTest.java @@ -28,6 +28,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; public class MulticastProcessorTest { diff --git a/src/test/java/io/reactivex/processors/PublishProcessorTest.java b/src/test/java/io/reactivex/processors/PublishProcessorTest.java index f91e61551f..fe28e75038 100644 --- a/src/test/java/io/reactivex/processors/PublishProcessorTest.java +++ b/src/test/java/io/reactivex/processors/PublishProcessorTest.java @@ -30,6 +30,7 @@ import io.reactivex.functions.*; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class PublishProcessorTest extends FlowableProcessorTest { @@ -82,7 +83,7 @@ public void testCompletedStopsEmittingData() { inOrderA.verify(observerA).onNext(42); inOrderB.verify(observerB).onNext(42); - ts.dispose(); + ts.cancel(); inOrderA.verifyNoMoreInteractions(); channel.onNext(4711); @@ -183,7 +184,7 @@ public void testUnsubscribeFirstSubscriber() { processor.onNext("one"); processor.onNext("two"); - ts.dispose(); + ts.cancel(); assertObservedUntilTwo(subscriber); Subscriber anotherSubscriber = TestHelper.mockSubscriber(); @@ -275,7 +276,7 @@ public void testReSubscribe() { inOrder1.verifyNoMoreInteractions(); // unsubscribe - ts.dispose(); + ts.cancel(); // emit again but nothing will be there to receive it pp.onNext(2); @@ -292,7 +293,7 @@ public void testReSubscribe() { inOrder2.verify(subscriber2, times(1)).onNext(3); inOrder2.verifyNoMoreInteractions(); - ts2.dispose(); + ts2.cancel(); } private final Throwable testException = new Throwable(); @@ -704,7 +705,7 @@ public void run() { TestHelper.race(r1, r2); - if (ts.valueCount() > 0) { + if (ts.values().size() > 0) { ts.assertValuesOnly(0); } else { ts.assertEmpty(); diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java index 0258488d52..a1b69e8f0f 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorBoundedConcurrencyTest.java @@ -25,7 +25,8 @@ import io.reactivex.*; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.DefaultSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; public class ReplayProcessorBoundedConcurrencyTest { @@ -291,9 +292,9 @@ public void run() { public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValueSequence(expected); ts.assertTerminated(); } diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java index 978c86ebe4..c719149de3 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorConcurrencyTest.java @@ -25,7 +25,8 @@ import io.reactivex.*; import io.reactivex.functions.Consumer; import io.reactivex.schedulers.Schedulers; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.DefaultSubscriber; +import io.reactivex.testsupport.TestSubscriberEx; public class ReplayProcessorConcurrencyTest { @@ -291,9 +292,9 @@ public void run() { public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Flowable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValueSequence(expected); ts.assertTerminated(); } diff --git a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java index cf930b062a..f3bd65d2c7 100644 --- a/src/test/java/io/reactivex/processors/ReplayProcessorTest.java +++ b/src/test/java/io/reactivex/processors/ReplayProcessorTest.java @@ -34,6 +34,7 @@ import io.reactivex.processors.ReplayProcessor.*; import io.reactivex.schedulers.*; import io.reactivex.subscribers.*; +import io.reactivex.testsupport.TestHelper; public class ReplayProcessorTest extends FlowableProcessorTest { @@ -91,7 +92,7 @@ public void testCompletedStopsEmittingData() { inOrderA.verify(observerA).onNext(42); inOrderB.verify(observerB).onNext(42); - ts.dispose(); + ts.cancel(); // a should receive no more inOrderA.verifyNoMoreInteractions(); @@ -232,7 +233,7 @@ public void testUnsubscribeFirstSubscriber() { processor.onNext("one"); processor.onNext("two"); - ts.dispose(); + ts.cancel(); assertObservedUntilTwo(subscriber); Subscriber anotherSubscriber = TestHelper.mockSubscriber(); diff --git a/src/test/java/io/reactivex/processors/SerializedProcessorTest.java b/src/test/java/io/reactivex/processors/SerializedProcessorTest.java index 9772d780e0..dec4001f5e 100644 --- a/src/test/java/io/reactivex/processors/SerializedProcessorTest.java +++ b/src/test/java/io/reactivex/processors/SerializedProcessorTest.java @@ -16,14 +16,16 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class SerializedProcessorTest { @@ -34,7 +36,7 @@ public void testBasic() { processor.subscribe(ts); processor.onNext("hello"); processor.onComplete(); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValue("hello"); } @@ -414,10 +416,12 @@ public void normal() { @Test public void onNextOnNextRace() { + Set expectedSet = new HashSet(Arrays.asList(1, 2)); + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final FlowableProcessor s = PublishProcessor.create().toSerialized(); - TestSubscriber ts = s.test(); + TestSubscriberEx ts = s.to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -435,8 +439,14 @@ public void run() { TestHelper.race(r1, r2); - ts.assertSubscribed().assertNoErrors().assertNotComplete() - .assertValueSet(Arrays.asList(1, 2)); + ts.assertSubscribed() + .assertNoErrors() + .assertNotComplete() + .assertValueCount(2) + ; + + Set actualSet = new HashSet(ts.values()); + assertEquals("" + actualSet, expectedSet, actualSet); } } @@ -467,7 +477,7 @@ public void run() { ts.assertError(ex).assertNotComplete(); - if (ts.valueCount() != 0) { + if (ts.values().size() != 0) { ts.assertValue(1); } } @@ -498,7 +508,7 @@ public void run() { ts.assertComplete().assertNoErrors(); - if (ts.valueCount() != 0) { + if (ts.values().size() != 0) { ts.assertValue(1); } } diff --git a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java index 5bbe6dca75..97ba6aaf55 100644 --- a/src/test/java/io/reactivex/processors/UnicastProcessorTest.java +++ b/src/test/java/io/reactivex/processors/UnicastProcessorTest.java @@ -20,13 +20,14 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.disposables.Disposable; import io.reactivex.exceptions.TestException; -import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; -import io.reactivex.subscribers.*; +import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class UnicastProcessorTest extends FlowableProcessorTest { @@ -39,13 +40,13 @@ protected FlowableProcessor create() { public void fusionLive() { UnicastProcessor ap = UnicastProcessor.create(); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); ap.subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)); + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC); ts.assertNoValues().assertNoErrors().assertNotComplete(); @@ -64,13 +65,13 @@ public void fusionOfflie() { ap.onNext(1); ap.onComplete(); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); ap.subscribe(ts); ts - .assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1); } @@ -95,7 +96,7 @@ public void failFastFusionOffline() { ap.onNext(1); ap.onError(new RuntimeException()); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); ap.subscribe(ts); ts @@ -263,11 +264,11 @@ public void onErrorStatePeeking() { public void rejectSyncFusion() { UnicastProcessor p = UnicastProcessor.create(); - TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.SYNC); + TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.SYNC); p.subscribe(ts); - SubscriberFusion.assertFusion(ts, QueueFuseable.NONE); + ts.assertFusionMode(QueueFuseable.NONE); } @Test @@ -297,7 +298,7 @@ public void fusedDrainCancel() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final UnicastProcessor p = UnicastProcessor.create(); - final TestSubscriber ts = SubscriberFusion.newTest(QueueFuseable.ANY); + final TestSubscriberEx ts = new TestSubscriberEx().setInitialFusionMode(QueueFuseable.ANY); p.subscribe(ts); @@ -324,8 +325,8 @@ public void subscribeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final UnicastProcessor us = UnicastProcessor.create(); - final TestSubscriber ts1 = new TestSubscriber(); - final TestSubscriber ts2 = new TestSubscriber(); + final TestSubscriberEx ts1 = new TestSubscriberEx(); + final TestSubscriberEx ts2 = new TestSubscriberEx(); Runnable r1 = new Runnable() { @Override @@ -343,10 +344,10 @@ public void run() { TestHelper.race(r1, r2); - if (ts1.errorCount() == 0) { + if (ts1.errors().size() == 0) { ts2.assertFailure(IllegalStateException.class); } else - if (ts2.errorCount() == 0) { + if (ts2.errors().size() == 0) { ts1.assertFailure(IllegalStateException.class); } else { fail("Neither TestObserver failed"); @@ -373,7 +374,7 @@ public void hasObservers() { public void drainFusedFailFast() { UnicastProcessor us = UnicastProcessor.create(false); - TestSubscriber ts = us.to(SubscriberFusion.test(1, QueueFuseable.ANY, false)); + TestSubscriberEx ts = us.to(TestHelper.testSubscriber(1, QueueFuseable.ANY, false)); us.done = true; us.drainFused(ts); @@ -385,7 +386,7 @@ public void drainFusedFailFast() { public void drainFusedFailFastEmpty() { UnicastProcessor us = UnicastProcessor.create(false); - TestSubscriber ts = us.to(SubscriberFusion.test(1, QueueFuseable.ANY, false)); + TestSubscriberEx ts = us.to(TestHelper.testSubscriber(1, QueueFuseable.ANY, false)); us.drainFused(ts); @@ -396,7 +397,7 @@ public void drainFusedFailFastEmpty() { public void checkTerminatedFailFastEmpty() { UnicastProcessor us = UnicastProcessor.create(false); - TestSubscriber ts = us.to(SubscriberFusion.test(1, QueueFuseable.ANY, false)); + TestSubscriberEx ts = us.to(TestHelper.testSubscriber(1, QueueFuseable.ANY, false)); us.checkTerminated(true, true, false, ts, us.queue); diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java index bccca7524e..5e52e3bf3c 100644 --- a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerInterruptibleTest.java @@ -29,6 +29,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.schedulers.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ExecutorSchedulerInterruptibleTest extends AbstractSchedulerConcurrencyTests { diff --git a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java index eaa5b692f1..4855449977 100644 --- a/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/ExecutorSchedulerTest.java @@ -29,6 +29,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.internal.schedulers.*; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ExecutorSchedulerTest extends AbstractSchedulerConcurrencyTests { diff --git a/src/test/java/io/reactivex/schedulers/SchedulerTest.java b/src/test/java/io/reactivex/schedulers/SchedulerTest.java index 99ffca6afb..d838e43d2c 100644 --- a/src/test/java/io/reactivex/schedulers/SchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/SchedulerTest.java @@ -28,6 +28,7 @@ import io.reactivex.internal.disposables.*; import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SchedulerTest { diff --git a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java index 2768a12b1a..d8732796d7 100644 --- a/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java +++ b/src/test/java/io/reactivex/schedulers/TrampolineSchedulerTest.java @@ -13,16 +13,16 @@ package io.reactivex.schedulers; -import io.reactivex.Flowable; -import io.reactivex.Scheduler; +import io.reactivex.*; import io.reactivex.Scheduler.Worker; -import io.reactivex.TestHelper; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.Disposable; import io.reactivex.functions.Consumer; import io.reactivex.functions.Function; import io.reactivex.internal.functions.Functions; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.TestHelper; + import java.util.ArrayList; import java.util.Arrays; import java.util.concurrent.TimeUnit; @@ -130,7 +130,7 @@ public Disposable apply(Long ount1) { }) .subscribeOn(Schedulers.computation()) .subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); } diff --git a/src/test/java/io/reactivex/single/SingleCacheTest.java b/src/test/java/io/reactivex/single/SingleCacheTest.java index ddfa964ac0..4b3d06e4ef 100644 --- a/src/test/java/io/reactivex/single/SingleCacheTest.java +++ b/src/test/java/io/reactivex/single/SingleCacheTest.java @@ -75,7 +75,7 @@ public void delayedDisposed() { TestObserver to2 = cache.test(); - to1.cancel(); + to1.dispose(); ps.onNext(1); ps.onComplete(); diff --git a/src/test/java/io/reactivex/single/SingleSubscribeTest.java b/src/test/java/io/reactivex/single/SingleSubscribeTest.java index d1ace79dc9..418e778290 100644 --- a/src/test/java/io/reactivex/single/SingleSubscribeTest.java +++ b/src/test/java/io/reactivex/single/SingleSubscribeTest.java @@ -27,6 +27,7 @@ import io.reactivex.internal.functions.Functions; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.subjects.PublishSubject; +import io.reactivex.testsupport.TestHelper; public class SingleSubscribeTest { diff --git a/src/test/java/io/reactivex/single/SingleTest.java b/src/test/java/io/reactivex/single/SingleTest.java index 1bc0919685..c5080c9e3b 100644 --- a/src/test/java/io/reactivex/single/SingleTest.java +++ b/src/test/java/io/reactivex/single/SingleTest.java @@ -29,6 +29,7 @@ import io.reactivex.internal.operators.single.SingleInternalHelper; import io.reactivex.schedulers.Schedulers; import io.reactivex.subscribers.TestSubscriber; +import io.reactivex.testsupport.*; public class SingleTest { @@ -142,7 +143,7 @@ public void subscribe(SingleObserver observer) { @Test public void testCreateError() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); Single.unsafeCreate(new SingleSource() { @Override public void subscribe(SingleObserver observer) { @@ -176,13 +177,13 @@ public String apply(String v) { } }) .toFlowable().subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertValueSequence(Arrays.asList("Hello")); } @Test - public void testFlatMap() { - TestSubscriber ts = new TestSubscriber(); + public void testFlatMap() throws InterruptedException { + TestSubscriberEx ts = new TestSubscriberEx(); Single.just("Hello").flatMap(new Function>() { @Override public Single apply(String s) { @@ -190,7 +191,7 @@ public Single apply(String s) { } } ).toFlowable().subscribe(ts); - if (!ts.awaitTerminalEvent(5, TimeUnit.SECONDS)) { + if (!ts.await(5, TimeUnit.SECONDS)) { ts.cancel(); Assert.fail("TestSubscriber timed out."); } @@ -215,7 +216,7 @@ public void subscribe(SingleObserver observer) { s1.timeout(100, TimeUnit.MILLISECONDS).toFlowable().subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertError(TimeoutException.class); } @@ -237,7 +238,7 @@ public void subscribe(SingleObserver observer) { s1.timeout(100, TimeUnit.MILLISECONDS, Single.just("hello")).toFlowable().subscribe(ts); - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); ts.assertNoErrors(); ts.assertValue("hello"); } @@ -284,7 +285,7 @@ public void run() { Thread.sleep(100); - ts.dispose(); + ts.cancel(); if (latch.await(1000, TimeUnit.MILLISECONDS)) { assertTrue(unsubscribed.get()); @@ -560,7 +561,7 @@ public void fromObservableEmpty() { @Test public void fromObservableMoreThan1Elements() { Single.fromObservable(Observable.just(1, 2)) - .test() + .to(TestHelper.testConsumer()) .assertFailure(IllegalArgumentException.class) .assertErrorMessage("Sequence contains more than one element!"); } @@ -575,7 +576,7 @@ public void fromObservableOneElement() { @Test public void fromObservableError() { Single.fromObservable(Observable.error(new RuntimeException("some error"))) - .test() + .to(TestHelper.testConsumer()) .assertFailure(RuntimeException.class) .assertErrorMessage("some error"); } diff --git a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java index efd643e8d9..1d0aa5fb77 100644 --- a/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/AsyncSubjectTest.java @@ -23,12 +23,13 @@ import org.junit.*; import org.mockito.*; -import io.reactivex.*; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; import io.reactivex.functions.Consumer; import io.reactivex.internal.fuseable.QueueFuseable; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; +import io.reactivex.testsupport.*; public class AsyncSubjectTest extends SubjectTest { @@ -390,13 +391,10 @@ public void testCurrentStateMethodsError() { public void fusionLive() { AsyncSubject ap = new AsyncSubject(); - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = ap.to(TestHelper.testConsumer(false, QueueFuseable.ANY)); - ap.subscribe(to); - - to - .assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)); + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC); to.assertNoValues().assertNoErrors().assertNotComplete(); @@ -415,13 +413,10 @@ public void fusionOfflie() { ap.onNext(1); ap.onComplete(); - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); - - ap.subscribe(to); + TestObserverEx to = ap.to(TestHelper.testConsumer(false, QueueFuseable.ANY)); - to - .assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + to.assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1); } @@ -469,14 +464,14 @@ public void cancelRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; Runnable r2 = new Runnable() { @Override public void run() { - to2.cancel(); + to2.dispose(); } }; @@ -490,12 +485,12 @@ public void onErrorCancelRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final AsyncSubject p = AsyncSubject.create(); - final TestObserver to1 = p.test(); + final TestObserverEx to1 = p.to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; @@ -510,7 +505,7 @@ public void run() { TestHelper.race(r1, r2); - if (to1.errorCount() != 0) { + if (to1.errors().size() != 0) { to1.assertFailure(TestException.class); } else { to1.assertEmpty(); @@ -526,7 +521,7 @@ public void onNextCrossCancel() { TestObserver to1 = new TestObserver() { @Override public void onNext(Object t) { - to2.cancel(); + to2.dispose(); super.onNext(t); } }; @@ -549,7 +544,7 @@ public void onErrorCrossCancel() { TestObserver to1 = new TestObserver() { @Override public void onError(Throwable t) { - to2.cancel(); + to2.dispose(); super.onError(t); } }; @@ -571,7 +566,7 @@ public void onCompleteCrossCancel() { TestObserver to1 = new TestObserver() { @Override public void onComplete() { - to2.cancel(); + to2.dispose(); super.onComplete(); } }; diff --git a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java index 9a2b52f8f7..989e87c2a9 100644 --- a/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/BehaviorSubjectTest.java @@ -32,6 +32,7 @@ import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.BehaviorSubject.BehaviorDisposable; +import io.reactivex.testsupport.TestHelper; public class BehaviorSubjectTest extends SubjectTest { @@ -649,7 +650,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -681,7 +682,7 @@ public void run() { TestHelper.race(r1, r2); - if (to[0].valueCount() == 1) { + if (to[0].values().size() == 1) { to[0].assertValue(2).assertNoErrors().assertNotComplete(); } else { to[0].assertValues(1, 2).assertNoErrors().assertNotComplete(); diff --git a/src/test/java/io/reactivex/subjects/CompletableSubjectTest.java b/src/test/java/io/reactivex/subjects/CompletableSubjectTest.java index 56be25b2b3..759ba238c4 100644 --- a/src/test/java/io/reactivex/subjects/CompletableSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/CompletableSubjectTest.java @@ -24,6 +24,7 @@ import io.reactivex.disposables.*; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class CompletableSubjectTest { @@ -131,7 +132,7 @@ public void nullThrowable() { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } - cs.test().assertEmpty().cancel();; + cs.test().assertEmpty().dispose(); } @Test @@ -219,7 +220,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; TestHelper.race(r1, r2); diff --git a/src/test/java/io/reactivex/subjects/MaybeSubjectTest.java b/src/test/java/io/reactivex/subjects/MaybeSubjectTest.java index b2a62c894b..ae5e9ac449 100644 --- a/src/test/java/io/reactivex/subjects/MaybeSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/MaybeSubjectTest.java @@ -24,6 +24,7 @@ import io.reactivex.disposables.*; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class MaybeSubjectTest { @@ -265,7 +266,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; TestHelper.race(r1, r2); diff --git a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java index 7731d508f8..51582867c4 100644 --- a/src/test/java/io/reactivex/subjects/PublishSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/PublishSubjectTest.java @@ -29,6 +29,7 @@ import io.reactivex.exceptions.TestException; import io.reactivex.functions.*; import io.reactivex.observers.*; +import io.reactivex.testsupport.TestHelper; public class PublishSubjectTest extends SubjectTest { @@ -448,7 +449,7 @@ public void crossCancel() { @Override public void onNext(Integer t) { super.onNext(t); - to1.cancel(); + to1.dispose(); } }; @@ -471,7 +472,7 @@ public void crossCancelOnError() { @Override public void onError(Throwable t) { super.onError(t); - to1.cancel(); + to1.dispose(); } }; @@ -494,7 +495,7 @@ public void crossCancelOnComplete() { @Override public void onComplete() { super.onComplete(); - to1.cancel(); + to1.dispose(); } }; @@ -556,7 +557,7 @@ public void onComplete() { }); - to.cancel(); + to.dispose(); assertFalse(ps.hasObservers()); } @@ -601,7 +602,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java index 693fd9a6ee..28288ce4e5 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectBoundedConcurrencyTest.java @@ -26,8 +26,9 @@ import io.reactivex.Observer; import io.reactivex.disposables.Disposables; import io.reactivex.functions.Consumer; -import io.reactivex.observers.*; +import io.reactivex.observers.DefaultObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestObserverEx; public class ReplaySubjectBoundedConcurrencyTest { @@ -295,9 +296,9 @@ public void run() { public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertValueSequence(expected); to.assertTerminated(); } diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java index 67120c49bc..4059e427e4 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectConcurrencyTest.java @@ -26,8 +26,9 @@ import io.reactivex.Observer; import io.reactivex.disposables.Disposables; import io.reactivex.functions.Consumer; -import io.reactivex.observers.*; +import io.reactivex.observers.DefaultObserver; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestObserverEx; public class ReplaySubjectConcurrencyTest { @@ -295,9 +296,9 @@ public void run() { public void testRaceForTerminalState() { final List expected = Arrays.asList(1); for (int i = 0; i < 100000; i++) { - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); Observable.just(1).subscribeOn(Schedulers.computation()).cache().subscribe(to); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertValueSequence(expected); to.assertTerminated(); } diff --git a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java index aa91270226..333db59da6 100644 --- a/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java +++ b/src/test/java/io/reactivex/subjects/ReplaySubjectTest.java @@ -32,6 +32,7 @@ import io.reactivex.observers.*; import io.reactivex.schedulers.*; import io.reactivex.subjects.ReplaySubject.*; +import io.reactivex.testsupport.TestHelper; public class ReplaySubjectTest extends SubjectTest { @@ -881,7 +882,7 @@ public void hasSubscribers() { assertTrue(rp.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(rp.hasObservers()); } @@ -999,7 +1000,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -1059,14 +1060,14 @@ public void cancelRace() { Runnable r1 = new Runnable() { @Override public void run() { - to1.cancel(); + to1.dispose(); } }; Runnable r2 = new Runnable() { @Override public void run() { - to2.cancel(); + to2.dispose(); } }; diff --git a/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java b/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java index fad8557f2c..8948eaa3ee 100644 --- a/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/SerializedSubjectTest.java @@ -16,15 +16,16 @@ import static org.junit.Assert.*; import java.util.*; +import java.util.concurrent.TimeUnit; import org.junit.Test; import io.reactivex.Observable; -import io.reactivex.TestHelper; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.observers.*; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class SerializedSubjectTest { @@ -35,7 +36,7 @@ public void testBasic() { subject.subscribe(to); subject.onNext("hello"); subject.onComplete(); - to.awaitTerminalEvent(); + to.awaitDone(5, TimeUnit.SECONDS); to.assertValue("hello"); } @@ -415,10 +416,12 @@ public void normal() { @Test public void onNextOnNextRace() { + Set expectedSet = new HashSet(Arrays.asList(1, 2)); + for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final Subject s = PublishSubject.create().toSerialized(); - TestObserver to = s.test(); + TestObserverEx to = s.to(TestHelper.testConsumer()); Runnable r1 = new Runnable() { @Override @@ -436,8 +439,14 @@ public void run() { TestHelper.race(r1, r2); - to.assertSubscribed().assertNoErrors().assertNotComplete() - .assertValueSet(Arrays.asList(1, 2)); + to.assertSubscribed() + .assertNoErrors() + .assertNotComplete() + .assertValueCount(2) + ; + + Set actualSet = new HashSet(to.values()); + assertEquals("" + actualSet, expectedSet, actualSet); } } @@ -468,7 +477,7 @@ public void run() { to.assertError(ex).assertNotComplete(); - if (to.valueCount() != 0) { + if (to.values().size() != 0) { to.assertValue(1); } } @@ -499,7 +508,7 @@ public void run() { to.assertComplete().assertNoErrors(); - if (to.valueCount() != 0) { + if (to.values().size() != 0) { to.assertValue(1); } } diff --git a/src/test/java/io/reactivex/subjects/SingleSubjectTest.java b/src/test/java/io/reactivex/subjects/SingleSubjectTest.java index cdba1fe5c9..649dfca135 100644 --- a/src/test/java/io/reactivex/subjects/SingleSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/SingleSubjectTest.java @@ -24,6 +24,7 @@ import io.reactivex.disposables.*; import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class SingleSubjectTest { @@ -137,7 +138,7 @@ public void nullValue() { assertEquals("onSuccess called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } - ss.test().assertEmpty().cancel(); + ss.test().assertEmpty().dispose(); } @Test @@ -151,7 +152,7 @@ public void nullThrowable() { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } - ss.test().assertEmpty().cancel(); + ss.test().assertEmpty().dispose(); } @Test @@ -239,7 +240,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; TestHelper.race(r1, r2); diff --git a/src/test/java/io/reactivex/subjects/SubjectTest.java b/src/test/java/io/reactivex/subjects/SubjectTest.java index a50a17781b..ab455573a7 100644 --- a/src/test/java/io/reactivex/subjects/SubjectTest.java +++ b/src/test/java/io/reactivex/subjects/SubjectTest.java @@ -32,7 +32,7 @@ public void onNextNull() { assertEquals("onNext called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } - p.test().assertEmpty().cancel(); + p.test().assertEmpty().dispose(); } @Test @@ -46,6 +46,6 @@ public void onErrorNull() { assertEquals("onError called with null. Null values are generally not allowed in 2.x operators and sources.", ex.getMessage()); } - p.test().assertEmpty().cancel(); + p.test().assertEmpty().dispose(); } } diff --git a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java index ca13ba0495..92592b61da 100644 --- a/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java +++ b/src/test/java/io/reactivex/subjects/UnicastSubjectTest.java @@ -21,12 +21,13 @@ import org.junit.Test; -import io.reactivex.*; +import io.reactivex.Observable; import io.reactivex.disposables.*; import io.reactivex.exceptions.TestException; -import io.reactivex.internal.fuseable.*; -import io.reactivex.observers.*; +import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.observers.TestObserver; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class UnicastSubjectTest extends SubjectTest { @@ -39,13 +40,13 @@ protected Subject create() { public void fusionLive() { UnicastSubject ap = UnicastSubject.create(); - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); ap.subscribe(to); to - .assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)); + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC); to.assertNoValues().assertNoErrors().assertNotComplete(); @@ -64,13 +65,13 @@ public void fusionOfflie() { ap.onNext(1); ap.onComplete(); - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); ap.subscribe(to); to - .assertOf(ObserverFusion.assertFuseable()) - .assertOf(ObserverFusion.assertFusionMode(QueueFuseable.ASYNC)) + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) .assertResult(1); } @@ -120,7 +121,7 @@ public void fusionOfflineFailFast() { UnicastSubject ap = UnicastSubject.create(false); ap.onNext(1); ap.onError(new RuntimeException()); - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); ap.subscribe(to); to @@ -135,7 +136,7 @@ public void fusionOfflineFailFastMultipleEvents() { ap.onNext(2); ap.onNext(3); ap.onComplete(); - TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); ap.subscribe(to); to @@ -236,7 +237,7 @@ public void run() { Runnable r1 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -299,11 +300,11 @@ public void onErrorStatePeeking() { public void rejectSyncFusion() { UnicastSubject p = UnicastSubject.create(); - TestObserver to = ObserverFusion.newTest(QueueFuseable.SYNC); + TestObserverEx to = new TestObserverEx(QueueFuseable.SYNC); p.subscribe(to); - ObserverFusion.assertFusion(to, QueueFuseable.NONE); + to.assertFusionMode(QueueFuseable.NONE); } @Test @@ -333,7 +334,7 @@ public void fusedDrainCancel() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final UnicastSubject p = UnicastSubject.create(); - final TestObserver to = ObserverFusion.newTest(QueueFuseable.ANY); + final TestObserverEx to = new TestObserverEx(QueueFuseable.ANY); p.subscribe(to); @@ -347,7 +348,7 @@ public void run() { Runnable r2 = new Runnable() { @Override public void run() { - to.cancel(); + to.dispose(); } }; @@ -389,8 +390,8 @@ public void subscribeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final UnicastSubject us = UnicastSubject.create(); - final TestObserver to1 = new TestObserver(); - final TestObserver to2 = new TestObserver(); + final TestObserverEx to1 = new TestObserverEx(); + final TestObserverEx to2 = new TestObserverEx(); Runnable r1 = new Runnable() { @Override @@ -408,10 +409,10 @@ public void run() { TestHelper.race(r1, r2); - if (to1.errorCount() == 0) { + if (to1.errors().size() == 0) { to2.assertFailure(IllegalStateException.class); } else - if (to2.errorCount() == 0) { + if (to2.errors().size() == 0) { to1.assertFailure(IllegalStateException.class); } else { fail("Neither TestObserver failed"); @@ -429,7 +430,7 @@ public void hasObservers() { assertTrue(us.hasObservers()); - to.cancel(); + to.dispose(); assertFalse(us.hasObservers()); } @@ -438,7 +439,7 @@ public void hasObservers() { public void drainFusedFailFast() { UnicastSubject us = UnicastSubject.create(false); - TestObserver to = us.to(ObserverFusion.test(QueueFuseable.ANY, false)); + TestObserverEx to = us.to(TestHelper.testConsumer(QueueFuseable.ANY, false)); us.done = true; us.drainFused(to); @@ -450,7 +451,7 @@ public void drainFusedFailFast() { public void drainFusedFailFastEmpty() { UnicastSubject us = UnicastSubject.create(false); - TestObserver to = us.to(ObserverFusion.test(QueueFuseable.ANY, false)); + TestObserverEx to = us.to(TestHelper.testConsumer(QueueFuseable.ANY, false)); us.drainFused(to); diff --git a/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java b/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java index d6ec19dd7c..bda36687d8 100644 --- a/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/DisposableSubscriberTest.java @@ -23,6 +23,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class DisposableSubscriberTest { diff --git a/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java b/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java index bcaf51acf1..6bc769a018 100644 --- a/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/ResourceSubscriberTest.java @@ -25,6 +25,7 @@ import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.internal.util.EndConsumerHelper; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.TestHelper; public class ResourceSubscriberTest { diff --git a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java index 3ac4a19d7c..e7882dbc6c 100644 --- a/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SafeSubscriberTest.java @@ -14,6 +14,7 @@ package io.reactivex.subscribers; import static org.junit.Assert.*; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.util.List; @@ -27,6 +28,7 @@ import io.reactivex.exceptions.*; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; +import io.reactivex.testsupport.*; public class SafeSubscriberTest { @@ -674,7 +676,7 @@ public void onNextNull() { @Test public void onNextWithoutOnSubscribe() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); SafeSubscriber so = new SafeSubscriber(ts); @@ -685,7 +687,7 @@ public void onNextWithoutOnSubscribe() { @Test public void onErrorWithoutOnSubscribe() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); SafeSubscriber so = new SafeSubscriber(ts); @@ -699,7 +701,7 @@ public void onErrorWithoutOnSubscribe() { @Test public void onCompleteWithoutOnSubscribe() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); SafeSubscriber so = new SafeSubscriber(ts); diff --git a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java index c38105eb68..23b33ff095 100644 --- a/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/SerializedSubscriberTest.java @@ -24,11 +24,12 @@ import org.junit.*; import org.reactivestreams.*; -import io.reactivex.*; +import io.reactivex.Flowable; import io.reactivex.exceptions.TestException; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.*; public class SerializedSubscriberTest { @@ -274,7 +275,7 @@ public void testNotificationDelay() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch running = new CountDownLatch(2); - TestSubscriber ts = new TestSubscriber(new DefaultSubscriber() { + TestSubscriberEx ts = new TestSubscriberEx(new DefaultSubscriber() { @Override public void onComplete() { @@ -314,7 +315,7 @@ public void onNext(String t) { waitOnThreads(f1, f2); // not completed yet - assertEquals(2, ts.valueCount()); + assertEquals(2, ts.values().size()); Thread t2 = ts.lastThread(); System.out.println("second onNext on thread: " + t2); @@ -1086,7 +1087,7 @@ public void run() { .assertNoErrors() .assertComplete(); - assertTrue(ts.valueCount() <= 1); + assertTrue(ts.values().size() <= 1); } } @@ -1124,7 +1125,7 @@ public void run() { .assertError(ex) .assertNotComplete(); - assertTrue(ts.valueCount() <= 1); + assertTrue(ts.values().size() <= 1); } } @@ -1162,7 +1163,7 @@ public void run() { .assertError(ex) .assertNotComplete(); - assertTrue(ts.valueCount() <= 1); + assertTrue(ts.values().size() <= 1); } } @@ -1196,7 +1197,7 @@ public void onCompleteOnErrorRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { List errors = TestHelper.trackPluginErrors(); try { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final SerializedSubscriber so = new SerializedSubscriber(ts); @@ -1241,7 +1242,7 @@ public void run() { @Test public void nullOnNext() { - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); final SerializedSubscriber so = new SerializedSubscriber(ts); diff --git a/src/test/java/io/reactivex/subscribers/SubscriberFusion.java b/src/test/java/io/reactivex/subscribers/SubscriberFusion.java deleted file mode 100644 index 8ca323c5a3..0000000000 --- a/src/test/java/io/reactivex/subscribers/SubscriberFusion.java +++ /dev/null @@ -1,192 +0,0 @@ -/** - * Copyright (c) 2016-present, RxJava Contributors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in - * compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is - * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See - * the License for the specific language governing permissions and limitations under the License. - */ - -package io.reactivex.subscribers; - -import io.reactivex.*; -import io.reactivex.functions.Consumer; -import io.reactivex.internal.fuseable.QueueFuseable; - -/** - * Utility methods that return functional interfaces to support assertions regarding fusion - * in a TestSubscriber. - *

Don't move this class as it needs package-private access to TestSubscriber's internals. - */ -public enum SubscriberFusion { - ; - - /** - * Returns a function that takes a Flowable and returns a TestSubscriber that - * is set up according to the parameters and is subscribed to the Flowable. - *

- * Use this as follows: - *

-     * source
-     * .to(SubscriberFusion.test(0, QueueFuseable.ANY, false))
-     * .assertResult(0);
-     * 
- * @param the value type - * @param initialRequest the initial request amount, non-negative - * @param mode the fusion mode to request, see {@link QueueFuseable} constants. - * @param cancelled should the TestSubscriber cancelled before the subscription even happens? - * @return the new Function instance - */ - public static FlowableConverter> test( - final long initialRequest, final int mode, final boolean cancelled) { - return new TestFusionCheckConverter(mode, cancelled, initialRequest); - } - /** - * Returns a Consumer that asserts on its TestSubscriber parameter that - * the upstream is Fuseable (sent a QueueDisposable subclass in onSubscribe). - *

- * Use this as follows: - *

-     * source
-     * .to(ObserverFusion.test(0, QueueFuseable.ANY, false))
-     * .assertOf(ObserverFusion.assertFuseable());
-     * 
- * @param the value type - * @return the new Consumer instance - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Consumer> assertFuseable() { - return (Consumer)AssertFuseable.INSTANCE; - } - - static final class AssertFusionConsumer implements Consumer> { - private final int mode; - - AssertFusionConsumer(int mode) { - this.mode = mode; - } - - @Override - public void accept(TestSubscriber ts) throws Exception { - ts.assertFusionMode(mode); - } - } - - static final class TestFusionCheckConverter implements FlowableConverter> { - private final int mode; - private final boolean cancelled; - private final long initialRequest; - - TestFusionCheckConverter(int mode, boolean cancelled, long initialRequest) { - this.mode = mode; - this.cancelled = cancelled; - this.initialRequest = initialRequest; - } - - @Override - public TestSubscriber apply(Flowable t) { - TestSubscriber ts = new TestSubscriber(initialRequest); - ts.setInitialFusionMode(mode); - if (cancelled) { - ts.cancel(); - } - t.subscribe(ts); - return ts; - } - } - - enum AssertFuseable implements Consumer> { - INSTANCE; - @Override - public void accept(TestSubscriber ts) throws Exception { - ts.assertFuseable(); - } - } - - /** - * Returns a Consumer that asserts on its TestSubscriber parameter that - * the upstream is not Fuseable (didn't sent a QueueDisposable subclass in onSubscribe). - *

- * Use this as follows: - *

-     * source
-     * .to(ObserverFusion.test(0, QueueFuseable.ANY, false))
-     * .assertOf(ObserverFusion.assertNotFuseable());
-     * 
- * @param the value type - * @return the new Consumer instance - */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public static Consumer> assertNotFuseable() { - return (Consumer)AssertNotFuseable.INSTANCE; - } - - enum AssertNotFuseable implements Consumer> { - INSTANCE; - @Override - public void accept(TestSubscriber ts) throws Exception { - ts.assertNotFuseable(); - } - } - - /** - * Returns a Consumer that asserts on its TestSubscriber parameter that - * the upstream is Fuseable (sent a QueueFuseable.subclass in onSubscribe) - * and the established the given fusion mode. - *

- * Use this as follows: - *

-     * source
-     * .to(SubscriberFusion.test(0, QueueFuseable.ANY, false))
-     * .assertOf(SubscriberFusion.assertFusionMode(QueueFuseable.SYNC));
-     * 
- * @param the value type - * @param mode the expected established fusion mode, see {@link QueueFuseable} constants. - * @return the new Consumer instance - */ - public static Consumer> assertFusionMode(final int mode) { - return new AssertFusionConsumer(mode); - } - - /** - * Constructs a TestSubscriber with the given initial request and required fusion mode. - * @param the value type - * @param initialRequest the initial request, non-negative - * @param mode the requested fusion mode, see {@link QueueFuseable} constants - * @return the new TestSubscriber - */ - public static TestSubscriber newTest(long initialRequest, int mode) { - TestSubscriber ts = new TestSubscriber(initialRequest); - ts.setInitialFusionMode(mode); - return ts; - } - - /** - * Constructs a TestSubscriber with the given required fusion mode. - * @param the value type - * @param mode the requested fusion mode, see {@link QueueFuseable} constants - * @return the new TestSubscriber - */ - public static TestSubscriber newTest(int mode) { - TestSubscriber ts = new TestSubscriber(); - ts.setInitialFusionMode(mode); - return ts; - } - - /** - * Assert that the TestSubscriber received a fuseabe QueueFuseable.and - * is in the given fusion mode. - * @param the value type - * @param ts the TestSubscriber instance - * @param mode the expected mode - * @return the TestSubscriber - */ - public static TestSubscriber assertFusion(TestSubscriber ts, int mode) { - return ts.assertOf(SubscriberFusion.assertFuseable()) - .assertOf(SubscriberFusion.assertFusionMode(mode)); - } -} diff --git a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java index 6c634d8d91..1a6a0d9f32 100644 --- a/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java +++ b/src/test/java/io/reactivex/subscribers/TestSubscriberTest.java @@ -31,12 +31,10 @@ import io.reactivex.exceptions.*; import io.reactivex.functions.*; import io.reactivex.internal.functions.Functions; -import io.reactivex.internal.fuseable.QueueFuseable; import io.reactivex.internal.subscriptions.*; -import io.reactivex.observers.BaseTestConsumer; -import io.reactivex.observers.BaseTestConsumer.TestWaitStrategy; -import io.reactivex.processors.*; +import io.reactivex.processors.PublishProcessor; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; public class TestSubscriberTest { @@ -51,7 +49,8 @@ public void testAssert() { ts.assertValues(1, 2); ts.assertValueCount(2); - ts.assertTerminated(); + ts.assertComplete(); + ts.assertNoErrors(); } @Test @@ -66,7 +65,8 @@ public void testAssertNotMatchCount() { ts.assertValues(1); ts.assertValueCount(2); - ts.assertTerminated(); + ts.assertComplete(); + ts.assertNoErrors(); } @Test @@ -81,65 +81,8 @@ public void testAssertNotMatchValue() { ts.assertValues(1, 3); ts.assertValueCount(2); - ts.assertTerminated(); - } - - @Test - public void assertNeverAtNotMatchingValue() { - Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber ts = new TestSubscriber(); - oi.subscribe(ts); - - ts.assertNever(3); - ts.assertValueCount(2); - ts.assertTerminated(); - } - - @Test - public void assertNeverAtMatchingValue() { - Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); - TestSubscriber ts = new TestSubscriber(); - oi.subscribe(ts); - - ts.assertValues(1, 2); - - thrown.expect(AssertionError.class); - - ts.assertNever(2); - ts.assertValueCount(2); - ts.assertTerminated(); - } - - @Test - public void assertNeverAtMatchingPredicate() { - TestSubscriber ts = new TestSubscriber(); - - Flowable.just(1, 2).subscribe(ts); - - ts.assertValues(1, 2); - - thrown.expect(AssertionError.class); - - ts.assertNever(new Predicate() { - @Override - public boolean test(final Integer o) throws Exception { - return o == 1; - } - }); - } - - @Test - public void assertNeverAtNotMatchingPredicate() { - TestSubscriber ts = new TestSubscriber(); - - Flowable.just(2, 3).subscribe(ts); - - ts.assertNever(new Predicate() { - @Override - public boolean test(final Integer o) throws Exception { - return o == 1; - } - }); + ts.assertComplete(); + ts.assertNoErrors(); } @Test @@ -157,7 +100,8 @@ public void testAssertTerminalEventNotReceived() { ts.assertValues(1, 2); ts.assertValueCount(2); - ts.assertTerminated(); + ts.assertComplete(); + ts.assertNoErrors(); } @Test @@ -199,8 +143,9 @@ public void testAssertError() { public void testAwaitTerminalEventWithDuration() { TestSubscriber ts = new TestSubscriber(); Flowable.just(1).subscribe(ts); - ts.awaitTerminalEvent(1, TimeUnit.SECONDS); - ts.assertTerminated(); + ts.awaitDone(1, TimeUnit.SECONDS); + ts.assertComplete(); + ts.assertNoErrors(); } @Test @@ -217,7 +162,7 @@ public void run() { }) // .delay(1000, TimeUnit.MILLISECONDS).subscribe(ts); - ts.awaitTerminalEvent(100, TimeUnit.MILLISECONDS); + ts.awaitDone(100, TimeUnit.MILLISECONDS); ts.dispose(); assertTrue(unsub.get()); } @@ -248,7 +193,8 @@ public void testDelegate1() { TestSubscriber ts = new TestSubscriber(ts0); ts.onComplete(); - ts0.assertTerminated(); + ts0.assertComplete(); + ts0.assertNoErrors(); } @Test @@ -549,13 +495,11 @@ public void run() { }, 200, TimeUnit.MILLISECONDS); try { - if (ts.awaitTerminalEvent()) { + if (ts.await(5, TimeUnit.SECONDS)) { fail("Did not interrupt wait!"); } - } catch (RuntimeException ex) { - if (!(ex.getCause() instanceof InterruptedException)) { - fail("The cause is not InterruptedException! " + ex.getCause()); - } + } catch (InterruptedException expected) { + // expected } } finally { w.dispose(); @@ -577,13 +521,11 @@ public void run() { }, 200, TimeUnit.MILLISECONDS); try { - if (ts.awaitTerminalEvent(5, TimeUnit.SECONDS)) { + if (ts.await(5, TimeUnit.SECONDS)) { fail("Did not interrupt wait!"); } - } catch (RuntimeException ex) { - if (!(ex.getCause() instanceof InterruptedException)) { - fail("The cause is not InterruptedException! " + ex.getCause()); - } + } catch (InterruptedException expected) { + // expected } } finally { Thread.interrupted(); // clear interrupted flag @@ -605,7 +547,11 @@ public void run() { } }, 200, TimeUnit.MILLISECONDS); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } ts.dispose(); if (!ts.isCancelled()) { fail("Did not unsubscribe!"); @@ -622,7 +568,7 @@ public void testNoTerminalEventBut1Completed() { ts.onComplete(); try { - ts.assertNotTerminated(); + ts.assertNotComplete(); throw new RuntimeException("Failed to report there were terminal event(s)!"); } catch (AssertionError ex) { // expected @@ -636,7 +582,7 @@ public void testNoTerminalEventBut1Error() { ts.onError(new TestException()); try { - ts.assertNotTerminated(); + ts.assertNoErrors(); throw new RuntimeException("Failed to report there were terminal event(s)!"); } catch (AssertionError ex) { // expected @@ -644,14 +590,21 @@ public void testNoTerminalEventBut1Error() { } @Test - public void testNoTerminalEventBut1Error1Completed() { + public void noTerminalEventBut1Error1Complete() { TestSubscriber ts = new TestSubscriber(); ts.onComplete(); ts.onError(new TestException()); try { - ts.assertNotTerminated(); + ts.assertNotComplete(); + throw new RuntimeException("Failed to report there were terminal event(s)!"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertNoErrors(); throw new RuntimeException("Failed to report there were terminal event(s)!"); } catch (AssertionError ex) { // expected @@ -667,7 +620,7 @@ public void testNoTerminalEventBut2Errors() { ts.onError(new TestException()); try { - ts.assertNotTerminated(); + ts.assertNoErrors(); throw new RuntimeException("Failed to report there were terminal event(s)!"); } catch (AssertionError ex) { // expected @@ -723,7 +676,7 @@ public void onComplete() { // expected } - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); } @Test(timeout = 1000) @@ -742,7 +695,7 @@ public void onError(Throwable e) { // expected } - ts.awaitTerminalEvent(); + ts.awaitDone(5, TimeUnit.SECONDS); } @Test @@ -751,19 +704,10 @@ public void createDelegate() { TestSubscriber ts = TestSubscriber.create(ts1); - ts.assertNotSubscribed(); - assertFalse(ts.hasSubscription()); ts.onSubscribe(new BooleanSubscription()); - try { - ts.assertNotSubscribed(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - assertTrue(ts.hasSubscription()); assertFalse(ts.isDisposed()); @@ -778,10 +722,6 @@ public void createDelegate() { assertTrue(ts.isDisposed()); - assertTrue(ts.isTerminated()); - - assertSame(Thread.currentThread(), ts.lastThread()); - try { ts.assertNoValues(); throw new RuntimeException("Should have thrown"); @@ -804,16 +744,6 @@ public void createDelegate() { } catch (AssertionError exc) { // expected } - - ts.assertValueSet(Collections.singleton(1)); - - try { - ts.assertValueSet(Collections.singleton(2)); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - } @Test @@ -834,13 +764,6 @@ public void assertError() { // expected } - try { - ts.assertErrorMessage(""); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - try { ts.assertError(Functions.alwaysTrue()); throw new RuntimeException("Should have thrown"); @@ -855,13 +778,6 @@ public void assertError() { // expected } - try { - ts.assertTerminated(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - ts.onSubscribe(new BooleanSubscription()); ts.assertSubscribed(); @@ -876,8 +792,6 @@ public void assertError() { ts.assertError(TestException.class); - ts.assertErrorMessage("Forced failure"); - ts.assertError(Functions.alwaysTrue()); ts.assertError(new Predicate() { @@ -887,13 +801,6 @@ public boolean test(Throwable t) { } }); - try { - ts.assertErrorMessage(""); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError exc) { - // expected - } - try { ts.assertError(new RuntimeException()); throw new RuntimeException("Should have thrown"); @@ -922,8 +829,6 @@ public boolean test(Throwable t) { // expected } - ts.assertTerminated(); - ts.assertValueCount(0); ts.assertNoValues(); @@ -951,115 +856,9 @@ public void assertFailure() { ts.assertFailure(TestException.class); - ts.assertFailure(Functions.alwaysTrue()); - - ts.assertFailureAndMessage(TestException.class, "Forced failure"); - ts.onNext(1); ts.assertFailure(TestException.class, 1); - - ts.assertFailure(Functions.alwaysTrue(), 1); - - ts.assertFailureAndMessage(TestException.class, "Forced failure", 1); - } - - @Test - public void assertFuseable() { - TestSubscriber ts = TestSubscriber.create(); - - ts.onSubscribe(new BooleanSubscription()); - - ts.assertNotFuseable(); - - try { - ts.assertFuseable(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - try { - ts.assertFusionMode(QueueFuseable.SYNC); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - ts = TestSubscriber.create(); - ts.setInitialFusionMode(QueueFuseable.ANY); - - ts.onSubscribe(new ScalarSubscription(ts, 1)); - - ts.assertFuseable(); - - ts.assertFusionMode(QueueFuseable.SYNC); - - try { - ts.assertFusionMode(QueueFuseable.NONE); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - try { - ts.assertNotFuseable(); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - } - - @Test - public void assertTerminated() { - TestSubscriber ts = TestSubscriber.create(); - - ts.assertNotTerminated(); - - ts.onError(null); - - try { - ts.assertNotTerminated(); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertOf() { - TestSubscriber ts = TestSubscriber.create(); - - ts.assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber f) throws Exception { - f.assertNotSubscribed(); - } - }); - - try { - ts.assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber f) throws Exception { - f.assertSubscribed(); - } - }); - throw new RuntimeException("Should have thrown"); - } catch (AssertionError ex) { - // expected - } - - try { - ts.assertOf(new Consumer>() { - @Override - public void accept(TestSubscriber f) throws Exception { - throw new IllegalArgumentException(); - } - }); - throw new RuntimeException("Should have thrown"); - } catch (IllegalArgumentException ex) { - // expected - } } @Test @@ -1111,10 +910,10 @@ public void await() throws Exception { assertTrue(ts.isDisposed()); - assertFalse(ts.awaitTerminalEvent(100, TimeUnit.MILLISECONDS)); + assertFalse(ts.await(100, TimeUnit.MILLISECONDS)); - assertEquals(0, ts.completions()); - assertEquals(0, ts.errorCount()); + ts.assertNoErrors(); + ts.assertNotComplete(); ts.onComplete(); @@ -1124,10 +923,10 @@ public void await() throws Exception { ts.awaitDone(5, TimeUnit.SECONDS); - assertEquals(1, ts.completions()); - assertEquals(0, ts.errorCount()); + ts.assertComplete(); + ts.assertNoErrors(); - assertTrue(ts.awaitTerminalEvent()); + assertTrue(ts.await(5, TimeUnit.SECONDS)); final TestSubscriber ts1 = TestSubscriber.create(); @@ -1141,33 +940,15 @@ public void run() { }, 200, TimeUnit.MILLISECONDS); ts1.await(); - - ts1.assertValueSet(Collections.emptySet()); } - @Test - public void errors() { - TestSubscriber ts = TestSubscriber.create(); - - ts.onSubscribe(new BooleanSubscription()); - - assertEquals(0, ts.errors().size()); - - ts.onError(new TestException()); - - assertEquals(1, ts.errors().size()); - - TestHelper.assertError(ts.errors(), 0, TestException.class); - } - - @SuppressWarnings("unchecked") @Test public void onNext() { TestSubscriber ts = TestSubscriber.create(); ts.onSubscribe(new BooleanSubscription()); - assertEquals(0, ts.valueCount()); + ts.assertNoValues(); assertEquals(Collections.emptyList(), ts.values()); @@ -1182,19 +963,7 @@ public void onNext() { ts.assertValue(1); - assertEquals(Arrays.asList(Collections.singletonList(1), Collections.emptyList(), Collections.emptyList()), ts.getEvents()); - ts.onComplete(); - - assertEquals(Arrays.asList(Collections.singletonList(1), Collections.emptyList(), Collections.singletonList(Notification.createOnComplete())), ts.getEvents()); - } - - @Test - public void fusionModeToString() { - assertEquals("NONE", TestSubscriber.fusionModeToString(QueueFuseable.NONE)); - assertEquals("SYNC", TestSubscriber.fusionModeToString(QueueFuseable.SYNC)); - assertEquals("ASYNC", TestSubscriber.fusionModeToString(QueueFuseable.ASYNC)); - assertEquals("Unknown(100)", TestSubscriber.fusionModeToString(100)); } @Test @@ -1214,7 +983,7 @@ public void multipleTerminals() { // expected } - ts.assertTerminated(); + ts.assertComplete(); ts.onComplete(); @@ -1226,7 +995,7 @@ public void multipleTerminals() { } try { - ts.assertTerminated(); + ts.assertComplete(); throw new RuntimeException("Should have thrown"); } catch (Throwable ex) { // expected @@ -1299,15 +1068,25 @@ public void awaitTerminalEventInterrupt() { Thread.currentThread().interrupt(); - ts.awaitTerminalEvent(); + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } - assertTrue(Thread.interrupted()); + // FIXME ? catch consumes this flag + // assertTrue(Thread.interrupted()); Thread.currentThread().interrupt(); - ts.awaitTerminalEvent(5, TimeUnit.SECONDS); + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } - assertTrue(Thread.interrupted()); + // FIXME ? catch consumes this flag + // assertTrue(Thread.interrupted()); } @Test @@ -1316,15 +1095,16 @@ public void assertTerminated2() { ts.onSubscribe(new BooleanSubscription()); - assertFalse(ts.isTerminated()); + ts.assertNotComplete().assertNoErrors(); ts.onError(new TestException()); - ts.onError(new IOException()); - assertTrue(ts.isTerminated()); + ts.assertError(TestException.class); + + ts.onError(new IOException()); try { - ts.assertTerminated(); + ts.assertNoErrors(); throw new RuntimeException("Should have thrown"); } catch (AssertionError ex) { // expected @@ -1345,7 +1125,16 @@ public void assertTerminated2() { ts.onComplete(); try { - ts.assertTerminated(); + ts.assertComplete() + .assertNoErrors(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertError(Throwable.class) + .assertNotComplete(); throw new RuntimeException("Should have thrown"); } catch (AssertionError ex) { // expected @@ -1454,29 +1243,13 @@ public void awaitDoneTimed() { } } - @Test - public void assertNotSubscribed() { - TestSubscriber ts = new TestSubscriber(); - - ts.assertNotSubscribed(); - - ts.errors().add(new TestException()); - - try { - ts.assertNotSubscribed(); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - // expected - } - } - @Test public void assertErrorMultiple() { TestSubscriber ts = new TestSubscriber(); TestException e = new TestException(); - ts.errors().add(e); - ts.errors().add(new TestException()); + ts.onError(e); + ts.onError(new TestException()); try { ts.assertError(TestException.class); @@ -1490,12 +1263,6 @@ public void assertErrorMultiple() { } catch (AssertionError ex) { // expected } - try { - ts.assertErrorMessage(""); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - // expected - } } @Test @@ -1535,7 +1302,7 @@ public void completeWithoutOnSubscribe() { } @Test - public void completeDelegateThrows() { + public void completeDelegateThrows() throws Exception { TestSubscriber ts = new TestSubscriber(new FlowableSubscriber() { @Override @@ -1566,12 +1333,12 @@ public void onComplete() { ts.onComplete(); throw new RuntimeException("Should have thrown!"); } catch (TestException ex) { - assertTrue(ts.isTerminated()); + assertTrue(ts.await(1, TimeUnit.SECONDS)); } } @Test - public void errorDelegateThrows() { + public void errorDelegateThrows() throws Exception { TestSubscriber ts = new TestSubscriber(new FlowableSubscriber() { @Override @@ -1602,50 +1369,10 @@ public void onComplete() { ts.onError(new IOException()); throw new RuntimeException("Should have thrown!"); } catch (TestException ex) { - assertTrue(ts.isTerminated()); + assertTrue(ts.await(1, TimeUnit.SECONDS)); } } - @Test - public void syncQueueThrows() { - TestSubscriber ts = new TestSubscriber(); - ts.setInitialFusionMode(QueueFuseable.SYNC); - - Flowable.range(1, 5) - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { throw new TestException(); } - }) - .subscribe(ts); - - ts.assertSubscribed() - .assertFuseable() - .assertFusionMode(QueueFuseable.SYNC) - .assertFailure(TestException.class); - } - - @Test - public void asyncQueueThrows() { - TestSubscriber ts = new TestSubscriber(); - ts.setInitialFusionMode(QueueFuseable.ANY); - - UnicastProcessor up = UnicastProcessor.create(); - - up - .map(new Function() { - @Override - public Object apply(Integer v) throws Exception { throw new TestException(); } - }) - .subscribe(ts); - - up.onNext(1); - - ts.assertSubscribed() - .assertFuseable() - .assertFusionMode(QueueFuseable.ASYNC) - .assertFailure(TestException.class); - } - @Test public void assertValuePredicateEmpty() { TestSubscriber ts = new TestSubscriber(); @@ -1824,7 +1551,7 @@ public void timeoutIndicated2() throws InterruptedException { public void timeoutIndicated3() throws InterruptedException { TestSubscriber ts = Flowable.never() .test(); - assertFalse(ts.awaitTerminalEvent(1, TimeUnit.MILLISECONDS)); + assertFalse(ts.await(1, TimeUnit.MILLISECONDS)); try { ts.assertResult(1); @@ -1847,11 +1574,6 @@ public void disposeIndicated() { } } - @Test - public void checkTestWaitStrategyEnum() { - TestHelper.checkEnum(BaseTestConsumer.TestWaitStrategy.class); - } - @Test public void awaitCount() { Flowable.range(1, 10).delay(100, TimeUnit.MILLISECONDS) @@ -1871,102 +1593,6 @@ public void awaitCountLess() { .assertResult(1, 2, 3, 4); } - @Test - public void awaitCountLess2() { - Flowable.range(1, 4) - .test() - .awaitCount(5, TestWaitStrategy.YIELD) - .assertResult(1, 2, 3, 4); - } - - @Test - public void awaitCountLess3() { - Flowable.range(1, 4).delay(50, TimeUnit.MILLISECONDS) - .test() - .awaitCount(5, TestWaitStrategy.SLEEP_1MS) - .assertResult(1, 2, 3, 4); - } - - @Test - public void interruptTestWaitStrategy() { - try { - Thread.currentThread().interrupt(); - TestWaitStrategy.SLEEP_1000MS.run(); - } catch (RuntimeException ex) { - assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); - } - } - - @Test - public void awaitCountTimeout() { - TestSubscriber ts = Flowable.never() - .test() - .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50); - - assertTrue(ts.isTimeout()); - ts.clearTimeout(); - assertFalse(ts.isTimeout()); - } - - @Test - public void assertTimeout() { - Flowable.never() - .test() - .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50) - .assertTimeout(); - } - - @Test - public void assertTimeout2() { - try { - Flowable.empty() - .test() - .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50) - .assertTimeout(); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - assertTrue(ex.toString(), ex.getMessage().contains("No timeout?!")); - } - } - - @Test - public void assertNoTimeout() { - Flowable.just(1) - .test() - .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50) - .assertNoTimeout(); - } - - @Test - public void assertNoTimeout2() { - try { - Flowable.never() - .test() - .awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50) - .assertNoTimeout(); - throw new RuntimeException("Should have thrown!"); - } catch (AssertionError ex) { - assertTrue(ex.toString(), ex.getMessage().contains("Timeout?!")); - } - } - - @Test - public void assertNeverPredicateThrows() { - try { - Flowable.just(1) - .test() - .assertNever(new Predicate() { - @Override - public boolean test(Integer t) throws Exception { - throw new IllegalArgumentException(); - } - }); - throw new RuntimeException("Should have thrown!"); - } catch (IllegalArgumentException ex) { - // expected - } - } - @Test public void assertValueAtPredicateThrows() { try { @@ -1984,13 +1610,6 @@ public boolean test(Integer t) throws Exception { } } - @Test - public void waitStrategyRuns() { - for (TestWaitStrategy ws : TestWaitStrategy.values()) { - ws.run(); - } - } - @Test public void assertValuesOnly() { TestSubscriber ts = TestSubscriber.create(); @@ -2052,168 +1671,4 @@ public void assertValuesOnlyThrowsWhenErrored() { // expected } } - - @Test - public void assertValueSetOnly() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - ts.assertValueSetOnly(Collections.emptySet()); - - ts.onNext(5); - ts.assertValueSetOnly(Collections.singleton(5)); - - ts.onNext(-1); - ts.assertValueSetOnly(new HashSet(Arrays.asList(5, -1))); - } - - @Test - public void assertValueSetOnlyThrowsOnUnexpectedValue() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - ts.assertValueSetOnly(Collections.emptySet()); - - ts.onNext(5); - ts.assertValueSetOnly(Collections.singleton(5)); - - ts.onNext(-1); - - try { - ts.assertValueSetOnly(Collections.singleton(5)); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSetOnlyThrowsWhenCompleted() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - - ts.onComplete(); - - try { - ts.assertValueSetOnly(Collections.emptySet()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSetOnlyThrowsWhenErrored() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - - ts.onError(new TestException()); - - try { - ts.assertValueSetOnly(Collections.emptySet()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSequenceOnly() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - ts.assertValueSequenceOnly(Collections.emptyList()); - - ts.onNext(5); - ts.assertValueSequenceOnly(Collections.singletonList(5)); - - ts.onNext(-1); - ts.assertValueSequenceOnly(Arrays.asList(5, -1)); - } - - @Test - public void assertValueSequenceOnlyThrowsOnUnexpectedValue() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - ts.assertValueSequenceOnly(Collections.emptyList()); - - ts.onNext(5); - ts.assertValueSequenceOnly(Collections.singletonList(5)); - - ts.onNext(-1); - - try { - ts.assertValueSequenceOnly(Collections.singletonList(5)); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSequenceOnlyThrowsWhenCompleted() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - - ts.onComplete(); - - try { - ts.assertValueSequenceOnly(Collections.emptyList()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test - public void assertValueSequenceOnlyThrowsWhenErrored() { - TestSubscriber ts = TestSubscriber.create(); - ts.onSubscribe(new BooleanSubscription()); - - ts.onError(new TestException()); - - try { - ts.assertValueSequenceOnly(Collections.emptyList()); - throw new RuntimeException(); - } catch (AssertionError ex) { - // expected - } - } - - @Test(timeout = 1000) - public void awaitCount0() { - TestSubscriber ts = TestSubscriber.create(); - ts.awaitCount(0, TestWaitStrategy.SLEEP_1MS, 0); - } - - @Test - public void assertValueSetWiderSet() { - Set set = new HashSet(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7)); - - Flowable.just(4, 5, 1, 3, 2) - .test() - .assertValueSet(set); - } - - @Test - public void assertValueSetExact() { - Set set = new HashSet(Arrays.asList(1, 2, 3, 4, 5)); - - Flowable.just(4, 5, 1, 3, 2) - .test() - .assertValueSet(set) - .assertValueCount(set.size()); - } - - @Test - public void assertValueSetMissing() { - Set set = new HashSet(Arrays.asList(0, 1, 2, 4, 5, 6, 7)); - - try { - Flowable.range(1, 5) - .test() - .assertValueSet(set); - - throw new RuntimeException("Should have failed"); - } catch (AssertionError ex) { - assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3)); - } - } } diff --git a/src/test/java/io/reactivex/testsupport/BaseTestConsumerEx.java b/src/test/java/io/reactivex/testsupport/BaseTestConsumerEx.java new file mode 100644 index 0000000000..e36d13bfb8 --- /dev/null +++ b/src/test/java/io/reactivex/testsupport/BaseTestConsumerEx.java @@ -0,0 +1,303 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.testsupport; + +import java.util.List; + +import io.reactivex.functions.Predicate; +import io.reactivex.internal.functions.ObjectHelper; +import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.internal.util.ExceptionHelper; +import io.reactivex.observers.BaseTestConsumer; + +/** + * Base class with shared infrastructure to support TestSubscriber and TestObserver. + * @param the value type consumed + * @param the subclass of this BaseTestConsumer + */ +public abstract class BaseTestConsumerEx> +extends BaseTestConsumer { + + protected int initialFusionMode; + + protected int establishedFusionMode; + + /** + * The optional tag associated with this test consumer. + * @since 2.0.7 + */ + protected CharSequence tag; + + /** + * Indicates that one of the awaitX method has timed out. + * @since 2.0.7 + */ + protected boolean timeout; + + public BaseTestConsumerEx() { + super(); + } + + /** + * Returns the last thread which called the onXXX methods of this TestObserver/TestSubscriber. + * @return the last thread which called the onXXX methods + */ + public final Thread lastThread() { + return lastThread; + } + + // assertion methods + + /** + * Assert that this TestObserver/TestSubscriber did not receive an onNext value which is equal to + * the given value with respect to null-safe Object.equals. + * + *

History: 2.0.5 - experimental + * @param value the value to expect not being received + * @return this + * @since 2.1 + */ + @SuppressWarnings("unchecked") + public final U assertNever(T value) { + int s = values.size(); + + for (int i = 0; i < s; i++) { + T v = this.values.get(i); + if (ObjectHelper.equals(v, value)) { + throw fail("Value at position " + i + " is equal to " + valueAndClass(value) + "; Expected them to be different"); + } + } + return (U) this; + } + + /** + * Asserts that this TestObserver/TestSubscriber did not receive any onNext value for which + * the provided predicate returns true. + * + *

History: 2.0.5 - experimental + * @param valuePredicate the predicate that receives the onNext value + * and should return true for the expected value. + * @return this + * @since 2.1 + */ + @SuppressWarnings("unchecked") + public final U assertNever(Predicate valuePredicate) { + int s = values.size(); + + for (int i = 0; i < s; i++) { + T v = this.values.get(i); + try { + if (valuePredicate.test(v)) { + throw fail("Value at position " + i + " matches predicate " + valuePredicate.toString() + ", which was not expected."); + } + } catch (Throwable ex) { + throw ExceptionHelper.wrapOrThrow(ex); + } + } + return (U)this; + } + + /** + * Assert that the TestObserver/TestSubscriber terminated (i.e., the terminal latch reached zero). + * @return this + */ + @SuppressWarnings("unchecked") + public final U assertTerminated() { + if (done.getCount() != 0) { + throw fail("Subscriber still running!"); + } + long c = completions; + if (c > 1) { + throw fail("Terminated with multiple completions: " + c); + } + int s = errors.size(); + if (s > 1) { + throw fail("Terminated with multiple errors: " + s); + } + + if (c != 0 && s != 0) { + throw fail("Terminated with multiple completions and errors: " + c); + } + return (U)this; + } + + /** + * Assert that the TestObserver/TestSubscriber has not terminated (i.e., the terminal latch is still non-zero). + * @return this + */ + @SuppressWarnings("unchecked") + public final U assertNotTerminated() { + if (done.getCount() == 0) { + throw fail("Subscriber terminated!"); + } + return (U)this; + } + + /** + * Assert that there is a single error and it has the given message. + * @param message the message expected + * @return this + */ + @SuppressWarnings("unchecked") + public final U assertErrorMessage(String message) { + int s = errors.size(); + if (s == 0) { + throw fail("No errors"); + } else + if (s == 1) { + Throwable e = errors.get(0); + String errorMessage = e.getMessage(); + if (!ObjectHelper.equals(message, errorMessage)) { + throw fail("Error message differs; exptected: " + message + " but was: " + errorMessage); + } + } else { + throw fail("Multiple errors"); + } + return (U)this; + } + + /** + * Assert that the upstream signalled the specified values in order and then failed + * with a Throwable for which the provided predicate returns true. + * @param errorPredicate + * the predicate that receives the error Throwable + * and should return true for expected errors. + * @param values the expected values, asserted in order + * @return this + */ + public final U assertFailure(Predicate errorPredicate, T... values) { + return assertSubscribed() + .assertValues(values) + .assertError(errorPredicate) + .assertNotComplete(); + } + + /** + * Assert that the upstream signalled the specified values in order, + * then failed with a specific class or subclass of Throwable + * and with the given exact error message. + * @param error the expected exception (parent) class + * @param message the expected failure message + * @param values the expected values, asserted in order + * @return this + */ + public final U assertFailureAndMessage(Class error, + String message, T... values) { + return assertSubscribed() + .assertValues(values) + .assertError(error) + .assertErrorMessage(message) + .assertNotComplete(); + } + + /** + * Returns true if an await timed out. + * @return true if one of the timeout-based await methods has timed out. + *

History: 2.0.7 - experimental + * @see #clearTimeout() + * @see #assertTimeout() + * @see #assertNoTimeout() + * @since 2.1 + */ + public final boolean isTimeout() { + return timeout; + } + + /** + * Clears the timeout flag set by the await methods when they timed out. + *

History: 2.0.7 - experimental + * @return this + * @since 2.1 + * @see #isTimeout() + */ + @SuppressWarnings("unchecked") + public final U clearTimeout() { + timeout = false; + return (U)this; + } + + /** + * Asserts that some awaitX method has timed out. + *

History: 2.0.7 - experimental + * @return this + * @since 2.1 + */ + @SuppressWarnings("unchecked") + public final U assertTimeout() { + if (!timeout) { + throw fail("No timeout?!"); + } + return (U)this; + } + + /** + * Asserts that some awaitX method has not timed out. + *

History: 2.0.7 - experimental + * @return this + * @since 2.1 + */ + @SuppressWarnings("unchecked") + public final U assertNoTimeout() { + if (timeout) { + throw fail("Timeout?!"); + } + return (U)this; + } + + /** + * Returns the internal shared list of errors. + * @return Returns the internal shared list of errors. + */ + public final List errors() { + return errors; + } + + /** + * Returns true if this test consumer has terminated in any fashion. + * @return true if this test consumer has terminated in any fashion + */ + public final boolean isTerminated() { + return done.getCount() == 0; + } + + /** + * Returns the number of times onComplete() was called. + * @return the number of times onComplete() was called + */ + public final long completions() { + return completions; + } + + /** + * Fail with the given message and add the sequence of errors as suppressed ones. + *

Note this is deliberately the only fail method. Most of the times an assertion + * would fail but it is possible it was due to an exception somewhere. This construct + * will capture those potential errors and report it along with the original failure. + * + * @param message the message to use + * @return AssertionError the prepared AssertionError instance + */ + public final AssertionError failWith(String message) { + return fail(message); + } + + static String fusionModeToString(int mode) { + switch (mode) { + case QueueFuseable.NONE : return "NONE"; + case QueueFuseable.SYNC : return "SYNC"; + case QueueFuseable.ASYNC : return "ASYNC"; + default: return "Unknown(" + mode + ")"; + } + } +} diff --git a/src/test/java/io/reactivex/TestHelper.java b/src/test/java/io/reactivex/testsupport/TestHelper.java similarity index 93% rename from src/test/java/io/reactivex/TestHelper.java rename to src/test/java/io/reactivex/testsupport/TestHelper.java index 018b4e61ef..07ce95fb15 100644 --- a/src/test/java/io/reactivex/TestHelper.java +++ b/src/test/java/io/reactivex/testsupport/TestHelper.java @@ -11,7 +11,7 @@ * the License for the specific language governing permissions and limitations under the License. */ -package io.reactivex; +package io.reactivex.testsupport; import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; @@ -27,6 +27,9 @@ import org.mockito.stubbing.Answer; import org.reactivestreams.*; +import io.reactivex.*; +import io.reactivex.Observable; +import io.reactivex.Observer; import io.reactivex.disposables.*; import io.reactivex.exceptions.*; import io.reactivex.functions.*; @@ -37,7 +40,7 @@ import io.reactivex.internal.operators.single.SingleToFlowable; import io.reactivex.internal.subscriptions.BooleanSubscription; import io.reactivex.internal.util.ExceptionHelper; -import io.reactivex.observers.TestObserver; +import io.reactivex.observers.BaseTestConsumer; import io.reactivex.parallel.ParallelFlowable; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.processors.PublishProcessor; @@ -46,7 +49,7 @@ import io.reactivex.subscribers.TestSubscriber; /** - * Common methods for helping with tests from 1.x mostly. + * Common methods for helping with tests. */ public enum TestHelper { ; @@ -217,7 +220,7 @@ public static void assertUndeliverable(List list, int index, Class to, int index, Class clazz) { + public static void assertError(TestObserverEx to, int index, Class clazz) { Throwable ex = to.errors().get(0); try { if (ex instanceof CompositeException) { @@ -233,7 +236,7 @@ public static void assertError(TestObserver to, int index, Class ts, int index, Class clazz) { + public static void assertError(TestSubscriberEx ts, int index, Class clazz) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; @@ -244,7 +247,7 @@ public static void assertError(TestSubscriber ts, int index, Class to, int index, Class clazz, String message) { + public static void assertError(TestObserverEx to, int index, Class clazz, String message) { Throwable ex = to.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; @@ -256,7 +259,7 @@ public static void assertError(TestObserver to, int index, Class ts, int index, Class clazz, String message) { + public static void assertError(TestSubscriberEx ts, int index, Class clazz, String message) { Throwable ex = ts.errors().get(0); if (ex instanceof CompositeException) { CompositeException ce = (CompositeException) ex; @@ -481,52 +484,6 @@ public static > void checkEnum(Class enumClass) { } } - /** - * Returns an Consumer that asserts the TestSubscriber has exactly one value + completed - * normally and that single value is not the value specified. - * @param the value type - * @param value the value not expected - * @return the consumer - */ - public static Consumer> subscriberSingleNot(final T value) { - return new Consumer>() { - @Override - public void accept(TestSubscriber ts) throws Exception { - ts - .assertSubscribed() - .assertValueCount(1) - .assertNoErrors() - .assertComplete(); - - T v = ts.values().get(0); - assertNotEquals(value, v); - } - }; - } - - /** - * Returns an Consumer that asserts the TestObserver has exactly one value + completed - * normally and that single value is not the value specified. - * @param the value type - * @param value the value not expected - * @return the consumer - */ - public static Consumer> observerSingleNot(final T value) { - return new Consumer>() { - @Override - public void accept(TestObserver to) throws Exception { - to - .assertSubscribed() - .assertValueCount(1) - .assertNoErrors() - .assertComplete(); - - T v = to.values().get(0); - assertNotEquals(value, v); - } - }; - } - /** * Calls onSubscribe twice and checks if it doesn't affect the first Subscription while * reporting it to plugin error handler. @@ -2230,7 +2187,7 @@ public static void checkDisposedMaybeToSingle(Function, ? extend * @param ts the TestSubscriber instance * @param classes the array of expected Throwables inside the Composite */ - public static void assertCompositeExceptions(TestSubscriber ts, Class... classes) { + public static void assertCompositeExceptions(TestSubscriberEx ts, Class... classes) { ts .assertSubscribed() .assertError(CompositeException.class) @@ -2253,7 +2210,7 @@ public static void assertCompositeExceptions(TestSubscriber ts, Class ts, Object... classes) { + public static void assertCompositeExceptions(TestSubscriberEx ts, Object... classes) { ts .assertSubscribed() .assertError(CompositeException.class) @@ -2274,7 +2231,7 @@ public static void assertCompositeExceptions(TestSubscriber ts, Object... cla * @param to the TestSubscriber instance * @param classes the array of expected Throwables inside the Composite */ - public static void assertCompositeExceptions(TestObserver to, Class... classes) { + public static void assertCompositeExceptions(TestObserverEx to, Class... classes) { to .assertSubscribed() .assertError(CompositeException.class) @@ -2297,7 +2254,7 @@ public static void assertCompositeExceptions(TestObserver to, Class to, Object... classes) { + public static void assertCompositeExceptions(TestObserverEx to, Object... classes) { to .assertSubscribed() .assertError(CompositeException.class) @@ -2475,7 +2432,7 @@ public void onComplete() { * @param to the test consumer instance * @return the list */ - public static List errorList(TestObserver to) { + public static List errorList(TestObserverEx to) { return compositeList(to.errors().get(0)); } @@ -2484,7 +2441,7 @@ public static List errorList(TestObserver to) { * @param ts the test consumer instance * @return the list */ - public static List errorList(TestSubscriber ts) { + public static List errorList(TestSubscriberEx ts) { return compositeList(ts.errors().get(0)); } @@ -2535,7 +2492,7 @@ protected void subscribeActual(Observer observer) { if (o instanceof ObservableSource) { ObservableSource os = (ObservableSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2557,7 +2514,7 @@ protected void subscribeActual(Observer observer) { if (o instanceof Publisher) { Publisher os = (Publisher) o; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); os.subscribe(ts); @@ -2579,7 +2536,7 @@ protected void subscribeActual(Observer observer) { if (o instanceof SingleSource) { SingleSource os = (SingleSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2601,7 +2558,7 @@ protected void subscribeActual(Observer observer) { if (o instanceof MaybeSource) { MaybeSource os = (MaybeSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2623,7 +2580,7 @@ protected void subscribeActual(Observer observer) { if (o instanceof CompletableSource) { CompletableSource os = (CompletableSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2694,7 +2651,7 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof ObservableSource) { ObservableSource os = (ObservableSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2716,7 +2673,7 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof Publisher) { Publisher os = (Publisher) o; - TestSubscriber ts = new TestSubscriber(); + TestSubscriberEx ts = new TestSubscriberEx(); os.subscribe(ts); @@ -2738,7 +2695,7 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof SingleSource) { SingleSource os = (SingleSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2760,7 +2717,7 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof MaybeSource) { MaybeSource os = (MaybeSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -2782,7 +2739,7 @@ protected void subscribeActual(Subscriber subscriber) { if (o instanceof CompletableSource) { CompletableSource os = (CompletableSource) o; - TestObserver to = new TestObserver(); + TestObserverEx to = new TestObserverEx(); os.subscribe(to); @@ -3132,4 +3089,133 @@ public boolean isDisposed() { public static ObservableTransformer observableStripBoundary() { return new ObservableStripBoundary(null); } + + public static TestConsumerExConverters testConsumer() { + return new TestConsumerExConverters(false, 0); + } + + public static TestConsumerExConverters testConsumer(boolean cancelled) { + return new TestConsumerExConverters(cancelled, 0); + } + + public static TestConsumerExConverters testConsumer(final int fusionMode, final boolean cancelled) { + return new TestConsumerExConverters(cancelled, fusionMode); + } + + public static TestConsumerExConverters testConsumer(final boolean cancelled, final int fusionMode) { + return new TestConsumerExConverters(cancelled, fusionMode); + } + + public static FlowableConverter> testSubscriber(final long initialRequest) { + return testSubscriber(initialRequest, false, 0); + } + + public static FlowableConverter> testSubscriber(final long initialRequest, final boolean cancelled) { + return testSubscriber(initialRequest, cancelled, 0); + } + + public static FlowableConverter> testSubscriber(final long initialRequest, final int fusionMode, final boolean cancelled) { + return testSubscriber(initialRequest, cancelled, fusionMode); + } + + public static FlowableConverter> testSubscriber(final long initialRequest, final boolean cancelled, final int fusionMode) { + return new FlowableConverter>() { + @Override + public TestSubscriberEx apply(Flowable f) { + TestSubscriberEx tse = new TestSubscriberEx(initialRequest); + if (cancelled) { + tse.cancel(); + } + tse.setInitialFusionMode(fusionMode); + return f.subscribeWith(tse); + } + }; + } + + public static final class TestConsumerExConverters implements + ObservableConverter>, + SingleConverter>, + MaybeConverter>, + CompletableConverter>, + FlowableConverter> { + + final boolean cancelled; + + final int fusionMode; + + TestConsumerExConverters(boolean cancelled, int fusionMode) { + this.cancelled = cancelled; + this.fusionMode = fusionMode; + } + + @Override + public TestObserverEx apply(Completable upstream) { + TestObserverEx toe = new TestObserverEx(); + if (cancelled) { + toe.dispose(); + } + toe.setInitialFusionMode(fusionMode); + return upstream.subscribeWith(toe); + } + + @Override + public TestObserverEx apply(Maybe upstream) { + TestObserverEx toe = new TestObserverEx(); + if (cancelled) { + toe.dispose(); + } + toe.setInitialFusionMode(fusionMode); + return upstream.subscribeWith(toe); + } + + @Override + public TestObserverEx apply(Single upstream) { + TestObserverEx toe = new TestObserverEx(); + if (cancelled) { + toe.dispose(); + } + toe.setInitialFusionMode(fusionMode); + return upstream.subscribeWith(toe); + } + + @Override + public TestObserverEx apply(Observable upstream) { + TestObserverEx toe = new TestObserverEx(); + if (cancelled) { + toe.dispose(); + } + toe.setInitialFusionMode(fusionMode); + return upstream.subscribeWith(toe); + } + + @Override + public TestSubscriberEx apply(Flowable upstream) { + TestSubscriberEx tse = new TestSubscriberEx(); + if (cancelled) { + tse.dispose(); + } + tse.setInitialFusionMode(fusionMode); + return upstream.subscribeWith(tse); + } + } + + public static TestSubscriberEx assertValueSet(TestSubscriberEx ts, T... values) { + Set expectedSet = new HashSet(Arrays.asList(values)); + for (T t : ts.values()) { + if (!expectedSet.contains(t)) { + throw ts.failWith("Item not in the set: " + BaseTestConsumer.valueAndClass(t)); + } + } + return ts; + } + + public static TestObserverEx assertValueSet(TestObserverEx to, T... values) { + Set expectedSet = new HashSet(Arrays.asList(values)); + for (T t : to.values()) { + if (!expectedSet.contains(t)) { + throw to.failWith("Item not in the set: " + BaseTestConsumer.valueAndClass(t)); + } + } + return to; + } } diff --git a/src/test/java/io/reactivex/testsupport/TestObserverEx.java b/src/test/java/io/reactivex/testsupport/TestObserverEx.java new file mode 100644 index 0000000000..1d6a251c00 --- /dev/null +++ b/src/test/java/io/reactivex/testsupport/TestObserverEx.java @@ -0,0 +1,318 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ +package io.reactivex.testsupport; + +import java.util.concurrent.atomic.AtomicReference; + +import io.reactivex.*; +import io.reactivex.disposables.Disposable; +import io.reactivex.internal.disposables.DisposableHelper; +import io.reactivex.internal.fuseable.*; + +/** + * An extended test Observer that records events and allows making assertions about them. + * + *

You can override the onSubscribe, onNext, onError, onComplete, onSuccess and + * cancel methods but not the others (this is by design). + * + *

The TestObserver implements Disposable for convenience where dispose calls cancel. + * + * @param the value type + */ +public class TestObserverEx +extends BaseTestConsumerEx> +implements Observer, Disposable, MaybeObserver, SingleObserver, CompletableObserver { + /** The actual observer to forward events to. */ + private final Observer downstream; + + /** Holds the current subscription if any. */ + private final AtomicReference upstream = new AtomicReference(); + + private QueueDisposable qd; + + /** + * Constructs a non-forwarding TestObserver. + */ + public TestObserverEx() { + this(EmptyObserver.INSTANCE); + } + + /** + * Constructs a forwarding TestObserver. + * @param downstream the actual Observer to forward events to + */ + public TestObserverEx(Observer downstream) { + this.downstream = downstream; + } + + /** + * Constructs a TestObserverEx with the given initial fusion mode. + * @param fusionMode the fusion mode, see {@link QueueFuseable} + */ + public TestObserverEx(int fusionMode) { + this(); + setInitialFusionMode(fusionMode); + } + + @SuppressWarnings("unchecked") + @Override + public void onSubscribe(Disposable d) { + lastThread = Thread.currentThread(); + + if (d == null) { + errors.add(new NullPointerException("onSubscribe received a null Subscription")); + return; + } + if (!upstream.compareAndSet(null, d)) { + d.dispose(); + if (upstream.get() != DisposableHelper.DISPOSED) { + errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + d)); + } + return; + } + + if (initialFusionMode != 0) { + if (d instanceof QueueDisposable) { + qd = (QueueDisposable)d; + + int m = qd.requestFusion(initialFusionMode); + establishedFusionMode = m; + + if (m == QueueFuseable.SYNC) { + checkSubscriptionOnce = true; + lastThread = Thread.currentThread(); + try { + T t; + while ((t = qd.poll()) != null) { + values.add(t); + } + completions++; + + upstream.lazySet(DisposableHelper.DISPOSED); + } catch (Throwable ex) { + errors.add(ex); + } + return; + } + } + } + + downstream.onSubscribe(d); + } + + @Override + public void onNext(T t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + + lastThread = Thread.currentThread(); + + if (establishedFusionMode == QueueFuseable.ASYNC) { + try { + while ((t = qd.poll()) != null) { + values.add(t); + } + } catch (Throwable ex) { + errors.add(ex); + qd.dispose(); + } + return; + } + + values.add(t); + + if (t == null) { + errors.add(new NullPointerException("onNext received a null value")); + } + + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + + try { + lastThread = Thread.currentThread(); + if (t == null) { + errors.add(new NullPointerException("onError received a null Throwable")); + } else { + errors.add(t); + } + + downstream.onError(t); + } finally { + done.countDown(); + } + } + + @Override + public void onComplete() { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + + try { + lastThread = Thread.currentThread(); + completions++; + + downstream.onComplete(); + } finally { + done.countDown(); + } + } + + @Override + public final void dispose() { + DisposableHelper.dispose(upstream); + } + + @Override + public final boolean isDisposed() { + return DisposableHelper.isDisposed(upstream.get()); + } + + // state retrieval methods + /** + * Returns true if this TestObserver received a subscription. + * @return true if this TestObserver received a subscription + */ + public final boolean hasSubscription() { + return upstream.get() != null; + } + + /** + * Assert that the onSubscribe method was called exactly once. + * @return this; + */ + @Override + public final TestObserverEx assertSubscribed() { + if (upstream.get() == null) { + throw fail("Not subscribed!"); + } + return this; + } + + /** + * Assert that the onSubscribe method hasn't been called at all. + * @return this; + */ + public final TestObserverEx assertNotSubscribed() { + if (upstream.get() != null) { + throw fail("Subscribed!"); + } else + if (!errors.isEmpty()) { + throw fail("Not subscribed but errors found"); + } + return this; + } + + /** + * Sets the initial fusion mode if the upstream supports fusion. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @param mode the mode to establish, see the {@link QueueDisposable} constants + * @return this + */ + public final TestObserverEx setInitialFusionMode(int mode) { + this.initialFusionMode = mode; + return this; + } + + /** + * Asserts that the given fusion mode has been established + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @param mode the expected mode + * @return this + */ + public final TestObserverEx assertFusionMode(int mode) { + int m = establishedFusionMode; + if (m != mode) { + if (qd != null) { + throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) + + ", actual: " + fusionModeToString(m)); + } else { + throw fail("Upstream is not fuseable"); + } + } + return this; + } + + /** + * Assert that the upstream is a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @return this + */ + public final TestObserverEx assertFuseable() { + if (qd == null) { + throw new AssertionError("Upstream is not fuseable."); + } + return this; + } + + /** + * Assert that the upstream is not a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use ObserverFusion to work with such tests. + * @return this + */ + public final TestObserverEx assertNotFuseable() { + if (qd != null) { + throw new AssertionError("Upstream is fuseable."); + } + return this; + } + + @Override + public void onSuccess(T value) { + onNext(value); + onComplete(); + } + + /** + * An observer that ignores all events and does not report errors. + */ + enum EmptyObserver implements Observer { + INSTANCE; + + @Override + public void onSubscribe(Disposable d) { + } + + @Override + public void onNext(Object t) { + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onComplete() { + } + } +} diff --git a/src/test/java/io/reactivex/testsupport/TestObserverExTest.java b/src/test/java/io/reactivex/testsupport/TestObserverExTest.java new file mode 100644 index 0000000000..a11c24f978 --- /dev/null +++ b/src/test/java/io/reactivex/testsupport/TestObserverExTest.java @@ -0,0 +1,1383 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.testsupport; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; + +import org.junit.*; +import org.junit.rules.ExpectedException; +import org.mockito.InOrder; + +import io.reactivex.Observable; +import io.reactivex.Observer; +import io.reactivex.disposables.*; +import io.reactivex.exceptions.TestException; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.internal.operators.observable.ObservableScalarXMap.ScalarDisposable; +import io.reactivex.observers.TestObserver; +import io.reactivex.schedulers.Schedulers; +import io.reactivex.subjects.*; + +public class TestObserverExTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testAssert() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + TestObserverEx subscriber = new TestObserverEx(); + oi.subscribe(subscriber); + + subscriber.assertValues(1, 2); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); + } + + @Test + public void testAssertNotMatchCount() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + TestObserverEx subscriber = new TestObserverEx(); + oi.subscribe(subscriber); + + thrown.expect(AssertionError.class); + // FIXME different message format +// thrown.expectMessage("Number of items does not match. Provided: 1 Actual: 2"); + + subscriber.assertValue(1); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); + } + + @Test + public void testAssertNotMatchValue() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + TestObserverEx subscriber = new TestObserverEx(); + oi.subscribe(subscriber); + + thrown.expect(AssertionError.class); + // FIXME different message format +// thrown.expectMessage("Value at index: 1 expected to be [3] (Integer) but was: [2] (Integer)"); + + subscriber.assertValues(1, 3); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); + } + + @Test + public void assertNeverAtNotMatchingValue() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + TestObserverEx subscriber = new TestObserverEx(); + oi.subscribe(subscriber); + + subscriber.assertNever(3); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); + } + + @Test + public void assertNeverAtMatchingValue() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + TestObserverEx subscriber = new TestObserverEx(); + oi.subscribe(subscriber); + + subscriber.assertValues(1, 2); + + thrown.expect(AssertionError.class); + + subscriber.assertNever(2); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); + } + + @Test + public void assertNeverAtMatchingPredicate() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1, 2).subscribe(to); + + to.assertValues(1, 2); + + thrown.expect(AssertionError.class); + + to.assertNever(new Predicate() { + @Override + public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertNeverAtNotMatchingPredicate() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(2, 3).subscribe(to); + + to.assertNever(new Predicate() { + @Override + public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void testAssertTerminalEventNotReceived() { + PublishSubject p = PublishSubject.create(); + TestObserverEx subscriber = new TestObserverEx(); + p.subscribe(subscriber); + + p.onNext(1); + p.onNext(2); + + thrown.expect(AssertionError.class); + // FIXME different message format +// thrown.expectMessage("No terminal events received."); + + subscriber.assertValues(1, 2); + subscriber.assertValueCount(2); + subscriber.assertTerminated(); + } + + @Test + public void testWrappingMock() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2)); + + Observer mockSubscriber = TestHelper.mockObserver(); + + oi.subscribe(new TestObserverEx(mockSubscriber)); + + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); + inOrder.verifyNoMoreInteractions(); + } + + @Test + public void testWrappingMockWhenUnsubscribeInvolved() { + Observable oi = Observable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); + Observer mockSubscriber = TestHelper.mockObserver(); + oi.subscribe(new TestObserverEx(mockSubscriber)); + + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); + inOrder.verifyNoMoreInteractions(); + } + + @Test + public void testErrorSwallowed() { + Observable.error(new RuntimeException()).subscribe(new TestObserverEx()); + } + + @Test + public void testNullExpected() { + TestObserverEx to = new TestObserverEx(); + to.onNext(1); + + try { + to.assertValue((Integer) null); + } catch (AssertionError ex) { + // this is expected + return; + } + fail("Null element check assertion didn't happen!"); + } + + @Test + public void testNullActual() { + TestObserverEx to = new TestObserverEx(); + to.onNext(null); + + try { + to.assertValue(1); + } catch (AssertionError ex) { + // this is expected + return; + } + fail("Null element check assertion didn't happen!"); + } + + @Test + public void testTerminalErrorOnce() { + TestObserverEx to = new TestObserverEx(); + to.onError(new TestException()); + to.onError(new TestException()); + + try { + to.assertTerminated(); + } catch (AssertionError ex) { + // this is expected + return; + } + fail("Failed to report multiple onError terminal events!"); + } + + @Test + public void testTerminalCompletedOnce() { + TestObserverEx to = new TestObserverEx(); + to.onComplete(); + to.onComplete(); + + try { + to.assertTerminated(); + } catch (AssertionError ex) { + // this is expected + return; + } + fail("Failed to report multiple onComplete terminal events!"); + } + + @Test + public void testTerminalOneKind() { + TestObserverEx to = new TestObserverEx(); + to.onError(new TestException()); + to.onComplete(); + + try { + to.assertTerminated(); + } catch (AssertionError ex) { + // this is expected + return; + } + fail("Failed to report multiple kinds of events!"); + } + + @Test + public void createDelegate() { + TestObserverEx to1 = new TestObserverEx(); + + TestObserverEx to = new TestObserverEx(to1); + + to.assertNotSubscribed(); + + assertFalse(to.hasSubscription()); + + to.onSubscribe(Disposables.empty()); + + try { + to.assertNotSubscribed(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + assertTrue(to.hasSubscription()); + + assertFalse(to.isDisposed()); + + to.onNext(1); + to.onError(new TestException()); + to.onComplete(); + + to1.assertValue(1).assertError(TestException.class).assertComplete(); + + to.dispose(); + + assertTrue(to.isDisposed()); + + assertSame(Thread.currentThread(), to.lastThread()); + + try { + to.assertNoValues(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertValueCount(0); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + to.assertValueSequence(Collections.singletonList(1)); + + try { + to.assertValueSequence(Collections.singletonList(2)); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + } + + @Test + public void assertError() { + TestObserverEx to = new TestObserverEx(); + + try { + to.assertError(TestException.class); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertError(new TestException()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertError(Functions.alwaysTrue()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertErrorMessage(""); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertSubscribed(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + to.onSubscribe(Disposables.empty()); + + to.assertSubscribed(); + + to.assertNoErrors(); + + TestException ex = new TestException("Forced failure"); + + to.onError(ex); + + to.assertError(ex); + + to.assertError(TestException.class); + + to.assertError(Functions.alwaysTrue()); + + to.assertError(new Predicate() { + @Override + public boolean test(Throwable t) throws Exception { + return t.getMessage() != null && t.getMessage().contains("Forced"); + } + }); + + to.assertErrorMessage("Forced failure"); + + try { + to.assertErrorMessage(""); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertError(new RuntimeException()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertError(IOException.class); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertError(Functions.alwaysFalse()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + to.assertNoErrors(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + to.assertTerminated(); + + to.assertValueCount(0); + + to.assertNoValues(); + } + + @Test + public void emptyObserverEnum() { + assertEquals(1, TestObserverEx.EmptyObserver.values().length); + assertNotNull(TestObserverEx.EmptyObserver.valueOf("INSTANCE")); + } + + @Test + public void valueAndClass() { + assertEquals("null", TestObserver.valueAndClass(null)); + assertEquals("1 (class: Integer)", TestObserver.valueAndClass(1)); + } + + @Test + public void assertFailure() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.onError(new TestException("Forced failure")); + + to.assertFailure(TestException.class); + + to.assertFailure(Functions.alwaysTrue()); + + to.assertFailureAndMessage(TestException.class, "Forced failure"); + + to.onNext(1); + + to.assertFailure(TestException.class, 1); + + to.assertFailure(Functions.alwaysTrue(), 1); + + to.assertFailureAndMessage(TestException.class, "Forced failure", 1); + } + + @Test + public void assertFuseable() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.assertNotFuseable(); + + try { + to.assertFuseable(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertFusionMode(QueueFuseable.SYNC); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + to = new TestObserverEx(); + to.setInitialFusionMode(QueueFuseable.ANY); + + to.onSubscribe(new ScalarDisposable(to, 1)); + + to.assertFuseable(); + + to.assertFusionMode(QueueFuseable.SYNC); + + try { + to.assertFusionMode(QueueFuseable.NONE); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertNotFuseable(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + } + + @Test + public void assertTerminated() { + TestObserverEx to = new TestObserverEx(); + + to.assertNotTerminated(); + + to.onError(null); + + try { + to.assertNotTerminated(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertResult() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.onComplete(); + + to.assertResult(); + + try { + to.assertResult(1); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + to.onNext(1); + + to.assertResult(1); + + try { + to.assertResult(2); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertResult(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + } + + @Test(timeout = 5000) + public void await() throws Exception { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + assertFalse(to.await(100, TimeUnit.MILLISECONDS)); + + to.awaitDone(100, TimeUnit.MILLISECONDS); + + assertTrue(to.isDisposed()); + + to.assertNotTerminated(); + + to.onComplete(); + + assertTrue(to.await(100, TimeUnit.MILLISECONDS)); + + to.await(); + + to.awaitDone(5, TimeUnit.SECONDS); + + to.assertNoErrors().assertComplete(); + + final TestObserverEx to1 = new TestObserverEx(); + + to1.onSubscribe(Disposables.empty()); + + Schedulers.single().scheduleDirect(new Runnable() { + @Override + public void run() { + to1.onComplete(); + } + }, 200, TimeUnit.MILLISECONDS); + + to1.await(); + } + + @Test + public void errors() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + assertEquals(0, to.errors().size()); + + to.onError(new TestException()); + + assertEquals(1, to.errors().size()); + + TestHelper.assertError(to.errors(), 0, TestException.class); + } + + @Test + public void onNext() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.assertValueCount(0); + + assertEquals(Collections.emptyList(), to.values()); + + to.onNext(1); + + assertEquals(Collections.singletonList(1), to.values()); + + to.dispose(); + + assertTrue(to.isDisposed()); + + to.assertValue(1); + + to.onComplete(); + } + + @Test + public void fusionModeToString() { + assertEquals("NONE", TestObserverEx.fusionModeToString(QueueFuseable.NONE)); + assertEquals("SYNC", TestObserverEx.fusionModeToString(QueueFuseable.SYNC)); + assertEquals("ASYNC", TestObserverEx.fusionModeToString(QueueFuseable.ASYNC)); + assertEquals("Unknown(100)", TestObserverEx.fusionModeToString(100)); + } + + @Test + public void multipleTerminals() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.assertNotComplete(); + + to.onComplete(); + + try { + to.assertNotComplete(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + to.assertTerminated(); + + to.onComplete(); + + try { + to.assertComplete(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + try { + to.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + try { + to.assertNotComplete(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + } + + @Test + public void assertValue() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + try { + to.assertValue(1); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + to.onNext(1); + + to.assertValue(1); + + try { + to.assertValue(2); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + to.onNext(2); + + try { + to.assertValue(1); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + } + + @Test + public void onNextMisbehave() { + TestObserverEx to = new TestObserverEx(); + + to.onNext(1); + + to.assertError(IllegalStateException.class); + + to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.onNext(null); + + to.assertFailure(NullPointerException.class, (Integer)null); + } + + @Test + public void assertTerminated2() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.assertNotTerminated(); + + to.onError(new TestException()); + + to.assertTerminated(); + + to.onError(new IOException()); + + try { + to.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + to.assertError(TestException.class); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.onError(new TestException()); + to.onComplete(); + + try { + to.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void onSubscribe() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(null); + + to.assertError(NullPointerException.class); + + to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + Disposable d1 = Disposables.empty(); + + to.onSubscribe(d1); + + assertTrue(d1.isDisposed()); + + to.assertError(IllegalStateException.class); + + to = new TestObserverEx(); + to.dispose(); + + d1 = Disposables.empty(); + + to.onSubscribe(d1); + + assertTrue(d1.isDisposed()); + + } + + @Test + public void assertValueSequence() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + to.onNext(1); + to.onNext(2); + + try { + to.assertValueSequence(Collections.emptyList()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError expected) { + assertTrue(expected.getMessage(), expected.getMessage().startsWith("More values received than expected (0)")); + } + + try { + to.assertValueSequence(Collections.singletonList(1)); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError expected) { + assertTrue(expected.getMessage(), expected.getMessage().startsWith("More values received than expected (1)")); + } + + to.assertValueSequence(Arrays.asList(1, 2)); + + try { + to.assertValueSequence(Arrays.asList(1, 2, 3)); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError expected) { + assertTrue(expected.getMessage(), expected.getMessage().startsWith("Fewer values received than expected (2)")); + } + } + + @Test + public void assertEmpty() { + TestObserverEx to = new TestObserverEx(); + + try { + to.assertEmpty(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + + to.onSubscribe(Disposables.empty()); + + to.assertEmpty(); + + to.onNext(1); + + try { + to.assertEmpty(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void awaitDoneTimed() { + TestObserverEx to = new TestObserverEx(); + + Thread.currentThread().interrupt(); + + try { + to.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException ex) { + assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); + } + } + + @Test + public void assertNotSubscribed() { + TestObserverEx to = new TestObserverEx(); + + to.assertNotSubscribed(); + + to.errors().add(new TestException()); + + try { + to.assertNotSubscribed(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertErrorMultiple() { + TestObserverEx to = new TestObserverEx(); + + TestException e = new TestException(); + to.errors().add(e); + to.errors().add(new TestException()); + + try { + to.assertError(TestException.class); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + try { + to.assertError(e); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + try { + to.assertError(Functions.alwaysTrue()); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + try { + to.assertErrorMessage(""); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void testErrorInPredicate() { + TestObserverEx to = new TestObserverEx(); + to.onError(new RuntimeException()); + try { + to.assertError(new Predicate() { + @Override + public boolean test(Throwable throwable) throws Exception { + throw new TestException(); + } + }); + } catch (TestException ex) { + // expected + return; + } + fail("Error in predicate but not thrown!"); + } + + @Test + public void assertComplete() { + TestObserverEx to = new TestObserverEx(); + + to.onSubscribe(Disposables.empty()); + + try { + to.assertComplete(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + + to.onComplete(); + + to.assertComplete(); + + to.onComplete(); + + try { + to.assertComplete(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void completeWithoutOnSubscribe() { + TestObserverEx to = new TestObserverEx(); + + to.onComplete(); + + to.assertError(IllegalStateException.class); + } + + @Test + public void completeDelegateThrows() { + TestObserverEx to = new TestObserverEx(new Observer() { + + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Integer value) { + + } + + @Override + public void onError(Throwable e) { + throw new TestException(); + } + + @Override + public void onComplete() { + throw new TestException(); + } + + }); + + to.onSubscribe(Disposables.empty()); + + try { + to.onComplete(); + throw new RuntimeException("Should have thrown!"); + } catch (TestException ex) { + to.assertTerminated(); + } + } + + @Test + public void errorDelegateThrows() { + TestObserverEx to = new TestObserverEx(new Observer() { + + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(Integer value) { + + } + + @Override + public void onError(Throwable e) { + throw new TestException(); + } + + @Override + public void onComplete() { + throw new TestException(); + } + + }); + + to.onSubscribe(Disposables.empty()); + + try { + to.onError(new IOException()); + throw new RuntimeException("Should have thrown!"); + } catch (TestException ex) { + to.assertTerminated(); + } + } + + @Test + public void syncQueueThrows() { + TestObserverEx to = new TestObserverEx(); + to.setInitialFusionMode(QueueFuseable.SYNC); + + Observable.range(1, 5) + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { throw new TestException(); } + }) + .subscribe(to); + + to.assertSubscribed() + .assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) + .assertFailure(TestException.class); + } + + @Test + public void asyncQueueThrows() { + TestObserverEx to = new TestObserverEx(); + to.setInitialFusionMode(QueueFuseable.ANY); + + UnicastSubject up = UnicastSubject.create(); + + up + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { throw new TestException(); } + }) + .subscribe(to); + + up.onNext(1); + + to.assertSubscribed() + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) + .assertFailure(TestException.class); + } + + @Test + public void completedMeansDisposed() { + // 2.0.2 - a terminated TestObserver no longer reports isDisposed + assertFalse(Observable.just(1) + .test() + .assertResult(1).isDisposed()); + } + + @Test + public void errorMeansDisposed() { + // 2.0.2 - a terminated TestObserver no longer reports isDisposed + assertFalse(Observable.error(new TestException()) + .test() + .assertFailure(TestException.class).isDisposed()); + } + + @Test + public void asyncFusion() { + TestObserverEx to = new TestObserverEx(); + to.setInitialFusionMode(QueueFuseable.ANY); + + UnicastSubject up = UnicastSubject.create(); + + up + .subscribe(to); + + up.onNext(1); + up.onComplete(); + + to.assertSubscribed() + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) + .assertResult(1); + } + + @Test + public void assertValuePredicateEmpty() { + TestObserverEx to = new TestObserverEx(); + + Observable.empty().subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("No values"); + to.assertValue(new Predicate() { + @Override public boolean test(final Object o) throws Exception { + return false; + } + }); + } + + @Test + public void assertValuePredicateMatch() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1).subscribe(to); + + to.assertValue(new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertValuePredicateNoMatch() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1).subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value not present"); + to.assertValue(new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o != 1; + } + }); + } + + @Test + public void assertValuePredicateMatchButMore() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1, 2).subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value present but other values as well"); + to.assertValue(new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertValueAtPredicateEmpty() { + TestObserverEx to = new TestObserverEx(); + + Observable.empty().subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("No values"); + to.assertValueAt(0, new Predicate() { + @Override public boolean test(final Object o) throws Exception { + return false; + } + }); + } + + @Test + public void assertValueAtPredicateMatch() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1, 2).subscribe(to); + + to.assertValueAt(1, new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 2; + } + }); + } + + @Test + public void assertValueAtPredicateNoMatch() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1, 2, 3).subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value not present"); + to.assertValueAt(2, new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o != 3; + } + }); + } + + @Test + public void assertValueAtInvalidIndex() { + TestObserverEx to = new TestObserverEx(); + + Observable.just(1, 2).subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)"); + to.assertValueAt(2, new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertValueAtIndexEmpty() { + TestObserverEx to = new TestObserverEx(); + + Observable.empty().subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("No values"); + to.assertValueAt(0, "a"); + } + + @Test + public void assertValueAtIndexMatch() { + TestObserverEx to = new TestObserverEx(); + + Observable.just("a", "b").subscribe(to); + + to.assertValueAt(1, "b"); + } + + @Test + public void assertValueAtIndexNoMatch() { + TestObserverEx to = new TestObserverEx(); + + Observable.just("a", "b", "c").subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("expected: b (class: String) but was: c (class: String) (latch = 0, values = 3, errors = 0, completions = 1)"); + to.assertValueAt(2, "b"); + } + + @Test + public void assertValueAtIndexInvalidIndex() { + TestObserverEx to = new TestObserverEx(); + + Observable.just("a", "b").subscribe(to); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)"); + to.assertValueAt(2, "c"); + } + + @Test + public void withTag() { + try { + for (int i = 1; i < 3; i++) { + Observable.just(i) + .test() + .withTag("testing with item=" + i) + .assertResult(1) + ; + } + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + assertTrue(ex.toString(), ex.toString().contains("testing with item=2")); + } + } + + @Test + public void assertValuesOnly() { + TestObserverEx to = new TestObserverEx(); + to.onSubscribe(Disposables.empty()); + to.assertValuesOnly(); + + to.onNext(5); + to.assertValuesOnly(5); + + to.onNext(-1); + to.assertValuesOnly(5, -1); + } + + @Test + public void assertValuesOnlyThrowsOnUnexpectedValue() { + TestObserverEx to = new TestObserverEx(); + to.onSubscribe(Disposables.empty()); + to.assertValuesOnly(); + + to.onNext(5); + to.assertValuesOnly(5); + + to.onNext(-1); + + try { + to.assertValuesOnly(5); + throw new RuntimeException(); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertValuesOnlyThrowsWhenCompleted() { + TestObserverEx to = new TestObserverEx(); + to.onSubscribe(Disposables.empty()); + + to.onComplete(); + + try { + to.assertValuesOnly(); + throw new RuntimeException(); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertValuesOnlyThrowsWhenErrored() { + TestObserverEx to = new TestObserverEx(); + to.onSubscribe(Disposables.empty()); + + to.onError(new TestException()); + + try { + to.assertValuesOnly(); + throw new RuntimeException(); + } catch (AssertionError ex) { + // expected + } + } +} diff --git a/src/test/java/io/reactivex/testsupport/TestSubscriberEx.java b/src/test/java/io/reactivex/testsupport/TestSubscriberEx.java new file mode 100644 index 0000000000..5435ba6d12 --- /dev/null +++ b/src/test/java/io/reactivex/testsupport/TestSubscriberEx.java @@ -0,0 +1,387 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ +package io.reactivex.testsupport; + +import java.util.concurrent.atomic.*; + +import org.reactivestreams.*; + +import io.reactivex.FlowableSubscriber; +import io.reactivex.internal.fuseable.*; +import io.reactivex.internal.subscriptions.SubscriptionHelper; + +/** + * An extended test subscriber that records events and allows making assertions about them. + * + *

You can override the onSubscribe, onNext, onError, onComplete, request and + * cancel methods but not the others (this is by design). + * + *

The TestSubscriber implements Disposable for convenience where dispose calls cancel. + * + *

When calling the default request method, you are requesting on behalf of the + * wrapped actual subscriber. + * + * @param the value type + */ +public class TestSubscriberEx +extends BaseTestConsumerEx> +implements FlowableSubscriber, Subscription { + /** The actual subscriber to forward events to. */ + private final Subscriber downstream; + + /** Makes sure the incoming Subscriptions get cancelled immediately. */ + private volatile boolean cancelled; + + /** Holds the current subscription if any. */ + private final AtomicReference upstream; + + /** Holds the requested amount until a subscription arrives. */ + private final AtomicLong missedRequested; + + private QueueSubscription qs; + + /** + * Constructs a non-forwarding TestSubscriber with an initial request value of Long.MAX_VALUE. + */ + public TestSubscriberEx() { + this(EmptySubscriber.INSTANCE, Long.MAX_VALUE); + } + + /** + * Constructs a non-forwarding TestSubscriber with the specified initial request value. + *

The TestSubscriber doesn't validate the initialRequest value so one can + * test sources with invalid values as well. + * @param initialRequest the initial request value + */ + public TestSubscriberEx(long initialRequest) { + this(EmptySubscriber.INSTANCE, initialRequest); + } + + /** + * Constructs a forwarding TestSubscriber but leaves the requesting to the wrapped subscriber. + * @param downstream the actual Subscriber to forward events to + */ + public TestSubscriberEx(Subscriber downstream) { + this(downstream, Long.MAX_VALUE); + } + + /** + * Constructs a forwarding TestSubscriber with the specified initial request value. + *

The TestSubscriber doesn't validate the initialRequest value so one can + * test sources with invalid values as well. + * @param actual the actual Subscriber to forward events to + * @param initialRequest the initial request value + */ + public TestSubscriberEx(Subscriber actual, long initialRequest) { + super(); + if (initialRequest < 0) { + throw new IllegalArgumentException("Negative initial request not allowed"); + } + this.downstream = actual; + this.upstream = new AtomicReference(); + this.missedRequested = new AtomicLong(initialRequest); + } + + @SuppressWarnings("unchecked") + @Override + public void onSubscribe(Subscription s) { + lastThread = Thread.currentThread(); + + if (s == null) { + errors.add(new NullPointerException("onSubscribe received a null Subscription")); + return; + } + if (!upstream.compareAndSet(null, s)) { + s.cancel(); + if (upstream.get() != SubscriptionHelper.CANCELLED) { + errors.add(new IllegalStateException("onSubscribe received multiple subscriptions: " + s)); + } + return; + } + + if (initialFusionMode != 0) { + if (s instanceof QueueSubscription) { + qs = (QueueSubscription)s; + + int m = qs.requestFusion(initialFusionMode); + establishedFusionMode = m; + + if (m == QueueFuseable.SYNC) { + checkSubscriptionOnce = true; + lastThread = Thread.currentThread(); + try { + T t; + while ((t = qs.poll()) != null) { + values.add(t); + } + completions++; + } catch (Throwable ex) { + // Exceptions.throwIfFatal(e); TODO add fatal exceptions? + errors.add(ex); + } + return; + } + } + } + + downstream.onSubscribe(s); + + long mr = missedRequested.getAndSet(0L); + if (mr != 0L) { + s.request(mr); + } + + onStart(); + } + + /** + * Called after the onSubscribe is called and handled. + */ + protected void onStart() { + + } + + @Override + public void onNext(T t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + lastThread = Thread.currentThread(); + + if (establishedFusionMode == QueueFuseable.ASYNC) { + try { + while ((t = qs.poll()) != null) { + values.add(t); + } + } catch (Throwable ex) { + // Exceptions.throwIfFatal(e); TODO add fatal exceptions? + errors.add(ex); + qs.cancel(); + } + return; + } + + values.add(t); + + if (t == null) { + errors.add(new NullPointerException("onNext received a null value")); + } + + downstream.onNext(t); + } + + @Override + public void onError(Throwable t) { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new NullPointerException("onSubscribe not called in proper order")); + } + } + try { + lastThread = Thread.currentThread(); + errors.add(t); + + if (t == null) { + errors.add(new IllegalStateException("onError received a null Throwable")); + } + + downstream.onError(t); + } finally { + done.countDown(); + } + } + + @Override + public void onComplete() { + if (!checkSubscriptionOnce) { + checkSubscriptionOnce = true; + if (upstream.get() == null) { + errors.add(new IllegalStateException("onSubscribe not called in proper order")); + } + } + try { + lastThread = Thread.currentThread(); + completions++; + + downstream.onComplete(); + } finally { + done.countDown(); + } + } + + @Override + public final void request(long n) { + SubscriptionHelper.deferredRequest(upstream, missedRequested, n); + } + + @Override + public final void cancel() { + if (!cancelled) { + cancelled = true; + SubscriptionHelper.cancel(upstream); + } + } + + /** + * Returns true if this TestSubscriber has been cancelled. + * @return true if this TestSubscriber has been cancelled + */ + public final boolean isCancelled() { + return cancelled; + } + + @Override + protected final void dispose() { + cancel(); + } + + @Override + protected final boolean isDisposed() { + return cancelled; + } + + // state retrieval methods + + /** + * Returns true if this TestSubscriber received a subscription. + * @return true if this TestSubscriber received a subscription + */ + public final boolean hasSubscription() { + return upstream.get() != null; + } + + // assertion methods + + /** + * Assert that the onSubscribe method was called exactly once. + * @return this + */ + @Override + public final TestSubscriberEx assertSubscribed() { + if (upstream.get() == null) { + throw fail("Not subscribed!"); + } + return this; + } + + /** + * Assert that the onSubscribe method hasn't been called at all. + * @return this + */ + public final TestSubscriberEx assertNotSubscribed() { + if (upstream.get() != null) { + throw fail("Subscribed!"); + } else + if (!errors.isEmpty()) { + throw fail("Not subscribed but errors found"); + } + return this; + } + + /** + * Sets the initial fusion mode if the upstream supports fusion. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @param mode the mode to establish, see the {@link QueueSubscription} constants + * @return this + */ + public final TestSubscriberEx setInitialFusionMode(int mode) { + this.initialFusionMode = mode; + return this; + } + + /** + * Asserts that the given fusion mode has been established + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @param mode the expected mode + * @return this + */ + public final TestSubscriberEx assertFusionMode(int mode) { + int m = establishedFusionMode; + if (m != mode) { + if (qs != null) { + throw new AssertionError("Fusion mode different. Expected: " + fusionModeToString(mode) + + ", actual: " + fusionModeToString(m)); + } else { + throw fail("Upstream is not fuseable"); + } + } + return this; + } + + /** + * Assert that the upstream is a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @return this + */ + public final TestSubscriberEx assertFuseable() { + if (qs == null) { + throw new AssertionError("Upstream is not fuseable."); + } + return this; + } + + /** + * Assert that the upstream is not a fuseable source. + *

Package-private: avoid leaking the now internal fusion properties into the public API. + * Use SubscriberFusion to work with such tests. + * @return this + */ + public final TestSubscriberEx assertNotFuseable() { + if (qs != null) { + throw new AssertionError("Upstream is fuseable."); + } + return this; + } + + /** + * Calls {@link #request(long)} and returns this. + *

History: 2.0.1 - experimental + * @param n the request amount + * @return this + * @since 2.1 + */ + public final TestSubscriberEx requestMore(long n) { + request(n); + return this; + } + + /** + * A subscriber that ignores all events and does not report errors. + */ + enum EmptySubscriber implements FlowableSubscriber { + INSTANCE; + + @Override + public void onSubscribe(Subscription s) { + } + + @Override + public void onNext(Object t) { + } + + @Override + public void onError(Throwable t) { + } + + @Override + public void onComplete() { + } + } +} diff --git a/src/test/java/io/reactivex/testsupport/TestSubscriberExTest.java b/src/test/java/io/reactivex/testsupport/TestSubscriberExTest.java new file mode 100644 index 0000000000..e2070069cf --- /dev/null +++ b/src/test/java/io/reactivex/testsupport/TestSubscriberExTest.java @@ -0,0 +1,1886 @@ +/** + * Copyright (c) 2016-present, RxJava Contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is + * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See + * the License for the specific language governing permissions and limitations under the License. + */ + +package io.reactivex.testsupport; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.junit.*; +import org.junit.rules.ExpectedException; +import org.mockito.InOrder; +import org.reactivestreams.*; + +import io.reactivex.*; +import io.reactivex.Scheduler.Worker; +import io.reactivex.exceptions.*; +import io.reactivex.functions.*; +import io.reactivex.internal.functions.Functions; +import io.reactivex.internal.fuseable.QueueFuseable; +import io.reactivex.internal.subscriptions.*; +import io.reactivex.processors.*; +import io.reactivex.schedulers.Schedulers; + +public class TestSubscriberExTest { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testAssert() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); + TestSubscriberEx ts = new TestSubscriberEx(); + oi.subscribe(ts); + + ts.assertValues(1, 2); + ts.assertValueCount(2); + ts.assertTerminated(); + } + + @Test + public void testAssertNotMatchCount() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); + TestSubscriberEx ts = new TestSubscriberEx(); + oi.subscribe(ts); + + thrown.expect(AssertionError.class); + + ts.assertValues(1); + ts.assertValueCount(2); + ts.assertTerminated(); + } + + @Test + public void testAssertNotMatchValue() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); + TestSubscriberEx ts = new TestSubscriberEx(); + oi.subscribe(ts); + + thrown.expect(AssertionError.class); + + ts.assertValues(1, 3); + ts.assertValueCount(2); + ts.assertTerminated(); + } + + @Test + public void assertNeverAtNotMatchingValue() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); + TestSubscriberEx ts = new TestSubscriberEx(); + oi.subscribe(ts); + + ts.assertNever(3); + ts.assertValueCount(2); + ts.assertTerminated(); + } + + @Test + public void assertNeverAtMatchingValue() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); + TestSubscriberEx ts = new TestSubscriberEx(); + oi.subscribe(ts); + + ts.assertValues(1, 2); + + thrown.expect(AssertionError.class); + + ts.assertNever(2); + ts.assertValueCount(2); + ts.assertTerminated(); + } + + @Test + public void assertNeverAtMatchingPredicate() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1, 2).subscribe(ts); + + ts.assertValues(1, 2); + + thrown.expect(AssertionError.class); + + ts.assertNever(new Predicate() { + @Override + public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertNeverAtNotMatchingPredicate() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(2, 3).subscribe(ts); + + ts.assertNever(new Predicate() { + @Override + public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void testAssertTerminalEventNotReceived() { + PublishProcessor p = PublishProcessor.create(); + TestSubscriberEx ts = new TestSubscriberEx(); + p.subscribe(ts); + + p.onNext(1); + p.onNext(2); + + thrown.expect(AssertionError.class); + + ts.assertValues(1, 2); + ts.assertValueCount(2); + ts.assertTerminated(); + } + + @Test + public void testWrappingMock() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2)); + Subscriber mockSubscriber = TestHelper.mockSubscriber(); + + oi.subscribe(new TestSubscriberEx(mockSubscriber)); + + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); + inOrder.verifyNoMoreInteractions(); + } + + @Test + public void testWrappingMockWhenUnsubscribeInvolved() { + Flowable oi = Flowable.fromIterable(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9)).take(2); + Subscriber mockSubscriber = TestHelper.mockSubscriber(); + oi.subscribe(new TestSubscriberEx(mockSubscriber)); + + InOrder inOrder = inOrder(mockSubscriber); + inOrder.verify(mockSubscriber, times(1)).onNext(1); + inOrder.verify(mockSubscriber, times(1)).onNext(2); + inOrder.verify(mockSubscriber, times(1)).onComplete(); + inOrder.verifyNoMoreInteractions(); + } + + @Test + public void testAssertError() { + RuntimeException e = new RuntimeException("Oops"); + TestSubscriberEx subscriber = new TestSubscriberEx(); + Flowable.error(e).subscribe(subscriber); + subscriber.assertError(e); + } + + @Test + public void testAwaitTerminalEventWithDurationAndUnsubscribeOnTimeout() { + TestSubscriberEx ts = new TestSubscriberEx(); + final AtomicBoolean unsub = new AtomicBoolean(false); + Flowable.just(1) + // + .doOnCancel(new Action() { + @Override + public void run() { + unsub.set(true); + } + }) + // + .delay(1000, TimeUnit.MILLISECONDS).subscribe(ts); + ts.awaitDone(100, TimeUnit.MILLISECONDS); + ts.dispose(); + assertTrue(unsub.get()); + } + + @Test(expected = NullPointerException.class) + public void testNullDelegate1() { + TestSubscriberEx ts = new TestSubscriberEx(null); + ts.onComplete(); + } + + @Test(expected = NullPointerException.class) + public void testNullDelegate2() { + TestSubscriberEx ts = new TestSubscriberEx(null); + ts.onComplete(); + } + + @Test(expected = NullPointerException.class) + public void testNullDelegate3() { + TestSubscriberEx ts = new TestSubscriberEx(null, 0L); + ts.onComplete(); + } + + @Test + public void testDelegate1() { + TestSubscriberEx ts0 = new TestSubscriberEx(); + ts0.onSubscribe(EmptySubscription.INSTANCE); + + TestSubscriberEx ts = new TestSubscriberEx(ts0); + ts.onComplete(); + + ts0.assertTerminated(); + } + + @Test + public void testDelegate2() { + TestSubscriberEx ts1 = new TestSubscriberEx(); + TestSubscriberEx ts2 = new TestSubscriberEx(ts1); + ts2.onComplete(); + + ts1.assertComplete(); + } + + @Test + public void testDelegate3() { + TestSubscriberEx ts1 = new TestSubscriberEx(); + TestSubscriberEx ts2 = new TestSubscriberEx(ts1, 0L); + ts2.onComplete(); + ts1.assertComplete(); + } + + @Test + public void testUnsubscribed() { + TestSubscriberEx ts = new TestSubscriberEx(); + assertFalse(ts.isCancelled()); + } + + @Test + public void testNoErrors() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onError(new TestException()); + try { + ts.assertNoErrors(); + } catch (AssertionError ex) { + // expected + return; + } + fail("Error present but no assertion error!"); + } + + @Test + public void testNotCompleted() { + TestSubscriberEx ts = new TestSubscriberEx(); + try { + ts.assertComplete(); + } catch (AssertionError ex) { + // expected + return; + } + fail("Not completed and no assertion error!"); + } + + @Test + public void testMultipleCompletions() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onComplete(); + ts.onComplete(); + try { + ts.assertComplete(); + } catch (AssertionError ex) { + // expected + return; + } + fail("Multiple completions and no assertion error!"); + } + + @Test + public void testCompleted() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onComplete(); + try { + ts.assertNotComplete(); + } catch (AssertionError ex) { + // expected + return; + } + fail("Completed and no assertion error!"); + } + + @Test + public void testMultipleCompletions2() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onComplete(); + ts.onComplete(); + try { + ts.assertNotComplete(); + } catch (AssertionError ex) { + // expected + return; + } + fail("Multiple completions and no assertion error!"); + } + + @Test + public void testMultipleErrors() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(EmptySubscription.INSTANCE); + ts.onError(new TestException()); + ts.onError(new TestException()); + try { + ts.assertNoErrors(); + } catch (AssertionError ex) { + Throwable e = ex.getCause(); + if (!(e instanceof CompositeException)) { + fail("Multiple Error present but the reported error doesn't have a composite cause!"); + } + CompositeException ce = (CompositeException)e; + if (ce.size() != 2) { + ce.printStackTrace(); + } + assertEquals(2, ce.size()); + // expected + return; + } + fail("Multiple Error present but no assertion error!"); + } + + @Test + public void testMultipleErrors2() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(EmptySubscription.INSTANCE); + ts.onError(new TestException()); + ts.onError(new TestException()); + try { + ts.assertError(TestException.class); + } catch (AssertionError ex) { + Throwable e = ex.getCause(); + if (!(e instanceof CompositeException)) { + fail("Multiple Error present but the reported error doesn't have a composite cause!"); + } + CompositeException ce = (CompositeException)e; + assertEquals(2, ce.size()); + // expected + return; + } + fail("Multiple Error present but no assertion error!"); + } + + @Test + public void testMultipleErrors3() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(EmptySubscription.INSTANCE); + ts.onError(new TestException()); + ts.onError(new TestException()); + try { + ts.assertError(new TestException()); + } catch (AssertionError ex) { + Throwable e = ex.getCause(); + if (!(e instanceof CompositeException)) { + fail("Multiple Error present but the reported error doesn't have a composite cause!"); + } + CompositeException ce = (CompositeException)e; + assertEquals(2, ce.size()); + // expected + return; + } + fail("Multiple Error present but no assertion error!"); + } + + @Test + public void testMultipleErrors4() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(EmptySubscription.INSTANCE); + ts.onError(new TestException()); + ts.onError(new TestException()); + try { + ts.assertError(Functions.alwaysTrue()); + } catch (AssertionError ex) { + Throwable e = ex.getCause(); + if (!(e instanceof CompositeException)) { + fail("Multiple Error present but the reported error doesn't have a composite cause!"); + } + CompositeException ce = (CompositeException)e; + assertEquals(2, ce.size()); + // expected + return; + } + fail("Multiple Error present but no assertion error!"); + } + + @Test + public void testDifferentError() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onError(new TestException()); + try { + ts.assertError(new TestException()); + } catch (AssertionError ex) { + // expected + return; + } + fail("Different Error present but no assertion error!"); + } + + @Test + public void testDifferentError2() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onError(new RuntimeException()); + try { + ts.assertError(new TestException()); + } catch (AssertionError ex) { + // expected + return; + } + fail("Different Error present but no assertion error!"); + } + + @Test + public void testDifferentError3() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onError(new RuntimeException()); + try { + ts.assertError(TestException.class); + } + catch (AssertionError ex) { + // expected + return; + } + fail("Different Error present but no assertion error!"); + } + + @Test + public void testDifferentError4() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onError(new RuntimeException()); + try { + ts.assertError(Functions.alwaysFalse()); + } catch (AssertionError ex) { + // expected + return; + } + fail("Different Error present but no assertion error!"); + } + + @Test + public void testErrorInPredicate() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onError(new RuntimeException()); + try { + ts.assertError(new Predicate() { + @Override + public boolean test(Throwable throwable) throws Exception { + throw new TestException(); + } + }); + } catch (TestException ex) { + // expected + return; + } + fail("Error in predicate but not thrown!"); + } + + @Test + public void testNoError() { + TestSubscriberEx ts = new TestSubscriberEx(); + try { + ts.assertError(TestException.class); + } catch (AssertionError ex) { + // expected + return; + } + fail("No present but no assertion error!"); + } + + @Test + public void testNoError2() { + TestSubscriberEx ts = new TestSubscriberEx(); + try { + ts.assertError(new TestException()); + } catch (AssertionError ex) { + // expected + return; + } + fail("No present but no assertion error!"); + } + + @Test + public void testNoError3() { + TestSubscriberEx ts = new TestSubscriberEx(); + try { + ts.assertError(Functions.alwaysTrue()); + } catch (AssertionError ex) { + // expected + return; + } + fail("No present but no assertion error!"); + } + + @Test + public void testInterruptTerminalEventAwait() { + TestSubscriberEx ts = new TestSubscriberEx(); + + final Thread t0 = Thread.currentThread(); + Worker w = Schedulers.computation().createWorker(); + try { + w.schedule(new Runnable() { + @Override + public void run() { + t0.interrupt(); + } + }, 200, TimeUnit.MILLISECONDS); + + try { + if (ts.await(5, TimeUnit.SECONDS)) { + fail("Did not interrupt wait!"); + } + } catch (InterruptedException expected) { + // expected + } + } finally { + w.dispose(); + } + } + + @Test + public void testInterruptTerminalEventAwaitTimed() { + TestSubscriberEx ts = new TestSubscriberEx(); + + final Thread t0 = Thread.currentThread(); + Worker w = Schedulers.computation().createWorker(); + try { + w.schedule(new Runnable() { + @Override + public void run() { + t0.interrupt(); + } + }, 200, TimeUnit.MILLISECONDS); + + try { + if (ts.await(5, TimeUnit.SECONDS)) { + fail("Did not interrupt wait!"); + } + } catch (InterruptedException expected) { + // expected + } + } finally { + Thread.interrupted(); // clear interrupted flag + w.dispose(); + } + } + + @Test + public void testInterruptTerminalEventAwaitAndUnsubscribe() { + TestSubscriberEx ts = new TestSubscriberEx(); + + final Thread t0 = Thread.currentThread(); + Worker w = Schedulers.computation().createWorker(); + try { + w.schedule(new Runnable() { + @Override + public void run() { + t0.interrupt(); + } + }, 200, TimeUnit.MILLISECONDS); + + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } + + ts.dispose(); + if (!ts.isCancelled()) { + fail("Did not unsubscribe!"); + } + } finally { + w.dispose(); + } + } + + @Test + public void testNoTerminalEventBut1Completed() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onComplete(); + + try { + ts.assertNotTerminated(); + throw new RuntimeException("Failed to report there were terminal event(s)!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void testNoTerminalEventBut1Error() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onError(new TestException()); + + try { + ts.assertNotTerminated(); + throw new RuntimeException("Failed to report there were terminal event(s)!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void testNoTerminalEventBut1Error1Completed() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onComplete(); + ts.onError(new TestException()); + + try { + ts.assertNotTerminated(); + throw new RuntimeException("Failed to report there were terminal event(s)!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void testNoTerminalEventBut2Errors() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(EmptySubscription.INSTANCE); + + ts.onError(new TestException()); + ts.onError(new TestException()); + + try { + ts.assertNotTerminated(); + throw new RuntimeException("Failed to report there were terminal event(s)!"); + } catch (AssertionError ex) { + // expected + Throwable e = ex.getCause(); + if (!(e instanceof CompositeException)) { + fail("Multiple Error present but the reported error doesn't have a composite cause!"); + } + CompositeException ce = (CompositeException)e; + assertEquals(2, ce.size()); + } + } + + @Test + public void testNoValues() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onNext(1); + + try { + ts.assertNoValues(); + throw new RuntimeException("Failed to report there were values!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void testValueCount() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onNext(1); + ts.onNext(2); + + try { + ts.assertValueCount(3); + throw new RuntimeException("Failed to report there were values!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test(timeout = 1000) + public void testOnCompletedCrashCountsDownLatch() { + TestSubscriberEx ts0 = new TestSubscriberEx() { + @Override + public void onComplete() { + throw new TestException(); + } + }; + TestSubscriberEx ts = new TestSubscriberEx(ts0); + + try { + ts.onComplete(); + } catch (TestException ex) { + // expected + } + + ts.awaitDone(5, TimeUnit.SECONDS); + } + + @Test(timeout = 1000) + public void testOnErrorCrashCountsDownLatch() { + TestSubscriberEx ts0 = new TestSubscriberEx() { + @Override + public void onError(Throwable e) { + throw new TestException(); + } + }; + TestSubscriberEx ts = new TestSubscriberEx(ts0); + + try { + ts.onError(new RuntimeException()); + } catch (TestException ex) { + // expected + } + + ts.awaitDone(5, TimeUnit.SECONDS); + } + + @Test + public void createDelegate() { + TestSubscriberEx ts1 = new TestSubscriberEx(); + + TestSubscriberEx ts = new TestSubscriberEx(ts1); + + ts.assertNotSubscribed(); + + assertFalse(ts.hasSubscription()); + + ts.onSubscribe(new BooleanSubscription()); + + try { + ts.assertNotSubscribed(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + assertTrue(ts.hasSubscription()); + + assertFalse(ts.isDisposed()); + + ts.onNext(1); + ts.onError(new TestException()); + ts.onComplete(); + + ts1.assertValue(1).assertError(TestException.class).assertComplete(); + + ts.dispose(); + + assertTrue(ts.isDisposed()); + + assertSame(Thread.currentThread(), ts.lastThread()); + + try { + ts.assertNoValues(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertValueCount(0); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + ts.assertValueSequence(Collections.singletonList(1)); + + try { + ts.assertValueSequence(Collections.singletonList(2)); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + } + + @Test + public void assertError() { + TestSubscriberEx ts = new TestSubscriberEx(); + + try { + ts.assertError(TestException.class); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertError(new TestException()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertErrorMessage(""); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertError(Functions.alwaysTrue()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertSubscribed(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + ts.onSubscribe(new BooleanSubscription()); + + ts.assertSubscribed(); + + ts.assertNoErrors(); + + TestException ex = new TestException("Forced failure"); + + ts.onError(ex); + + ts.assertError(ex); + + ts.assertError(TestException.class); + + ts.assertErrorMessage("Forced failure"); + + ts.assertError(Functions.alwaysTrue()); + + ts.assertError(new Predicate() { + @Override + public boolean test(Throwable t) { + return t.getMessage() != null && t.getMessage().contains("Forced"); + } + }); + + try { + ts.assertErrorMessage(""); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertError(new RuntimeException()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertError(IOException.class); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertNoErrors(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + try { + ts.assertError(Functions.alwaysFalse()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError exc) { + // expected + } + + ts.assertTerminated(); + + ts.assertValueCount(0); + + ts.assertNoValues(); + } + + @Test + public void emptyObserverEnum() { + assertEquals(1, TestSubscriberEx.EmptySubscriber.values().length); + assertNotNull(TestSubscriberEx.EmptySubscriber.valueOf("INSTANCE")); + } + + @Test + public void valueAndClass() { + assertEquals("null", TestSubscriberEx.valueAndClass(null)); + assertEquals("1 (class: Integer)", TestSubscriberEx.valueAndClass(1)); + } + + @Test + public void assertFailure() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.onError(new TestException("Forced failure")); + + ts.assertFailure(TestException.class); + + ts.assertFailure(Functions.alwaysTrue()); + + ts.assertFailureAndMessage(TestException.class, "Forced failure"); + + ts.onNext(1); + + ts.assertFailure(TestException.class, 1); + + ts.assertFailure(Functions.alwaysTrue(), 1); + + ts.assertFailureAndMessage(TestException.class, "Forced failure", 1); + } + + @Test + public void assertFuseable() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.assertNotFuseable(); + + try { + ts.assertFuseable(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertFusionMode(QueueFuseable.SYNC); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + ts = new TestSubscriberEx(); + ts.setInitialFusionMode(QueueFuseable.ANY); + + ts.onSubscribe(new ScalarSubscription(ts, 1)); + + ts.assertFuseable(); + + ts.assertFusionMode(QueueFuseable.SYNC); + + try { + ts.assertFusionMode(QueueFuseable.NONE); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertNotFuseable(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + } + + @Test + public void assertTerminated() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.assertNotTerminated(); + + ts.onError(null); + + try { + ts.assertNotTerminated(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertResult() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.onComplete(); + + ts.assertResult(); + + try { + ts.assertResult(1); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + ts.onNext(1); + + ts.assertResult(1); + + try { + ts.assertResult(2); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertResult(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + } + + @Test(timeout = 5000) + public void await() throws Exception { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + assertFalse(ts.await(100, TimeUnit.MILLISECONDS)); + + ts.awaitDone(100, TimeUnit.MILLISECONDS); + + assertTrue(ts.isDisposed()); + + assertFalse(ts.await(100, TimeUnit.MILLISECONDS)); + + ts.assertNotComplete().assertNoErrors(); + + ts.onComplete(); + + assertTrue(ts.await(100, TimeUnit.MILLISECONDS)); + + ts.await(); + + ts.awaitDone(5, TimeUnit.SECONDS); + + ts.assertComplete().assertNoErrors(); + + assertTrue(ts.await(5, TimeUnit.SECONDS)); + + final TestSubscriberEx ts1 = new TestSubscriberEx(); + + ts1.onSubscribe(new BooleanSubscription()); + + Schedulers.single().scheduleDirect(new Runnable() { + @Override + public void run() { + ts1.onComplete(); + } + }, 200, TimeUnit.MILLISECONDS); + + ts1.await(); + } + + @Test + public void errors() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + assertEquals(0, ts.errors().size()); + + ts.onError(new TestException()); + + assertEquals(1, ts.errors().size()); + + TestHelper.assertError(ts.errors(), 0, TestException.class); + } + + @Test + public void onNext() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.assertNoValues(); + + assertEquals(Collections.emptyList(), ts.values()); + + ts.onNext(1); + + assertEquals(Collections.singletonList(1), ts.values()); + + ts.cancel(); + + assertTrue(ts.isCancelled()); + assertTrue(ts.isDisposed()); + + ts.assertValue(1); + + ts.onComplete(); + } + + @Test + public void fusionModeToString() { + assertEquals("NONE", TestSubscriberEx.fusionModeToString(QueueFuseable.NONE)); + assertEquals("SYNC", TestSubscriberEx.fusionModeToString(QueueFuseable.SYNC)); + assertEquals("ASYNC", TestSubscriberEx.fusionModeToString(QueueFuseable.ASYNC)); + assertEquals("Unknown(100)", TestSubscriberEx.fusionModeToString(100)); + } + + @Test + public void multipleTerminals() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.assertNotComplete(); + + ts.onComplete(); + + try { + ts.assertNotComplete(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + ts.assertTerminated(); + + ts.onComplete(); + + try { + ts.assertComplete(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + try { + ts.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + try { + ts.assertNotComplete(); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + } + + @Test + public void assertValue() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + try { + ts.assertValue(1); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + ts.onNext(1); + + ts.assertValue(1); + + try { + ts.assertValue(2); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + + ts.onNext(2); + + try { + ts.assertValue(1); + throw new RuntimeException("Should have thrown"); + } catch (Throwable ex) { + // expected + } + } + + @Test + public void onNextMisbehave() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onNext(1); + + ts.assertError(IllegalStateException.class); + + ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.onNext(null); + + ts.assertFailure(NullPointerException.class, (Integer)null); + } + + @Test + public void awaitTerminalEventInterrupt() { + final TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + Thread.currentThread().interrupt(); + + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } + + // FIXME ? catch consumes this flag + // assertTrue(Thread.interrupted()); + + Thread.currentThread().interrupt(); + + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException allowed) { + assertTrue(allowed.toString(), allowed.getCause() instanceof InterruptedException); + } + + // FIXME ? catch consumes this flag + // assertTrue(Thread.interrupted()); + } + + @Test + public void assertTerminated2() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.assertNotTerminated(); + + ts.onError(new TestException()); + + ts.assertTerminated(); + + ts.onError(new IOException()); + + try { + ts.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertError(TestException.class); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.onError(new TestException()); + ts.onComplete(); + + try { + ts.assertTerminated(); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void onSubscribe() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(null); + + ts.assertError(NullPointerException.class); + + ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + BooleanSubscription bs1 = new BooleanSubscription(); + + ts.onSubscribe(bs1); + + assertTrue(bs1.isCancelled()); + + ts.assertError(IllegalStateException.class); + + ts = new TestSubscriberEx(); + ts.dispose(); + + bs1 = new BooleanSubscription(); + + ts.onSubscribe(bs1); + + assertTrue(bs1.isCancelled()); + + } + + @Test + public void assertValueSequence() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + ts.onNext(1); + ts.onNext(2); + + try { + ts.assertValueSequence(Collections.emptyList()); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + try { + ts.assertValueSequence(Collections.singletonList(1)); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + + ts.assertValueSequence(Arrays.asList(1, 2)); + + try { + ts.assertValueSequence(Arrays.asList(1, 2, 3)); + throw new RuntimeException("Should have thrown"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertEmpty() { + TestSubscriberEx ts = new TestSubscriberEx(); + + try { + ts.assertEmpty(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + + ts.onSubscribe(new BooleanSubscription()); + + ts.assertEmpty(); + + ts.onNext(1); + + try { + ts.assertEmpty(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void awaitDoneTimed() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Thread.currentThread().interrupt(); + + try { + ts.awaitDone(5, TimeUnit.SECONDS); + } catch (RuntimeException ex) { + assertTrue(ex.toString(), ex.getCause() instanceof InterruptedException); + } + } + + @Test + public void assertNotSubscribed() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.assertNotSubscribed(); + + ts.errors().add(new TestException()); + + try { + ts.assertNotSubscribed(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertErrorMultiple() { + TestSubscriberEx ts = new TestSubscriberEx(); + + TestException e = new TestException(); + ts.errors().add(e); + ts.errors().add(new TestException()); + + try { + ts.assertError(TestException.class); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + try { + ts.assertError(e); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + try { + ts.assertErrorMessage(""); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertComplete() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onSubscribe(new BooleanSubscription()); + + try { + ts.assertComplete(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + + ts.onComplete(); + + ts.assertComplete(); + + ts.onComplete(); + + try { + ts.assertComplete(); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void completeWithoutOnSubscribe() { + TestSubscriberEx ts = new TestSubscriberEx(); + + ts.onComplete(); + + ts.assertError(IllegalStateException.class); + } + + @Test + public void completeDelegateThrows() { + TestSubscriberEx ts = new TestSubscriberEx(new FlowableSubscriber() { + + @Override + public void onSubscribe(Subscription s) { + + } + + @Override + public void onNext(Integer value) { + + } + + @Override + public void onError(Throwable e) { + throw new TestException(); + } + + @Override + public void onComplete() { + throw new TestException(); + } + + }); + + ts.onSubscribe(new BooleanSubscription()); + + try { + ts.onComplete(); + throw new RuntimeException("Should have thrown!"); + } catch (TestException ex) { + ts.assertTerminated(); + } + } + + @Test + public void errorDelegateThrows() { + TestSubscriberEx ts = new TestSubscriberEx(new FlowableSubscriber() { + + @Override + public void onSubscribe(Subscription s) { + + } + + @Override + public void onNext(Integer value) { + + } + + @Override + public void onError(Throwable e) { + throw new TestException(); + } + + @Override + public void onComplete() { + throw new TestException(); + } + + }); + + ts.onSubscribe(new BooleanSubscription()); + + try { + ts.onError(new IOException()); + throw new RuntimeException("Should have thrown!"); + } catch (TestException ex) { + ts.assertTerminated(); + } + } + + @Test + public void syncQueueThrows() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.setInitialFusionMode(QueueFuseable.SYNC); + + Flowable.range(1, 5) + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { throw new TestException(); } + }) + .subscribe(ts); + + ts.assertSubscribed() + .assertFuseable() + .assertFusionMode(QueueFuseable.SYNC) + .assertFailure(TestException.class); + } + + @Test + public void asyncQueueThrows() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.setInitialFusionMode(QueueFuseable.ANY); + + UnicastProcessor up = UnicastProcessor.create(); + + up + .map(new Function() { + @Override + public Object apply(Integer v) throws Exception { throw new TestException(); } + }) + .subscribe(ts); + + up.onNext(1); + + ts.assertSubscribed() + .assertFuseable() + .assertFusionMode(QueueFuseable.ASYNC) + .assertFailure(TestException.class); + } + + @Test + public void assertValuePredicateEmpty() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.empty().subscribe(ts); + + thrown.expect(AssertionError.class); + thrown.expectMessage("No values"); + ts.assertValue(new Predicate() { + @Override public boolean test(final Object o) throws Exception { + return false; + } + }); + } + + @Test + public void assertValuePredicateMatch() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1).subscribe(ts); + + ts.assertValue(new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertValuePredicateNoMatch() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1).subscribe(ts); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value not present"); + ts.assertValue(new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o != 1; + } + }); + } + + @Test + public void assertValuePredicateMatchButMore() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1, 2).subscribe(ts); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value present but other values as well"); + ts.assertValue(new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void assertValueAtPredicateEmpty() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.empty().subscribe(ts); + + thrown.expect(AssertionError.class); + thrown.expectMessage("No values"); + ts.assertValueAt(0, new Predicate() { + @Override public boolean test(final Object o) throws Exception { + return false; + } + }); + } + + @Test + public void assertValueAtPredicateMatch() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1, 2).subscribe(ts); + + ts.assertValueAt(1, new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 2; + } + }); + } + + @Test + public void assertValueAtPredicateNoMatch() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1, 2, 3).subscribe(ts); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Value not present"); + ts.assertValueAt(2, new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o != 3; + } + }); + } + + @Test + public void assertValueAtInvalidIndex() { + TestSubscriberEx ts = new TestSubscriberEx(); + + Flowable.just(1, 2).subscribe(ts); + + thrown.expect(AssertionError.class); + thrown.expectMessage("Invalid index: 2 (latch = 0, values = 2, errors = 0, completions = 1)"); + ts.assertValueAt(2, new Predicate() { + @Override public boolean test(final Integer o) throws Exception { + return o == 1; + } + }); + } + + @Test + public void requestMore() { + Flowable.range(1, 5) + .test(0) + .requestMore(1) + .assertValue(1) + .requestMore(2) + .assertValues(1, 2, 3) + .requestMore(3) + .assertResult(1, 2, 3, 4, 5); + } + + @Test + public void withTag() { + try { + for (int i = 1; i < 3; i++) { + Flowable.just(i) + .test() + .withTag("testing with item=" + i) + .assertResult(1) + ; + } + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + assertTrue(ex.toString(), ex.toString().contains("testing with item=2")); + } + } + + @Test + public void timeoutIndicated() throws InterruptedException { + Thread.interrupted(); // clear flag + + TestSubscriberEx ts = Flowable.never() + .to(TestHelper.testConsumer()); + assertFalse(ts.await(1, TimeUnit.MILLISECONDS)); + + try { + ts.assertResult(1); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + assertTrue(ex.toString(), ex.toString().contains("timeout!")); + } + } + + @Test + public void timeoutIndicated2() throws InterruptedException { + try { + Flowable.never() + .test() + .awaitDone(1, TimeUnit.MILLISECONDS) + .assertResult(1); + + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + assertTrue(ex.toString(), ex.toString().contains("timeout!")); + } + } + + @Test + public void timeoutIndicated3() throws InterruptedException { + TestSubscriberEx ts = Flowable.never() + .to(TestHelper.testConsumer()); + assertFalse(ts.await(1, TimeUnit.MILLISECONDS)); + + try { + ts.assertResult(1); + throw new RuntimeException("Should have thrown!"); + } catch (AssertionError ex) { + assertTrue(ex.toString(), ex.toString().contains("timeout!")); + } + } + + @Test + public void disposeIndicated() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.cancel(); + + try { + ts.assertResult(1); + throw new RuntimeException("Should have thrown!"); + } catch (Throwable ex) { + assertTrue(ex.toString(), ex.toString().contains("disposed!")); + } + } + + @Test + public void awaitCount() { + Flowable.range(1, 10).delay(100, TimeUnit.MILLISECONDS) + .test(5) + .awaitCount(5) + .assertValues(1, 2, 3, 4, 5) + .requestMore(5) + .awaitDone(5, TimeUnit.SECONDS) + .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + } + + @Test + public void awaitCountLess() { + Flowable.range(1, 4) + .test() + .awaitCount(5) + .assertResult(1, 2, 3, 4); + } + + @Test + public void assertValueAtPredicateThrows() { + try { + Flowable.just(1) + .test() + .assertValueAt(0, new Predicate() { + @Override + public boolean test(Integer t) throws Exception { + throw new IllegalArgumentException(); + } + }); + throw new RuntimeException("Should have thrown!"); + } catch (IllegalArgumentException ex) { + // expected + } + } + + @Test + public void assertValuesOnly() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(new BooleanSubscription()); + ts.assertValuesOnly(); + + ts.onNext(5); + ts.assertValuesOnly(5); + + ts.onNext(-1); + ts.assertValuesOnly(5, -1); + } + + @Test + public void assertValuesOnlyThrowsOnUnexpectedValue() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(new BooleanSubscription()); + ts.assertValuesOnly(); + + ts.onNext(5); + ts.assertValuesOnly(5); + + ts.onNext(-1); + + try { + ts.assertValuesOnly(5); + throw new RuntimeException(); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertValuesOnlyThrowsWhenCompleted() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(new BooleanSubscription()); + + ts.onComplete(); + + try { + ts.assertValuesOnly(); + throw new RuntimeException(); + } catch (AssertionError ex) { + // expected + } + } + + @Test + public void assertValuesOnlyThrowsWhenErrored() { + TestSubscriberEx ts = new TestSubscriberEx(); + ts.onSubscribe(new BooleanSubscription()); + + ts.onError(new TestException()); + + try { + ts.assertValuesOnly(); + throw new RuntimeException(); + } catch (AssertionError ex) { + // expected + } + } +} diff --git a/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java b/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java index 8f8acaf3d4..b74cda605e 100644 --- a/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java +++ b/src/test/java/io/reactivex/validators/CheckLocalVariablesInTests.java @@ -119,22 +119,22 @@ static void findPattern(String pattern, boolean checkMain) throws Exception { @Test public void testSubscriberAsTo() throws Exception { - findPattern("TestSubscriber<.*>\\s+to"); + findPattern("TestSubscriber(Ex)?<.*>\\s+to"); } @Test public void testObserverAsTs() throws Exception { - findPattern("TestObserver<.*>\\s+ts"); + findPattern("TestObserver(Ex)?<.*>\\s+ts"); } @Test public void testSubscriberNoArgAsTo() throws Exception { - findPattern("TestSubscriber\\s+to"); + findPattern("TestSubscriber(Ex)?\\s+to"); } @Test public void testObserverNoArgAsTs() throws Exception { - findPattern("TestObserver\\s+ts"); + findPattern("TestObserver(Ex)?\\s+ts"); } @Test diff --git a/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java index cb75c07366..e8ab6373be 100644 --- a/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java +++ b/src/test/java/io/reactivex/validators/ParamValidationCheckerTest.java @@ -30,6 +30,7 @@ import io.reactivex.parallel.*; import io.reactivex.plugins.RxJavaPlugins; import io.reactivex.schedulers.Schedulers; +import io.reactivex.testsupport.TestHelper; /** * Check that static and instance methods validate their parameters against