private ArgumentCaptor<HttpHeaders> setupInfoRequest(boolean webSocketEnabled) { ArgumentCaptor<HttpHeaders> headersCaptor = ArgumentCaptor.forClass(HttpHeaders.class); when(this.infoReceiver.executeInfoRequest(any(), headersCaptor.capture())).thenReturn( "{\"entropy\":123," + "\"origins\":[\"*:*\"]," + "\"cookie_needed\":true," + "\"websocket\":" + webSocketEnabled + "}"); return headersCaptor; }
@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); }
private void testDefaultMediaType(MediaType negotiatedMediaType) { this.mediaTypeCaptor = ArgumentCaptor.forClass(MediaType.class); MimeType defaultContentType = MimeTypeUtils.TEXT_XML; HttpMessageWriter<String> writer = getWriter(defaultContentType); writer.write(Mono.just("body"), forClass(String.class), negotiatedMediaType, this.response, NO_HINTS); assertEquals(defaultContentType, this.response.getHeaders().getContentType()); assertEquals(defaultContentType, this.mediaTypeCaptor.getValue()); }
@Test public void onTimeoutBeforeHandlerInitialized() throws Exception { Runnable runnable = mock(Runnable.class); this.emitter.onTimeout(runnable); this.emitter.initialize(this.handler); ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class); verify(this.handler).onTimeout(captor.capture()); verify(this.handler).onCompletion(any()); assertNotNull(captor.getValue()); captor.getValue().run(); verify(runnable).run(); }
@Before public void setup() throws Exception { initMocks(this); new SystemEnvironment().setProperty(SystemEnvironment.INTERVAL, "60"); // so the thread does not wake up requestArgumentCaptor = ArgumentCaptor.forClass(String.class); doNothing().when(consoleAppender).append(requestArgumentCaptor.capture()); transmitter = new ConsoleOutputTransmitter(consoleAppender, 0, mock(ScheduledThreadPoolExecutor.class)); }
@Test public void testLoadBitmap_asDrawable() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); requestManager .load(bitmap) .into(target); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(target).onResourceReady(captor.capture(), any(Transition.class)); BitmapDrawable drawable = (BitmapDrawable) captor.getValue(); assertThat(drawable.getBitmap()).isEqualTo(bitmap); }
@Test public void onTimeoutAfterHandlerInitialized() throws Exception { this.emitter.initialize(this.handler); ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class); verify(this.handler).onTimeout(captor.capture()); verify(this.handler).onCompletion(any()); Runnable runnable = mock(Runnable.class); this.emitter.onTimeout(runnable); assertNotNull(captor.getValue()); captor.getValue().run(); verify(runnable).run(); }
@Test public void onCompletionBeforeHandlerInitialized() throws Exception { Runnable runnable = mock(Runnable.class); this.emitter.onCompletion(runnable); this.emitter.initialize(this.handler); ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class); verify(this.handler).onTimeout(any()); verify(this.handler).onCompletion(captor.capture()); assertNotNull(captor.getValue()); captor.getValue().run(); verify(runnable).run(); }
@Test public void onCompletionAfterHandlerInitialized() throws Exception { this.emitter.initialize(this.handler); ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class); verify(this.handler).onTimeout(any()); verify(this.handler).onCompletion(captor.capture()); Runnable runnable = mock(Runnable.class); this.emitter.onCompletion(runnable); assertNotNull(captor.getValue()); captor.getValue().run(); verify(runnable).run(); }
@Test public void testLoadDrawable() { Drawable drawable = new ColorDrawable(Color.RED); requestManager .load(drawable) .into(target); ArgumentCaptor<Drawable> drawableCaptor = ArgumentCaptor.forClass(Drawable.class); verify(target).onResourceReady(drawableCaptor.capture(), any(Transition.class)); assertThat(((ColorDrawable) drawableCaptor.getValue()).getColor()).isEqualTo(Color.RED); }
@Test public void testProvidesCurrentPlaceholderToAnimationIfPresent() { Drawable placeholder = new ColorDrawable(Color.BLACK); view.setImageDrawable(placeholder); @SuppressWarnings("unchecked") Transition<Drawable> animation = mock(Transition.class); target.onResourceReady(new ColorDrawable(Color.GREEN), animation); ArgumentCaptor<Drawable> drawableCaptor = ArgumentCaptor.forClass(Drawable.class); verify(animation).transition(drawableCaptor.capture(), eq(target)); assertThat(((ColorDrawable) drawableCaptor.getValue()).getColor()).isEqualTo(Color.GREEN); }
private void testInactivityTaskScheduling(Runnable runnable, long delay, long sleepTime) throws InterruptedException { ArgumentCaptor<Runnable> inactivityTaskCaptor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(inactivityTaskCaptor.capture(), eq(delay/2)); verifyNoMoreInteractions(this.taskScheduler); if (sleepTime > 0) { Thread.sleep(sleepTime); } Runnable inactivityTask = inactivityTaskCaptor.getValue(); assertNotNull(inactivityTask); inactivityTask.run(); if (sleepTime > 0) { verify(runnable).run(); } else { verifyNoMoreInteractions(runnable); } }
private <Resource> List<Integer> getTargetsSizes( RequestBuilder<Resource> requestBuilder, VerificationMode mode) { ArgumentCaptor<Integer> integerArgumentCaptor = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Target<Resource>> targetArgumentCaptor = cast(ArgumentCaptor.forClass(Target.class)); SizeReadyCallback cb = mock(SizeReadyCallback.class); verify(requestBuilder, mode).into(targetArgumentCaptor.capture()); for (Target<Resource> target : targetArgumentCaptor.getAllValues()) { target.getSize(cb); } verify(cb, mode).onSizeReady(integerArgumentCaptor.capture(), integerArgumentCaptor.capture()); return integerArgumentCaptor.getAllValues(); }
private Runnable getUserRegistryTask() { BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this); this.handler.onApplicationEvent(event); ArgumentCaptor<? extends Runnable> captor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(captor.capture(), eq(10000L)); return captor.getValue(); }
@Test public void testSetColorFilterSetsColorFilterOnPaint() { ColorFilter colorFilter = new PorterDuffColorFilter(Color.RED, Mode.ADD); drawable.setColorFilter(colorFilter); // Use ArgumentCaptor instead of eq() due to b/73121412 where ShadowPorterDuffColorFilter.equals // uses a method that can't be found (PorterDuffColorFilter.getColor). ArgumentCaptor<ColorFilter> captor = ArgumentCaptor.forClass(ColorFilter.class); verify(paint).setColorFilter(captor.capture()); assertThat(captor.getValue()).isSameAs(colorFilter); }
@Test public void clientEndpointConfig() throws Exception { URI uri = new URI("ws://localhost/abc"); List<String> protocols = Collections.singletonList("abc"); this.headers.setSecWebSocketProtocol(protocols); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class); verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class)); ClientEndpointConfig endpointConfig = captor.getValue(); assertEquals(protocols, endpointConfig.getPreferredSubprotocols()); }
@Test public void clientEndpointConfigWithUserProperties() throws Exception { Map<String,Object> userProperties = Collections.singletonMap("foo", "bar"); URI uri = new URI("ws://localhost/abc"); this.wsClient.setUserProperties(userProperties); this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); ArgumentCaptor<ClientEndpointConfig> captor = ArgumentCaptor.forClass(ClientEndpointConfig.class); verify(this.wsContainer).connectToServer(any(Endpoint.class), captor.capture(), any(URI.class)); ClientEndpointConfig endpointConfig = captor.getValue(); assertEquals(userProperties, endpointConfig.getUserProperties()); }