public void testAddDelayedShutdownHook_success() throws InterruptedException { TestApplication application = new TestApplication(); ExecutorService service = mock(ExecutorService.class); application.addDelayedShutdownHook(service, 2, TimeUnit.SECONDS); verify(service, Mockito.never()).shutdown(); application.shutdown(); InOrder shutdownFirst = Mockito.inOrder(service); shutdownFirst.verify(service).shutdown(); shutdownFirst.verify(service).awaitTermination(2, TimeUnit.SECONDS); }
@Test public void testSkipNothing() { Observable<Integer> src = Observable.just(5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(5); inOrder.verify(w, times(1)).onNext(3); inOrder.verify(w, times(1)).onNext(1); inOrder.verify(w, times(1)).onComplete(); inOrder.verify(w, never()).onError(any(Throwable.class)); }
@Test public void shouldNotOpenExplicitTransactionForPeriodicCommitQuery() throws Exception { KernelTransaction transaction = newTransaction(); TransactionStateMachineV1SPI stateMachineSPI = newTransactionStateMachineSPI( transaction ); when( stateMachineSPI.isPeriodicCommit( PERIODIC_COMMIT_QUERY ) ).thenReturn( true ); TransactionStateMachine stateMachine = newTransactionStateMachine( stateMachineSPI ); stateMachine.run( PERIODIC_COMMIT_QUERY, EMPTY_MAP ); // transaction was created only to stream back result of the periodic commit query assertEquals( transaction, stateMachine.ctx.currentTransaction ); InOrder inOrder = inOrder( stateMachineSPI ); inOrder.verify( stateMachineSPI ).isPeriodicCommit( PERIODIC_COMMIT_QUERY ); // periodic commit query was executed without starting an explicit transaction inOrder.verify( stateMachineSPI ).executeQuery( any( LoginContext.class ), eq( PERIODIC_COMMIT_QUERY ), eq( EMPTY_MAP ), any(), any() ); // explicit transaction was started only after query execution to stream the result inOrder.verify( stateMachineSPI ).beginTransaction( any( LoginContext.class ), any(), any() ); }
@Test public void testLastOrDefaultWithOneElement() { Single<Integer> o = Observable.just(1).last(2); SingleObserver<Integer> observer = TestHelper.mockSingleObserver(); o.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); // inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Test @Ignore("Null values no longer allowed") public void testDistinctOfSourceWithExceptionsFromKeySelector() { Observable<String> src = Observable.just("a", "b", null, "c"); src.distinct(TO_UPPER_WITH_EXCEPTION).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext("a"); inOrder.verify(w, times(1)).onNext("b"); inOrder.verify(w, times(1)).onError(any(NullPointerException.class)); inOrder.verify(w, never()).onNext(anyString()); inOrder.verify(w, never()).onComplete(); }
public void testSequential() { @SuppressWarnings("unchecked") Funnel<Object> elementFunnel = mock(Funnel.class); PrimitiveSink primitiveSink = mock(PrimitiveSink.class); Funnel<Iterable<?>> sequential = Funnels.sequentialFunnel(elementFunnel); sequential.funnel(Arrays.asList("foo", "bar", "baz", "quux"), primitiveSink); InOrder inOrder = inOrder(elementFunnel); inOrder.verify(elementFunnel).funnel("foo", primitiveSink); inOrder.verify(elementFunnel).funnel("bar", primitiveSink); inOrder.verify(elementFunnel).funnel("baz", primitiveSink); inOrder.verify(elementFunnel).funnel("quux", primitiveSink); }
@Test public void testSingleOrDefault() { Single<Integer> o = Observable.just(1).single(2); SingleObserver<Integer> observer = TestHelper.mockSingleObserver(); o.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); inOrder.verifyNoMoreInteractions(); }
@Test public void testSkipError() { Flowable<Integer> src = Flowable.just(1, 2, 42, 5, 3, 1); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, never()).onNext(anyInt()); inOrder.verify(w, never()).onComplete(); inOrder.verify(w, times(1)).onError(any(RuntimeException.class)); }
@Test public void testSkipSome() { Flowable<Integer> src = Flowable.just(1, 2, 3, 4, 5, 3, 1, 5); src.skipWhile(LESS_THAN_FIVE).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(5); inOrder.verify(w, times(1)).onNext(3); inOrder.verify(w, times(1)).onNext(1); inOrder.verify(w, times(1)).onNext(5); inOrder.verify(w, times(1)).onComplete(); inOrder.verify(w, never()).onError(any(Throwable.class)); }
@Test public void testSingleObservable() { Observable<Integer> o = Observable.just(1).singleElement().toObservable(); Observer<Integer> observer = TestHelper.mockObserver(); o.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onNext(1); inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Test public void testSkipAndCountBuffersWithGaps() { Observable<String> source = Observable.just("one", "two", "three", "four", "five"); Observable<List<String>> buffered = source.buffer(2, 3); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two")); inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five")); inOrder.verify(observer, Mockito.never()).onNext(Mockito.<String>anyList()); inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); inOrder.verify(observer, Mockito.times(1)).onComplete(); }
@Test public void testSingleOrDefaultWithEmpty() { Single<Integer> o = Observable.<Integer> empty() .single(1); SingleObserver<Integer> observer = TestHelper.mockSingleObserver(); o.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); inOrder.verifyNoMoreInteractions(); }
@Test public void testSkipWithIndex() { Flowable<Integer> src = Flowable.just(1, 2, 3, 4, 5); src.skipWhile(INDEX_LESS_THAN_THREE).subscribe(w); InOrder inOrder = inOrder(w); inOrder.verify(w, times(1)).onNext(4); inOrder.verify(w, times(1)).onNext(5); inOrder.verify(w, times(1)).onComplete(); inOrder.verify(w, never()).onError(any(Throwable.class)); }
@Test public void testLastOrDefault() { Single<Integer> single = Flowable.just(1, 2, 3) .last(4); SingleObserver<Integer> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(3); // inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Test public void testSkipAndCountGaplessBuffers() { Observable<String> source = Observable.just("one", "two", "three", "four", "five"); Observable<List<String>> buffered = source.buffer(3, 3); buffered.subscribe(observer); InOrder inOrder = Mockito.inOrder(observer); inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three")); inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five")); inOrder.verify(observer, Mockito.never()).onNext(Mockito.<String>anyList()); inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class)); inOrder.verify(observer, Mockito.times(1)).onComplete(); }
@Test public void testLastOrDefaultWithEmpty() { Single<Integer> single = Flowable.<Integer> empty() .last(1); SingleObserver<Integer> observer = TestHelper.mockSingleObserver(); single.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); // inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }
@Test public void testSkipLast1() { Flowable<String> flowable = Flowable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); Subscriber<String> subscriber = TestHelper.mockSubscriber(); InOrder inOrder = inOrder(subscriber); flowable.subscribe(subscriber); inOrder.verify(subscriber, never()).onNext("two"); inOrder.verify(subscriber, never()).onNext("three"); verify(subscriber, times(1)).onNext("one"); verify(subscriber, never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testLastWithOneElement() { Maybe<Integer> o = Observable.just(1).lastElement(); MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver(); o.subscribe(observer); InOrder inOrder = inOrder(observer); inOrder.verify(observer, times(1)).onSuccess(1); // inOrder.verify(observer, times(1)).onComplete(); inOrder.verifyNoMoreInteractions(); }