use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class TestObserverExTest method assertError.
@Test
public void assertError() {
TestObserverEx<Integer> 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.<Throwable>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(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");
}
});
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.<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.assertTerminated();
to.assertValueCount(0);
to.assertNoValues();
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableSubscriberTest method doubleSubscribe.
@Test
public void doubleSubscribe() {
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
return true;
}
}, Functions.<Throwable>emptyConsumer(), Functions.EMPTY_ACTION);
List<Throwable> list = TestHelper.trackPluginErrors();
try {
s.onSubscribe(new BooleanSubscription());
BooleanSubscription bs = new BooleanSubscription();
s.onSubscribe(bs);
assertTrue(bs.isCancelled());
TestHelper.assertError(list, 0, IllegalStateException.class, "Subscription already set!");
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableSubscriberTest method onNextCrashes.
@Test
public void onNextCrashes() {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
throw new TestException();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
BooleanSubscription b = new BooleanSubscription();
s.onSubscribe(b);
s.onNext(1);
assertTrue(b.isCancelled());
ts.assertFailure(TestException.class);
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableSubscriberTest method suppressAfterCompleteEvents.
@Test
public void suppressAfterCompleteEvents() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
final TestSubscriber<Integer> ts = new TestSubscriber<>();
ts.onSubscribe(new BooleanSubscription());
ForEachWhileSubscriber<Integer> s = new ForEachWhileSubscriber<>(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
ts.onNext(v);
return true;
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
ts.onError(e);
}
}, new Action() {
@Override
public void run() throws Exception {
ts.onComplete();
}
});
s.onComplete();
s.onNext(1);
s.onError(new TestException());
s.onComplete();
ts.assertResult();
TestHelper.assertUndeliverable(errors, 0, TestException.class);
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.functions.Predicate in project RxJava by ReactiveX.
the class FlowableSubscriberTest method forEachWhile.
@Test
public void forEachWhile() {
PublishProcessor<Integer> pp = PublishProcessor.create();
final List<Integer> list = new ArrayList<>();
Disposable d = pp.forEachWhile(new Predicate<Integer>() {
@Override
public boolean test(Integer v) throws Exception {
list.add(v);
return v < 3;
}
});
assertFalse(d.isDisposed());
pp.onNext(1);
pp.onNext(2);
pp.onNext(3);
assertFalse(pp.hasSubscribers());
assertEquals(Arrays.asList(1, 2, 3), list);
}
Aggregations