@SuppressWarnings("unchecked") @Test public void shouldNotInvokeFuncUntilSubscription() throws Exception { Callable<Object> func = mock(Callable.class); when(func.call()).thenReturn(new Object()); Single<Object> fromCallableSingle = Single.fromCallable(func); verifyZeroInteractions(func); fromCallableSingle.subscribe(); verify(func).call(); }
/** * This is testing a no-op path since it uses Schedulers.immediate() which will not do scheduling. */ @Test public void testObserveOn() { Observer<Integer> observer = TestHelper.mockObserver(); Observable.just(1, 2, 3).observeOn(ImmediateThinScheduler.INSTANCE).subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(2); verify(observer, times(1)).onNext(3); verify(observer, times(1)).onComplete(); }
public void testAddDelayedShutdownHook_interrupted() throws InterruptedException { TestApplication application = new TestApplication(); ExecutorService service = mock(ExecutorService.class); application.addDelayedShutdownHook(service, 2, TimeUnit.SECONDS); when(service.awaitTermination(2, TimeUnit.SECONDS)).thenThrow(new InterruptedException()); application.shutdown(); verify(service).shutdown(); }
@SuppressWarnings("unchecked") @Test public void shouldNotInvokeFuncUntilSubscription() throws Exception { Callable<Object> func = mock(Callable.class); when(func.call()).thenReturn(new Object()); Observable<Object> fromCallableObservable = Observable.fromCallable(func); verifyZeroInteractions(func); fromCallableObservable.subscribe(); verify(func).call(); }
@SuppressWarnings("unchecked") @Test public void shouldNotInvokeFuncUntilSubscription() throws Exception { Callable<Object> func = mock(Callable.class); when(func.call()).thenReturn(new Object()); Flowable<Object> fromCallableFlowable = Flowable.fromCallable(func); verifyZeroInteractions(func); fromCallableFlowable.subscribe(); verify(func).call(); }
@Test public void testSkipTwoElements() { Observable<String> skip = Observable.just("one", "two", "three").skip(2); Observer<String> observer = TestHelper.mockObserver(); skip.subscribe(observer); verify(observer, never()).onNext("one"); verify(observer, never()).onNext("two"); verify(observer, times(1)).onNext("three"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
public void testShutdownAndAwaitTermination_nonTerminationInternal() throws Exception { ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)) .thenReturn(false) .thenReturn(false); assertFalse(shutdownAndAwaitTermination(service, 1L, SECONDS)); verify(service).shutdown(); verify(service, times(2)).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); verify(service).shutdownNow(); }
@Test public void testListIterable() { Observable<String> o = Observable.fromIterable(Arrays.<String> asList("one", "two", "three")); Observer<String> observer = TestHelper.mockObserver(); o.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, times(1)).onNext("three"); verify(observer, Mockito.never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
public void testShutdownAndAwaitTermination_forcedShutDownInternal() throws Exception { ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)) .thenReturn(false) .thenReturn(true); when(service.isTerminated()).thenReturn(true); assertTrue(shutdownAndAwaitTermination(service, 1L, SECONDS)); verify(service).shutdown(); verify(service, times(2)).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); verify(service).shutdownNow(); }
@Test public void testCast() { Observable<?> source = Observable.just(1, 2); Observable<Integer> observable = source.cast(Integer.class); Observer<Integer> observer = TestHelper.mockObserver(); observable.subscribe(observer); verify(observer, times(1)).onNext(1); verify(observer, times(1)).onNext(1); verify(observer, never()).onError( any(Throwable.class)); verify(observer, times(1)).onComplete(); }