Java Code Examples for io.reactivex.rxjava3.observers.TestObserver#assertError()
The following examples show how to use
io.reactivex.rxjava3.observers.TestObserver#assertError() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplayingShareObservableTest.java From RxReplayingShare with Apache License 2.0 | 6 votes |
@Test public void errorClearsCacheAndResubscribes() { List<String> start = new ArrayList<>(); start.add("initA"); PublishSubject<String> upstream = PublishSubject.create(); Observable<String> replayed = upstream.startWithIterable(start).compose(ReplayingShare.<String>instance()); TestObserver<String> observer1 = new TestObserver<>(); replayed.subscribe(observer1); observer1.assertValues("initA"); TestObserver<String> observer2 = new TestObserver<>(); replayed.subscribe(observer2); observer1.assertValues("initA"); RuntimeException r = new RuntimeException(); upstream.onError(r); observer1.assertError(r); observer2.assertError(r); start.set(0, "initB"); TestObserver<String> observer3 = new TestObserver<>(); replayed.subscribe(observer3); observer3.assertValues("initB"); }
Example 2
Source File: UntilEventTransformerSingleTest.java From RxLifecycle with Apache License 2.0 | 6 votes |
@Test public void twoEvents() { TestObserver<String> testObserver = Single.just("1") .delay(1, TimeUnit.MILLISECONDS, testScheduler) .compose(RxLifecycle.<String, String>bindUntilEvent(lifecycle, "stop")) .test(); lifecycle.onNext("keep going"); testObserver.assertNoErrors(); lifecycle.onNext("stop"); testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); testObserver.assertNoValues(); testObserver.assertError(CancellationException.class); }
Example 3
Source File: TimeLimiterTransformerCompletableTest.java From resilience4j with Apache License 2.0 | 6 votes |
@Test public void otherError() { given(helloWorldService.returnHelloWorld()) .willThrow(new RuntimeException()); given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Completable.fromRunnable(helloWorldService::returnHelloWorld) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(RuntimeException.class); then(timeLimiter).should() .onError(any(RuntimeException.class)); }
Example 4
Source File: TimeLimiterTransformerMaybeTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeout() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Observable.interval(1, TimeUnit.MINUTES) .firstElement() .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(TimeoutException.class); then(timeLimiter).should() .onError(any(TimeoutException.class)); }
Example 5
Source File: OutsideLifecycleExceptionTest.java From RxLifecycle with Apache License 2.0 | 5 votes |
@Test public void eventThrowsBadException() { PublishSubject<String> stream = PublishSubject.create(); PublishSubject<String> lifecycle = PublishSubject.create(); TestObserver<String> testObserver = stream .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS)) .test(); // We get an error from the function for this lifecycle event lifecycle.onNext("ick"); stream.onNext("1"); testObserver.assertNoValues(); // We only want to check for our IllegalArgumentException, but may have // to wade through a CompositeException to get at it. testObserver.assertError(new Predicate<Throwable>() { @Override public boolean test(Throwable throwable) throws Exception { if (throwable instanceof CompositeException) { CompositeException ce = (CompositeException) throwable; for (Throwable t : ce.getExceptions()) { if (t instanceof IllegalArgumentException) { return true; } } } return false; } }); }
Example 6
Source File: UntilCorrespondingEventTransformerSingleTest.java From RxLifecycle with Apache License 2.0 | 5 votes |
@Test public void openAndCloseEvent() { TestObserver<String> testObserver = Single.just("1") .delay(1, TimeUnit.MILLISECONDS, testScheduler) .compose(RxLifecycle.<String, String>bind(lifecycle, CORRESPONDING_EVENTS)) .test(); lifecycle.onNext("create"); testObserver.assertNoErrors(); lifecycle.onNext("destroy"); testScheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS); testObserver.assertNoValues(); testObserver.assertError(CancellationException.class); }
Example 7
Source File: UntilEventTransformerCompletableTest.java From RxLifecycle with Apache License 2.0 | 5 votes |
@Test public void twoEvents() { TestObserver<Void> testObserver = completable .compose(RxLifecycle.bindUntilEvent(lifecycle, "stop")) .test(); lifecycle.onNext("keep going"); lifecycle.onNext("stop"); subject.onComplete(); testObserver.assertError(CancellationException.class); }
Example 8
Source File: UntilCorrespondingEventTransformerCompletableTest.java From RxLifecycle with Apache License 2.0 | 5 votes |
@Test public void openAndCloseEvent() { TestObserver<Void> testObserver = completable .compose(RxLifecycle.bind(lifecycle, CORRESPONDING_EVENTS)) .test(); lifecycle.onNext("create"); lifecycle.onNext("destroy"); subject.onComplete(); testObserver.assertError(CancellationException.class); }
Example 9
Source File: TimeLimiterTransformerSingleTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeout() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Single.timer(1, TimeUnit.MINUTES) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(TimeoutException.class); then(timeLimiter).should() .onError(any(TimeoutException.class)); }
Example 10
Source File: TimeLimiterTransformerSingleTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void otherError() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Single.error(new RuntimeException()) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(RuntimeException.class); then(timeLimiter).should() .onError(any(RuntimeException.class)); }
Example 11
Source File: TimeLimiterTransformerCompletableTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeout() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Maybe.timer(1, TimeUnit.MINUTES) .flatMapCompletable(t -> Completable.complete()) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(TimeoutException.class); then(timeLimiter).should() .onError(any(TimeoutException.class)); }
Example 12
Source File: TimeLimiterTransformerMaybeTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeoutEmpty() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Maybe.empty() .delay(1, TimeUnit.MINUTES) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(TimeoutException.class); then(timeLimiter).should() .onError(any(TimeoutException.class)); }
Example 13
Source File: UntilLifecycleTransformerCompletableTest.java From RxLifecycle with Apache License 2.0 | 5 votes |
@Test public void oneEvent() { TestObserver<Void> testObserver = completable .compose(RxLifecycle.bind(lifecycle)) .test(); lifecycle.onNext("stop"); subject.onComplete(); testObserver.assertError(CancellationException.class); }
Example 14
Source File: TimeLimiterTransformerMaybeTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void otherError() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Maybe.error(new RuntimeException()) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(RuntimeException.class); then(timeLimiter).should() .onError(any(RuntimeException.class)); }
Example 15
Source File: TimeLimiterTransformerObservableTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeoutEmpty() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Observable.empty() .delay(1, TimeUnit.MINUTES) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(TimeoutException.class); then(timeLimiter).should() .onError(any(TimeoutException.class)); }
Example 16
Source File: TimeLimiterTransformerObservableTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void timeout() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Observable.interval(1, TimeUnit.MINUTES) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(TimeoutException.class); then(timeLimiter).should() .onError(any(TimeoutException.class)); }
Example 17
Source File: TimeLimiterTransformerObservableTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void otherError() { given(timeLimiter.getTimeLimiterConfig()) .willReturn(toConfig(Duration.ZERO)); TestObserver<?> observer = Observable.error(new RuntimeException()) .compose(TimeLimiterTransformer.of(timeLimiter)) .test(); testScheduler.advanceTimeBy(1, TimeUnit.MINUTES); observer.assertError(RuntimeException.class); then(timeLimiter).should() .onError(any(RuntimeException.class)); }
Example 18
Source File: RxConnectablesTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void shouldPropagateErrorsFromUpstream() throws Exception { final Throwable expected = new RuntimeException("expected"); TestObserver<Integer> observer = input.compose(RxConnectables.toTransformer(connectable)).test(); input.onError(expected); observer.awaitDone(1, TimeUnit.SECONDS); observer.assertError(expected); }
Example 19
Source File: RxConnectablesTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void shouldPropagateErrorsFromConnectable() throws Exception { TestObserver<Integer> observer = input.compose(RxConnectables.toTransformer(connectable)).test(); input.onNext("crash"); observer.awaitDone(1, TimeUnit.SECONDS); observer.assertError(throwable -> throwable.getMessage().equals("crashing!")); }
Example 20
Source File: RxMobiusLoopTest.java From mobius with Apache License 2.0 | 5 votes |
@Test public void shouldPropagateIncomingErrorsAsUnrecoverable() throws Exception { final RxMobiusLoop<Integer, String, Boolean> loop = new RxMobiusLoop<>(builder, "", Collections.emptySet()); PublishSubject<Integer> input = PublishSubject.create(); TestObserver<String> subscriber = input.compose(loop).test(); Exception expected = new RuntimeException("expected"); input.onError(expected); subscriber.awaitDone(1, TimeUnit.SECONDS); subscriber.assertError(new UnrecoverableIncomingException(expected)); assertEquals(0, connection.valueCount()); }