### Question:
ComposerProviderHandler implements Handler { @Nonnull @Override public Response handle(@Nonnull final Context context) throws Exception { Response response = context.proceed(); if (!Boolean.parseBoolean(context.getRequest().getAttributes().get(DO_NOT_REWRITE, String.class))) { if (response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null) { response = HttpResponses .ok(composerJsonProcessor.rewriteProviderJson(context.getRepository(), response.getPayload())); } } return response; } @Inject  ComposerProviderHandler(final ComposerJsonProcessor composerJsonProcessor); @Nonnull @Override Response handle(@Nonnull final Context context); static final String DO_NOT_REWRITE; }### Answer:
@Test public void handleWithRewriteDisabled() throws Exception { when(requestAttributes.get(DO_NOT_REWRITE, String.class)).thenReturn("true"); Response output = underTest.handle(context); assertThat(output, is(response)); verifyNoMoreInteractions(composerJsonProcessor); }
@Test public void handleWithRewriteEnabled() throws Exception { Response output = underTest.handle(context); assertThat(output, is(not(response))); assertThat(output.getPayload(), is(rewrittenPayload)); verify(composerJsonProcessor).rewriteProviderJson(repository, payload); }
@Test public void handleWithRewriteEnabledNotOK() throws Exception { when(status.getCode()).thenReturn(INTERNAL_SERVER_ERROR); Response output = underTest.handle(context); assertThat(output, is(response)); verifyNoMoreInteractions(composerJsonProcessor); }
@Test public void handleWithRewriteEnabledNoPayload() throws Exception { when(response.getPayload()).thenReturn(null); Response output = underTest.handle(context); assertThat(output, is(response)); verifyNoMoreInteractions(composerJsonProcessor); }