use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class TestObserverTest method assertValuesOnlyThrowsWhenErrored.
@Test
public void assertValuesOnlyThrowsWhenErrored() {
TestObserver<Integer> to = TestObserver.create();
to.onSubscribe(Disposable.empty());
to.onError(new TestException());
try {
to.assertValuesOnly();
throw new RuntimeException();
} catch (AssertionError ex) {
// expected
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class TestObserverTest method createDelegate.
@Test
public void createDelegate() {
TestObserver<Integer> to1 = TestObserver.create();
TestObserver<Integer> to = TestObserver.create(to1);
assertFalse(to.hasSubscription());
to.onSubscribe(Disposable.empty());
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());
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
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class TestObserverTest method errorDelegateThrows.
@Test
public void errorDelegateThrows() {
TestObserver<Integer> to = new TestObserver<>(new Observer<Integer>() {
@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(Disposable.empty());
try {
to.onError(new IOException());
throw new RuntimeException("Should have thrown!");
} catch (TestException ex) {
to.assertNotComplete().assertError(Throwable.class);
}
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class TestObserverTest method assertError.
@Test
public void assertError() {
TestObserver<Integer> to = TestObserver.create();
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.<Throwable>alwaysTrue());
throw new RuntimeException("Should have thrown");
} catch (AssertionError ex) {
// expected
}
try {
to.assertSubscribed();
throw new RuntimeException("Should have thrown");
} catch (AssertionError exc) {
// expected
}
to.onSubscribe(Disposable.empty());
to.assertSubscribed();
to.assertNoErrors();
TestException ex = new TestException("Forced failure");
to.onError(ex);
to.assertError(ex);
to.assertError(TestException.class);
to.assertError(Functions.<Throwable>alwaysTrue());
to.assertError(new Predicate<Throwable>() {
@Override
public boolean test(Throwable t) throws Exception {
return t.getMessage() != null && t.getMessage().contains("Forced");
}
});
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.<Throwable>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.assertValueCount(0);
to.assertNoValues();
}
use of io.reactivex.rxjava3.observers.TestObserver in project RxJava by ReactiveX.
the class TestObserverTest method assertErrorMultiple.
@Test
public void assertErrorMultiple() {
TestObserver<Integer> to = new TestObserver<>();
TestException e = new TestException();
to.onError(e);
to.onError(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.<Throwable>alwaysTrue());
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
// expected
}
}
Aggregations