use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableThrottleFirstTest method testThrottlingWithCompleted.
@Test
public void testThrottlingWithCompleted() {
Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> observer) {
observer.onSubscribe(new BooleanSubscription());
// publish as it's first
publishNext(observer, 100, "one");
// skip as it's last within the first 400
publishNext(observer, 300, "two");
// publish
publishNext(observer, 900, "three");
// skip
publishNext(observer, 905, "four");
// Should be published as soon as the timeout expires.
publishCompleted(observer, 1000);
}
});
Flowable<String> sampled = source.throttleFirst(400, TimeUnit.MILLISECONDS, scheduler);
sampled.subscribe(observer);
InOrder inOrder = inOrder(observer);
scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(0)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(0)).onNext("four");
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableTimeIntervalTest method testTimeInterval.
@Test
public void testTimeInterval() {
InOrder inOrder = inOrder(observer);
observable.subscribe(observer);
testScheduler.advanceTimeBy(1000, TIME_UNIT);
subject.onNext(1);
testScheduler.advanceTimeBy(2000, TIME_UNIT);
subject.onNext(2);
testScheduler.advanceTimeBy(3000, TIME_UNIT);
subject.onNext(3);
subject.onComplete();
inOrder.verify(observer, times(1)).onNext(new Timed<Integer>(1, 1000, TIME_UNIT));
inOrder.verify(observer, times(1)).onNext(new Timed<Integer>(2, 2000, TIME_UNIT));
inOrder.verify(observer, times(1)).onNext(new Timed<Integer>(3, 3000, TIME_UNIT));
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored.
@Test
@Ignore("s should be considered cancelled upon executing onError and not expect downstream to call cancel")
public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyErrored() throws InterruptedException {
// From https://github.com/ReactiveX/RxJava/pull/951
final Subscription s = mock(Subscription.class);
Flowable<String> immediatelyError = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
subscriber.onError(new IOException("Error"));
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = immediatelyError.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onError(isA(IOException.class));
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldSwitchToOtherIfOnCompletedNotWithinTimeout.
@Test
public void shouldSwitchToOtherIfOnCompletedNotWithinTimeout() {
Flowable<String> other = Flowable.just("a", "b", "c");
Flowable<String> source = underlyingSubject.timeout(TIMEOUT, TIME_UNIT, testScheduler, other);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
source.subscribe(ts);
testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
underlyingSubject.onNext("One");
testScheduler.advanceTimeBy(4, TimeUnit.SECONDS);
underlyingSubject.onComplete();
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("One");
inOrder.verify(observer, times(1)).onNext("a");
inOrder.verify(observer, times(1)).onNext("b");
inOrder.verify(observer, times(1)).onNext("c");
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
ts.dispose();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableTimeoutTests method shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete.
@Test
@Ignore("s should be considered cancelled upon executing onComplete and not expect downstream to call cancel")
public void shouldUnsubscribeFromUnderlyingSubscriptionOnImmediatelyComplete() {
// From https://github.com/ReactiveX/RxJava/pull/951
final Subscription s = mock(Subscription.class);
Flowable<String> immediatelyComplete = Flowable.unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(Subscriber<? super String> subscriber) {
subscriber.onSubscribe(s);
subscriber.onComplete();
}
});
TestScheduler testScheduler = new TestScheduler();
Flowable<String> observableWithTimeout = immediatelyComplete.timeout(1000, TimeUnit.MILLISECONDS, testScheduler);
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer);
observableWithTimeout.subscribe(ts);
testScheduler.advanceTimeBy(2000, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
verify(s, times(1)).cancel();
}
Aggregations