Search in sources :

Example 41 with InOrder

use of org.mockito.InOrder in project RxJava by ReactiveX.

the class FlowableConcatTest method testConcatUnsubscribeConcurrent.

/**
     * All observables will be running in different threads so subscribe() is unblocked. CountDownLatch is only used in order to call unsubscribe() in a predictable manner.
     */
@Test
public void testConcatUnsubscribeConcurrent() {
    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);
    @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.subscribe(ts);
    try {
        //Block main thread to allow observable "w1" to complete and observable "w2" to call onNext exactly once.
        callOnce.await();
        //"four" from w2 has been processed by onNext()
        ts.dispose();
        //"five" and "six" will NOT be processed by onNext()
        //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");
    verify(observer, never()).onComplete();
    verify(observer, never()).onError(any(Throwable.class));
}
Also used : InOrder(org.mockito.InOrder)

Example 42 with InOrder

use of org.mockito.InOrder in project RxJava by ReactiveX.

the class FlowableDebounceTest method debounceSelectorNormal1.

@Test
public void debounceSelectorNormal1() {
    PublishProcessor<Integer> source = PublishProcessor.create();
    final PublishProcessor<Integer> debouncer = PublishProcessor.create();
    Function<Integer, Flowable<Integer>> debounceSel = new Function<Integer, Flowable<Integer>>() {

        @Override
        public Flowable<Integer> apply(Integer t1) {
            return debouncer;
        }
    };
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    source.debounce(debounceSel).subscribe(o);
    source.onNext(1);
    debouncer.onNext(1);
    source.onNext(2);
    source.onNext(3);
    source.onNext(4);
    debouncer.onNext(2);
    source.onNext(5);
    source.onComplete();
    inOrder.verify(o).onNext(1);
    inOrder.verify(o).onNext(4);
    inOrder.verify(o).onNext(5);
    inOrder.verify(o).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
Also used : Function(io.reactivex.functions.Function) InOrder(org.mockito.InOrder)

Example 43 with InOrder

use of org.mockito.InOrder in project RxJava by ReactiveX.

the class FlowableDebounceTest method testDebounceNeverEmits.

@Test
public void testDebounceNeverEmits() {
    Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(Subscriber<? super String> observer) {
            observer.onSubscribe(new BooleanSubscription());
            // all should be skipped since they are happening faster than the 200ms timeout
            // Should be skipped
            publishNext(observer, 100, "a");
            // Should be skipped
            publishNext(observer, 200, "b");
            // Should be skipped
            publishNext(observer, 300, "c");
            // Should be skipped
            publishNext(observer, 400, "d");
            // Should be skipped
            publishNext(observer, 500, "e");
            // Should be skipped
            publishNext(observer, 600, "f");
            // Should be skipped
            publishNext(observer, 700, "g");
            // Should be skipped
            publishNext(observer, 800, "h");
            // Should be published as soon as the timeout expires.
            publishCompleted(observer, 900);
        }
    });
    Flowable<String> sampled = source.debounce(200, TimeUnit.MILLISECONDS, scheduler);
    sampled.subscribe(observer);
    scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(0)).onNext(anyString());
    scheduler.advanceTimeTo(1000, TimeUnit.MILLISECONDS);
    inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 44 with InOrder

use of org.mockito.InOrder in project RxJava by ReactiveX.

the class FlowableDebounceTest method testDebounceWithError.

@Test
public void testDebounceWithError() {
    Flowable<String> source = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(Subscriber<? super String> observer) {
            observer.onSubscribe(new BooleanSubscription());
            Exception error = new TestException();
            // Should be published since "two" will arrive after the timeout expires.
            publishNext(observer, 100, "one");
            // Should be skipped since onError will arrive before the timeout expires.
            publishNext(observer, 600, "two");
            // Should be published as soon as the timeout expires.
            publishError(observer, 700, error);
        }
    });
    Flowable<String> sampled = source.debounce(400, TimeUnit.MILLISECONDS, scheduler);
    sampled.subscribe(observer);
    scheduler.advanceTimeTo(0, TimeUnit.MILLISECONDS);
    InOrder inOrder = inOrder(observer);
    // 100 + 400 means it triggers at 500
    scheduler.advanceTimeTo(500, TimeUnit.MILLISECONDS);
    inOrder.verify(observer).onNext("one");
    scheduler.advanceTimeTo(701, TimeUnit.MILLISECONDS);
    inOrder.verify(observer).onError(any(TestException.class));
    inOrder.verifyNoMoreInteractions();
}
Also used : BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) InOrder(org.mockito.InOrder)

Example 45 with InOrder

use of org.mockito.InOrder in project RxJava by ReactiveX.

the class FlowableDelayTest method testDelaySubscription.

@Test
public void testDelaySubscription() {
    Flowable<Integer> result = Flowable.just(1, 2, 3).delaySubscription(100, TimeUnit.MILLISECONDS, scheduler);
    Subscriber<Object> o = TestHelper.mockSubscriber();
    InOrder inOrder = inOrder(o);
    result.subscribe(o);
    inOrder.verify(o, never()).onNext(any());
    inOrder.verify(o, never()).onComplete();
    scheduler.advanceTimeBy(100, TimeUnit.MILLISECONDS);
    inOrder.verify(o, times(1)).onNext(1);
    inOrder.verify(o, times(1)).onNext(2);
    inOrder.verify(o, times(1)).onNext(3);
    inOrder.verify(o, times(1)).onComplete();
    verify(o, never()).onError(any(Throwable.class));
}
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