@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(); }
@Override protected void setUp() throws Exception { super.setUp(); hasher = mock(Hasher.class); hashFunction = mock(HashFunction.class); when(hashFunction.newHasher()).thenReturn(hasher); }
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(); }
@Test public void testCancelledBeforeSubscribe() throws Exception { @SuppressWarnings("unchecked") Future<Object> future = mock(Future.class); CancellationException e = new CancellationException("unit test synthetic cancellation"); when(future.get()).thenThrow(e); Observer<Object> o = TestHelper.mockObserver(); TestObserver<Object> to = new TestObserver<Object>(o); to.dispose(); Observable.fromFuture(future).subscribe(to); to.assertNoErrors(); to.assertNotComplete(); }
@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(); }
@Test public void testCancelledBeforeSubscribe() throws Exception { @SuppressWarnings("unchecked") Future<Object> future = mock(Future.class); CancellationException e = new CancellationException("unit test synthetic cancellation"); when(future.get()).thenThrow(e); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); TestSubscriber<Object> ts = new TestSubscriber<Object>(subscriber); ts.dispose(); Flowable.fromFuture(future).subscribe(ts); ts.assertNoErrors(); ts.assertNotComplete(); }
@Override protected void setUp() throws Exception { super.setUp(); hasher = mock(Hasher.class); hashFunction = mock(HashFunction.class); buffer = new ByteArrayInputStream(testBytes); when(hashFunction.newHasher()).thenReturn(hasher); }
@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(); }
@SuppressWarnings("unchecked") @Override protected void setUp() { backingMap = mock(ConcurrentMap.class); when(backingMap.isEmpty()).thenReturn(true); multiset = new ConcurrentHashMultiset<>(backingMap); }
public void testShutdownAndAwaitTermination_immediateShutdownInternal() throws Exception { ExecutorService service = mock(ExecutorService.class); when(service.awaitTermination(HALF_SECOND_NANOS, NANOSECONDS)).thenReturn(true); when(service.isTerminated()).thenReturn(true); assertTrue(shutdownAndAwaitTermination(service, 1L, SECONDS)); verify(service).shutdown(); verify(service).awaitTermination(HALF_SECOND_NANOS, NANOSECONDS); }
private <T> HandlerMethodArgumentResolver stubResolver(Mono<Object> stubValue) { HandlerMethodArgumentResolver resolver = mock(HandlerMethodArgumentResolver.class); when(resolver.supportsParameter(any())).thenReturn(true); when(resolver.resolveArgument(any(), any(), any())).thenReturn(stubValue); return resolver; }
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(); }
@Before public void setup() { when(this.client.getWebConnection()).thenReturn(mock(WebConnection.class)); this.builder = new MockMvcWebConnectionBuilderSupport(this.wac) {}; }
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(); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); WebSocketClient webSocketClient = mock(WebSocketClient.class); this.stompClient = new TestWebSocketStompClient(webSocketClient); this.stompClient.setTaskScheduler(this.taskScheduler); this.stompClient.setStompSession(this.stompSession); this.webSocketHandlerCaptor = ArgumentCaptor.forClass(WebSocketHandler.class); this.handshakeFuture = new SettableListenableFuture<>(); when(webSocketClient.doHandshake(this.webSocketHandlerCaptor.capture(), any(), any(URI.class))) .thenReturn(this.handshakeFuture); }
@Test public void attribute() { String name = "foo"; String value = "bar"; when(mockRequest.attribute(name)).thenReturn(Optional.of(value)); assertEquals(Optional.of(value), wrapper.attribute(name)); }
@Before public void setup() { this.protocolHandler = new StompSubProtocolHandler(); this.channel = Mockito.mock(MessageChannel.class); this.messageCaptor = ArgumentCaptor.forClass(Message.class); when(this.channel.send(any())).thenReturn(true); this.session = new TestWebSocketSession(); this.session.setId("s1"); this.session.setPrincipal(new TestPrincipal("joe")); }
@Test public void queryParam() { String name = "foo"; String value = "bar"; when(mockRequest.queryParam(name)).thenReturn(Optional.of(value)); assertEquals(Optional.of(value), wrapper.queryParam(name)); }
@Test public void getUserFromLocalRegistry() throws Exception { SimpUser user = Mockito.mock(SimpUser.class); Set<SimpUser> users = Collections.singleton(user); when(this.localRegistry.getUsers()).thenReturn(users); when(this.localRegistry.getUserCount()).thenReturn(1); when(this.localRegistry.getUser("joe")).thenReturn(user); assertEquals(1, this.registry.getUserCount()); assertSame(user, this.registry.getUser("joe")); }
@SuppressWarnings("unchecked") @Test public void shouldCallOnNextAndOnCompleted() throws Exception { Callable<String> func = mock(Callable.class); when(func.call()).thenReturn("test_value"); Observable<String> fromCallableObservable = Observable.fromCallable(func); Observer<Object> observer = TestHelper.mockObserver(); fromCallableObservable.subscribe(observer); verify(observer).onNext("test_value"); verify(observer).onComplete(); verify(observer, never()).onError(any(Throwable.class)); }