BodyReplacers { public static <T extends HttpMessage> BodyReplacer<T> replaceBody(final Predicate<T> predicate, final String replacement) { return message -> predicate.test(message) ? replacement : null; } private  BodyReplacers(); @API(status = MAINTAINED) static BodyReplacer<T> defaultValue(); @API(status = MAINTAINED) static BodyReplacer<T> binary(); @API(status = MAINTAINED) static BodyReplacer<T> multipart(); @API(status = MAINTAINED) static BodyReplacer<T> stream(); static BodyReplacer<T> replaceBody(final Predicate<T> predicate,
            final String replacement);  }
@Test void shouldReplaceWith() { final BodyReplacer<HttpMessage> unit = replaceBody(m -> m.getContentType().startsWith("image/"), "<content>"); final HttpMessage message = mock(HttpMessage.class); when(message.getContentType()).thenReturn("image/png"); final String body = unit.replace(message); assertThat(body, is("<content>")); }
@Test void shouldNotReplaceWith() throws IOException { final BodyReplacer<HttpMessage> unit = replaceBody(m -> m.getContentType().startsWith("image/"), "<content>"); final HttpMessage message = mock(HttpMessage.class); when(message.getContentType()).thenReturn("text/plain"); when(message.getBodyAsString()).thenReturn("Hello, world!"); final String body = unit.replace(message); assertThat(body, is(nullValue())); }