@Test public void write() throws Exception { String body = "<root>Hello World</root>"; MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); Marshaller marshaller = mock(Marshaller.class); willDoNothing().given(marshaller).marshal(eq(body), isA(Result.class)); MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter(marshaller); converter.write(body, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "xml"), outputMessage.getHeaders().getContentType()); }
/** * Delegates call to {@link BDDMockito#doNothing()} */ default BDDMockito.BDDStubber willDoNothing() { return BDDMockito.willDoNothing(); }
/** * Delegates call to {@link BDDMockito#doNothing()} */ default BDDMockito.BDDStubber willDoNothing() { return BDDMockito.willDoNothing(); }
RabbitTemplate amqpTemplate = spy(new RabbitTemplate(connectionFactory)); AmqpOutboundEndpoint endpoint = new AmqpOutboundEndpoint(amqpTemplate); willDoNothing() .given(amqpTemplate).send(anyString(), anyString(), any(Message.class), isNull()); willAnswer(invocation -> invocation.getArgument(2))
/** * Continue the fluent chain by specifying that the mock will not return anything. * This delegates to {@link BDDMockito#willDoNothing()}. * * @return The next step in the fluent chain */ public FluentMockitoGivenCommand<Mock> willDoNothing() { return new FluentMockitoGivenCommand<>(mock, BDDMockito.willDoNothing()); } }
Log logger = spy(TestUtils.getPropertyValue(adapter, "logger", Log.class)); new DirectFieldAccessor(adapter).setPropertyValue("logger", logger); willDoNothing().given(logger).warn(anyString(), any(Throwable.class)); willAnswer(i -> { i.callRealMethod();
Log logger = spy(TestUtils.getPropertyValue(rabbitAdmin, "logger", Log.class)); willReturn(true).given(logger).isInfoEnabled(); willDoNothing().given(logger).info(anyString()); new DirectFieldAccessor(rabbitAdmin).setPropertyValue("logger", logger);
new DirectFieldAccessor(ack1).setPropertyValue("logger", log1); given(log1.isWarnEnabled()).willReturn(true); willDoNothing().given(log1).warn(any()); ack1.acknowledge(AcknowledgmentCallback.Status.REQUEUE); assertThat(received2.getHeaders().get(KafkaHeaders.OFFSET)).isEqualTo(1L); new DirectFieldAccessor(ack2).setPropertyValue("logger", log2); given(log2.isWarnEnabled()).willReturn(true); willDoNothing().given(log2).warn(any()); ack2.acknowledge(AcknowledgmentCallback.Status.ACCEPT); received1 = source.receive();
ConditionalRejectingErrorHandler handler = new ConditionalRejectingErrorHandler(); Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class)); willDoNothing().given(logger).warn(anyString(), any(Throwable.class)); new DirectFieldAccessor(handler).setPropertyValue("logger", logger); handler.handleError(new ListenerExecutionFailedException("intended", new RuntimeException(),