Search in sources :

Example 31 with InOrder

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();
}
Also used : InOrder(org.mockito.InOrder)

Example 32 with InOrder

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();
}
Also used : InOrder(org.mockito.InOrder) TestScheduler(io.reactivex.schedulers.TestScheduler) Test(org.junit.Test)

Example 33 with InOrder

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));
}
Also used : InOrder(org.mockito.InOrder)

Example 34 with InOrder

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();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 35 with InOrder

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();
}
Also used : InOrder(org.mockito.InOrder)

Aggregations

InOrder (org.mockito.InOrder)3292 Test (org.junit.Test)2308 Test (org.junit.jupiter.api.Test)377 AbstractRestServiceTest (org.camunda.bpm.engine.rest.AbstractRestServiceTest)108 HashMap (java.util.HashMap)104 ArrayList (java.util.ArrayList)98 Response (com.jayway.restassured.response.Response)79 Matchers.containsString (org.hamcrest.Matchers.containsString)69 IOException (java.io.IOException)64 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)63 SmallTest (org.mule.tck.size.SmallTest)62 List (java.util.List)57 CompletableFuture (java.util.concurrent.CompletableFuture)52 Cleanup (lombok.Cleanup)46 InvocationOnMock (org.mockito.invocation.InvocationOnMock)46 WireCommands (io.pravega.shared.protocol.netty.WireCommands)45 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)44 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)44 Metadata (io.grpc.Metadata)43 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)41