### Question:
MessageCapture { void capture(final Context context, final Request request, final CapturePoint mode) { StringWriter out = new StringWriter(); PrintWriter writer = new PrintWriter(out); String id = context.getId(); switch (mode) { case REQUEST: captureRequest(writer, request, id); break; case FILTERED_REQUEST: captureFilteredRequest(writer, request, id); break; default: throw new IllegalArgumentException("The given mode is not accepted: " + mode.name()); } if (captureContext) { writer.println("Context's content as JSON:"); captureContextAsJson(writer, context); } logger.info(out.toString()); } MessageCapture(final Logger logger, final boolean captureEntity);  MessageCapture(final Logger logger, final boolean captureEntity, final boolean captureContext);   }### Answer:
@Test public void shouldLogRequest() throws Exception { MessageCapture capture = new MessageCapture(logger, false); capture.capture(new RootContext(), new Request(), CapturePoint.REQUEST); verify(logger).info(anyString()); }
@Test public void shouldLogContext() throws Exception { MessageCapture capture = new MessageCapture(logger, false, true); AttributesContext attributesContext = new AttributesContext(new RootContext()); attributesContext.getAttributes().put("a", "b"); capture.capture(attributesContext, new Request(), CapturePoint.REQUEST); verify(logger).info(captor.capture()); assertThat(captor.getValue()).contains("\"a\": \"b\""); }
@Test public void shouldLogFilteredRequest() throws Exception { MessageCapture capture = new MessageCapture(logger, false); capture.capture(new RootContext(), new Request(), CapturePoint.FILTERED_REQUEST); verify(logger).info(anyString()); }
@Test public void shouldLogResponse() throws Exception { MessageCapture capture = new MessageCapture(logger, false); capture.capture(new RootContext(), new Response(), CapturePoint.RESPONSE); verify(logger).info(anyString()); }
@Test public void shouldLogFilteredResponse() throws Exception { MessageCapture capture = new MessageCapture(logger, false); capture.capture(new RootContext(), new Response(), CapturePoint.FILTERED_RESPONSE); verify(logger).info(anyString()); }