use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class ReplayProcessorTest method testCompletedStopsEmittingData.
@Test
public void testCompletedStopsEmittingData() {
ReplayProcessor<Integer> channel = ReplayProcessor.create();
Subscriber<Object> observerA = TestHelper.mockSubscriber();
Subscriber<Object> observerB = TestHelper.mockSubscriber();
Subscriber<Object> observerC = TestHelper.mockSubscriber();
Subscriber<Object> observerD = TestHelper.mockSubscriber();
TestSubscriber<Object> ts = new TestSubscriber<Object>(observerA);
channel.subscribe(ts);
channel.subscribe(observerB);
InOrder inOrderA = inOrder(observerA);
InOrder inOrderB = inOrder(observerB);
InOrder inOrderC = inOrder(observerC);
InOrder inOrderD = inOrder(observerD);
channel.onNext(42);
// both A and B should have received 42 from before subscription
inOrderA.verify(observerA).onNext(42);
inOrderB.verify(observerB).onNext(42);
ts.dispose();
// a should receive no more
inOrderA.verifyNoMoreInteractions();
channel.onNext(4711);
// only be should receive 4711 at this point
inOrderB.verify(observerB).onNext(4711);
channel.onComplete();
// B is subscribed so should receive onComplete
inOrderB.verify(observerB).onComplete();
channel.subscribe(observerC);
// when C subscribes it should receive 42, 4711, onComplete
inOrderC.verify(observerC).onNext(42);
inOrderC.verify(observerC).onNext(4711);
inOrderC.verify(observerC).onComplete();
// if further events are propagated they should be ignored
channel.onNext(13);
channel.onNext(14);
channel.onNext(15);
channel.onError(new RuntimeException());
// a new subscription should only receive what was emitted prior to terminal state onComplete
channel.subscribe(observerD);
inOrderD.verify(observerD).onNext(42);
inOrderD.verify(observerD).onNext(4711);
inOrderD.verify(observerD).onComplete();
verify(observerA).onSubscribe((Subscription) notNull());
verify(observerB).onSubscribe((Subscription) notNull());
verify(observerC).onSubscribe((Subscription) notNull());
verify(observerD).onSubscribe((Subscription) notNull());
Mockito.verifyNoMoreInteractions(observerA);
Mockito.verifyNoMoreInteractions(observerB);
Mockito.verifyNoMoreInteractions(observerC);
Mockito.verifyNoMoreInteractions(observerD);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class ReplayProcessorTest method reentrantDrain.
@Test
public void reentrantDrain() {
TestScheduler scheduler = new TestScheduler();
final ReplayProcessor<Integer> rp = ReplayProcessor.createWithTimeAndSize(1, TimeUnit.SECONDS, scheduler, 2);
TestSubscriber<Integer> ts = new TestSubscriber<Integer>() {
@Override
public void onNext(Integer t) {
if (t == 1) {
rp.onNext(2);
}
super.onNext(t);
}
};
rp.subscribe(ts);
rp.onNext(1);
rp.onComplete();
ts.assertResult(1, 2);
}
use of io.reactivex.subscribers.TestSubscriber in project RxJava by ReactiveX.
the class TestObserverTest method testTerminalErrorOnce.
@Test
public void testTerminalErrorOnce() {
TestSubscriber<Integer> to = new TestSubscriber<Integer>();
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!");
}
Aggregations