private HttpMessageWriter<String> getWriter(Flux<DataBuffer> encodedStream, MimeType... mimeTypes) { List<MimeType> typeList = Arrays.asList(mimeTypes); when(this.encoder.getEncodableMimeTypes()).thenReturn(typeList); when(this.encoder.encode(any(), any(), any(), this.mediaTypeCaptor.capture(), any())).thenReturn(encodedStream); return new EncoderHttpMessageWriter<>(this.encoder); }
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; }
@Test public void convertAndSendPayloadAndHeaders() throws JMSException { Destination destination = new Destination() {}; Map<String, Object> headers = new HashMap<>(); headers.put("foo", "bar"); this.messagingTemplate.convertAndSend(destination, "Hello", headers); verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture()); assertTextMessage(this.messageCreator.getValue()); // see createTextMessage }
@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 expire_reschedule() { when(cache.evictEntry(captor.capture(), any(), anyLong())).thenAnswer(invocation -> { Timer timer = (Timer) invocation.getArgument(0); timer.setVariableTime(timerWheel.nanos + 100); return false; }); timerWheel.schedule(new Timer(100)); timerWheel.advance(TimerWheel.SPANS[0]); verify(cache).evictEntry(any(), any(), anyLong()); assertThat(captor.getValue().getNextInVariableOrder(), is(not(nullValue()))); assertThat(captor.getValue().getPreviousInVariableOrder(), is(not(nullValue()))); }
private Message<String> startSession(String id) { this.messageHandler.start(); Message<String> connectMessage = createConnectMessage(id, new TestPrincipal("joe"), null); this.messageHandler.setTaskScheduler(this.taskScheduler); this.messageHandler.handleMessage(connectMessage); verify(this.clientOutChannel, times(1)).send(this.messageCaptor.capture()); reset(this.clientOutChannel); return connectMessage; }
@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 convertAndSendPayloadAndHeadersName() throws JMSException { Map<String, Object> headers = new HashMap<>(); headers.put("foo", "bar"); this.messagingTemplate.convertAndSend("myQueue", "Hello", headers); verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture()); assertTextMessage(this.messageCreator.getValue()); // see createTextMessage }
@Before public void setup() { MockitoAnnotations.initMocks(this); this.exchangeFunction = mock(ExchangeFunction.class); when(this.exchangeFunction.exchange(this.captor.capture())).thenReturn(Mono.empty()); this.builder = WebClient.builder().baseUrl("/base").exchangeFunction(this.exchangeFunction); }
@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(); }
@Test public void test5() throws Exception { byte[] testContent = "Bla".getBytes(); SqlLobValue lob = new SqlLobValue(new ByteArrayInputStream(testContent), 3, handler); lob.setTypeValue(preparedStatement, 1, Types.CLOB, "test"); verify(creator).setClobAsAsciiStream(eq(preparedStatement), eq(1), inputStreamCaptor.capture(), eq(3)); byte[] bytes = new byte[3]; inputStreamCaptor.getValue().read(bytes); assertThat(bytes, equalTo(testContent)); }
@Before public void setUp() { MockitoAnnotations.initMocks(this); this.sessionHandler = mock(StompSessionHandler.class); this.connectHeaders = new StompHeaders(); this.session = new DefaultStompSession(this.sessionHandler, this.connectHeaders); this.session.setMessageConverter(new StringMessageConverter()); SettableListenableFuture<Void> future = new SettableListenableFuture<>(); future.set(null); when(this.connection.send(this.messageCaptor.capture())).thenReturn(future); }
@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 jsonView() throws Exception { given(this.messageChannel.send(any(Message.class))).willReturn(true); String sessionId = "sess1"; Message<?> inputMessage = createMessage(sessionId, "sub1", "/app", "/dest", null); this.jsonHandler.handleReturnValue(handleAndSendToJsonView(), this.jsonViewReturnType, inputMessage); verify(this.messageChannel).send(this.messageCaptor.capture()); Message<?> message = this.messageCaptor.getValue(); assertNotNull(message); String bytes = new String((byte[]) message.getPayload(), StandardCharsets.UTF_8); assertEquals("{\"withView1\":\"with\"}", bytes); }
@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 convertAndSendPayloadName() throws JMSException { this.messagingTemplate.convertAndSend("myQueue", "my Payload"); verify(this.jmsTemplate).send(eq("myQueue"), this.messageCreator.capture()); TextMessage textMessage = createTextMessage(this.messageCreator.getValue()); assertEquals("my Payload", textMessage.getText()); }
@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 convertAndSendPayload() throws JMSException { Destination destination = new Destination() {}; this.messagingTemplate.convertAndSend(destination, "my Payload"); verify(this.jmsTemplate).send(eq(destination), this.messageCreator.capture()); TextMessage textMessage = createTextMessage(this.messageCreator.getValue()); assertEquals("my Payload", textMessage.getText()); }