@Test public void monoLogWithGivenLogger() { Level level = Level.WARNING; Mono<String> source = Mono.just("foo"); Logger mockLogger = Mockito.mock(Logger.class); source.log(mockLogger, level, false, SignalType.ON_NEXT) .subscribe(); verify(mockLogger, only()).warn(anyString(), eq(SignalType.ON_NEXT), eq("foo")); verifyNoMoreInteractions(mockLogger); }
@Test public void transferSuccess() { @SuppressWarnings("unchecked") final AsyncMethodCallback<String> callback = mock(AsyncMethodCallback.class); AsyncMethodCallbacks.transfer(completedFuture("foo"), callback); verify(callback, only()).onComplete("foo"); }
@Test public void detectOnSwipeLeft() { MotionEvent ev1 = MotionEvent.obtain(10, 10, 0, 300, 50, 0); MotionEvent ev2 = MotionEvent.obtain(10, 10, 0, 100, 60, 0); testTouchTypeDetector.gestureListener.onFling(ev1, ev2, 201, 201); verify(mockListener, only()).onSwipe(SWIPE_DIR_LEFT); }
@Test public void fluxLogWithGivenLogger() { Level level = Level.WARNING; Flux<String> source = Flux.just("foo"); Logger mockLogger = Mockito.mock(Logger.class); source.log(mockLogger, level, false, SignalType.ON_NEXT) .subscribe(); verify(mockLogger, only()).warn(anyString(), eq(SignalType.ON_NEXT), eq("foo")); verifyNoMoreInteractions(mockLogger); }
@Test public void transferFailure_Throwable() { @SuppressWarnings("unchecked") final AsyncMethodCallback<String> callback = mock(AsyncMethodCallback.class); AsyncMethodCallbacks.transfer(exceptionallyCompletedFuture(new Throwable("foo")), callback); verify(callback, only()).onError(argThat(argument -> { return argument instanceof CompletionException && "foo".equals(argument.getCause().getMessage()); })); }
@Test public void execute() throws Exception { final HelloService.Iface client = helloClient(retryOnException, 100); when(serviceHandler.hello(anyString())).thenReturn("world"); assertThat(client.hello("hello")).isEqualTo("world"); verify(serviceHandler, only()).hello("hello"); }
@Test public void transferCallbackError() { @SuppressWarnings("unchecked") final AsyncMethodCallback<String> callback = mock(AsyncMethodCallback.class); doThrow(new AnticipatedException()).when(callback).onComplete(any()); AsyncMethodCallbacks.transfer(completedFuture("foo"), callback); verify(callback, only()).onComplete("foo"); } }
@Test public void shouldPersist() { Notification notification = new Notification("test"); underTest.scheduleForSending(notification); verify(notificationQueueDao, only()).insert(any(List.class)); }
@Test public void propagateLastResponseWhenNextRetryIsAfterTimeout() throws Exception { final RetryStrategyWithContent<RpcResponse> strategy = (ctx, response) -> CompletableFuture.completedFuture(Backoff.fixed(10000000)); final HelloService.Iface client = helloClient(strategy, 100); when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException()); final Throwable thrown = catchThrowable(() -> client.hello("hello")); assertThat(thrown).isInstanceOf(TApplicationException.class); assertThat(((TApplicationException) thrown).getType()).isEqualTo(TApplicationException.INTERNAL_ERROR); verify(serviceHandler, only()).hello("hello"); }
@Test public void detectOnLongPress() { testTouchTypeDetector.gestureListener.onLongPress(null); verify(mockListener, only()).onLongPress(); }
@Test public void shouldInvokeConsumerForEachKeyWithHighestPrecedenceOnce() throws URISyntaxException { DiscoverableURIs discoverables = new DiscoverableURIs.Builder() .add( "a", "/test1", LOWEST ) .add( "a", "/test2", LOW ) .add( "a", "/data3", NORMAL ) .add( "a", "/test4", HIGH ) .add( "a", "/test5", HIGHEST ) .build(); discoverables.forEach( consumer ); verify( consumer, only() ).accept( "a", new URI( "/test5" ) ); }
@Test public void transferFailure_Exception() { @SuppressWarnings("unchecked") final AsyncMethodCallback<String> callback = mock(AsyncMethodCallback.class); AsyncMethodCallbacks.transfer(exceptionallyCompletedFuture(new AnticipatedException()), callback); verify(callback, only()).onError(isA(AnticipatedException.class)); }
@Test public void detectShakeWithDoubleGravityForCustomThreshold() { testDetector(9, 1000).onSensorChanged(testAccelerometerEvent(new float[]{0, 0, 2 * 9.81f})); verify(mockListener, only()).onShakeDetected(); }
@Test public void detectOnDarkWithLuxLessThanCustomThreshold() { testDetector(9).onSensorChanged(testLightEvent(new float[]{3})); verify(mockListener, only()).onDark(); }
@Test public void detectOnLightWithExtraValues() { testDetector().onSensorChanged(testLightEvent(new float[]{10, 0, 43, 3, -423})); verify(mockListener, only()).onLight(); }
@Test public void detectShakeWithDoubleGravity() { testDetector().onSensorChanged(testAccelerometerEvent(new float[]{0, 0, 2 * 9.81f})); verify(mockListener, only()).onShakeDetected(); }
@Test public void detectOnLightWithLuxEqualsToCustomThreshold() { testDetector(9).onSensorChanged(testLightEvent(new float[]{9})); verify(mockListener, only()).onLight(); }
@Test public void detectLeftSideUp() { testOrientationDetector.onSensorChanged( testAccelerometerEvent(new float[]{-9.81f, 0, -9.81f})); testOrientationDetector.onSensorChanged(testMagneticEvent(new float[]{0, 0, 1})); verify(mockListener, only()).onLeftSideUp(); }
@Test public void detectBottomSideUp() { testOrientationDetector.onSensorChanged( testAccelerometerEvent(new float[]{-9.81f, -9.81f, -9.81f})); testOrientationDetector.onSensorChanged(testMagneticEvent(new float[]{0, 0, 1})); verify(mockListener, only()).onBottomSideUp(); }
@Test public void detectTopSideUp() { testOrientationDetector.onSensorChanged( testAccelerometerEvent(new float[]{9.81f, 9.81f, 9.81f})); testOrientationDetector.onSensorChanged(testMagneticEvent(new float[]{0, 0, 1})); verify(mockListener, only()).onTopSideUp(); }