use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableTests method testRangeWithScheduler.
@Test
public void testRangeWithScheduler() {
TestScheduler scheduler = new TestScheduler();
Flowable<Integer> observable = Flowable.range(3, 4).subscribeOn(scheduler);
Subscriber<Integer> observer = TestHelper.mockSubscriber();
observable.subscribe(observer);
scheduler.advanceTimeBy(1, TimeUnit.MILLISECONDS);
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext(3);
inOrder.verify(observer, times(1)).onNext(4);
inOrder.verify(observer, times(1)).onNext(5);
inOrder.verify(observer, times(1)).onNext(6);
inOrder.verify(observer, times(1)).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableThrottleWithTimeoutTests method testThrottle.
@Test
public void testThrottle() {
Subscriber<Integer> observer = TestHelper.mockSubscriber();
TestScheduler s = new TestScheduler();
PublishProcessor<Integer> o = PublishProcessor.create();
o.throttleWithTimeout(500, TimeUnit.MILLISECONDS, s).subscribe(observer);
// send events with simulated time increments
s.advanceTimeTo(0, TimeUnit.MILLISECONDS);
// skip
o.onNext(1);
// deliver
o.onNext(2);
s.advanceTimeTo(501, TimeUnit.MILLISECONDS);
// skip
o.onNext(3);
s.advanceTimeTo(600, TimeUnit.MILLISECONDS);
// skip
o.onNext(4);
s.advanceTimeTo(700, TimeUnit.MILLISECONDS);
// skip
o.onNext(5);
// deliver at 1300 after 500ms has passed since onNext(5)
o.onNext(6);
s.advanceTimeTo(1300, TimeUnit.MILLISECONDS);
// deliver
o.onNext(7);
s.advanceTimeTo(1800, TimeUnit.MILLISECONDS);
o.onComplete();
InOrder inOrder = inOrder(observer);
inOrder.verify(observer).onNext(2);
inOrder.verify(observer).onNext(6);
inOrder.verify(observer).onNext(7);
inOrder.verify(observer).onComplete();
inOrder.verifyNoMoreInteractions();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableConcatTest method testConcatConcurrentWithInfinity.
@Test
public void testConcatConcurrentWithInfinity() {
final TestObservable<String> w1 = new TestObservable<String>("one", "two", "three");
//This observable will send "hello" MAX_VALUE time.
final TestObservable<String> w2 = new TestObservable<String>("hello", Integer.MAX_VALUE);
Subscriber<String> observer = TestHelper.mockSubscriber();
@SuppressWarnings("unchecked") TestObservable<Flowable<String>> observableOfObservables = new TestObservable<Flowable<String>>(Flowable.unsafeCreate(w1), Flowable.unsafeCreate(w2));
Flowable<String> concatF = Flowable.concat(Flowable.unsafeCreate(observableOfObservables));
concatF.take(50).subscribe(observer);
//Wait for the thread to start up.
try {
w1.waitForThreadDone();
w2.waitForThreadDone();
} catch (InterruptedException e) {
e.printStackTrace();
}
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(1)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(47)).onNext("hello");
verify(observer, times(1)).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableConcatTest method testConcatNonBlockingObservables.
@Test
public void testConcatNonBlockingObservables() {
final CountDownLatch okToContinueW1 = new CountDownLatch(1);
final CountDownLatch okToContinueW2 = new CountDownLatch(1);
final TestObservable<String> w1 = new TestObservable<String>(null, okToContinueW1, "one", "two", "three");
final TestObservable<String> w2 = new TestObservable<String>(null, okToContinueW2, "four", "five", "six");
Subscriber<String> observer = TestHelper.mockSubscriber();
Flowable<Flowable<String>> observableOfObservables = Flowable.unsafeCreate(new Publisher<Flowable<String>>() {
@Override
public void subscribe(Subscriber<? super Flowable<String>> observer) {
observer.onSubscribe(new BooleanSubscription());
// simulate what would happen in an observable
observer.onNext(Flowable.unsafeCreate(w1));
observer.onNext(Flowable.unsafeCreate(w2));
observer.onComplete();
}
});
Flowable<String> concat = Flowable.concat(observableOfObservables);
concat.subscribe(observer);
verify(observer, times(0)).onComplete();
try {
// release both threads
okToContinueW1.countDown();
okToContinueW2.countDown();
// wait for both to finish
w1.t.join();
w2.t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(1)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(1)).onNext("four");
inOrder.verify(observer, times(1)).onNext("five");
inOrder.verify(observer, times(1)).onNext("six");
verify(observer, times(1)).onComplete();
}
use of org.mockito.InOrder in project RxJava by ReactiveX.
the class FlowableConcatTest method testConcatUnsubscribe.
/**
* Test unsubscribing the concatenated Flowable in a single thread.
*/
@Test
public void testConcatUnsubscribe() {
final CountDownLatch callOnce = new CountDownLatch(1);
final CountDownLatch okToContinue = new CountDownLatch(1);
final TestObservable<String> w1 = new TestObservable<String>("one", "two", "three");
final TestObservable<String> w2 = new TestObservable<String>(callOnce, okToContinue, "four", "five", "six");
Subscriber<String> observer = TestHelper.mockSubscriber();
TestSubscriber<String> ts = new TestSubscriber<String>(observer, 0L);
final Flowable<String> concat = Flowable.concat(Flowable.unsafeCreate(w1), Flowable.unsafeCreate(w2));
try {
// Subscribe
concat.subscribe(ts);
//Block main thread to allow observable "w1" to complete and observable "w2" to call onNext once.
callOnce.await();
// Unsubcribe
ts.dispose();
//Unblock the observable to continue.
okToContinue.countDown();
w1.t.join();
w2.t.join();
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
InOrder inOrder = inOrder(observer);
inOrder.verify(observer, times(1)).onNext("one");
inOrder.verify(observer, times(1)).onNext("two");
inOrder.verify(observer, times(1)).onNext("three");
inOrder.verify(observer, times(1)).onNext("four");
inOrder.verify(observer, never()).onNext("five");
inOrder.verify(observer, never()).onNext("six");
inOrder.verify(observer, never()).onComplete();
}
Aggregations