ResponseFilters { @API(status = MAINTAINED) public static ResponseFilter defaultValue() { return defaultValues(ResponseFilter.class).stream() .reduce(replaceBody(BodyReplacers.defaultValue()), ResponseFilter::merge); } private  ResponseFilters(); @API(status = MAINTAINED) static ResponseFilter defaultValue(); static ResponseFilter replaceBody(final BodyReplacer<HttpResponse> replacer);  }
@Test void shouldReplaceImageBodyByDefault() throws IOException { final ResponseFilter filter = ResponseFilters.defaultValue(); final HttpResponse response = filter.filter(MockHttpResponse.create() .withContentType("image/png") .withBodyAsString("this is an image")); response.withBody(); assertThat(response.getContentType(), is("image/png")); assertThat(response.getContentType(), is("image/png")); assertThat(response.getBody(), is("<binary>".getBytes(UTF_8))); assertThat(response.getBodyAsString(), is("<binary>")); }
@Test void shouldReplaceImageBodyEvenWithoutBody() throws IOException { final ResponseFilter filter = ResponseFilters.defaultValue(); final HttpResponse response = filter.filter(MockHttpResponse.create() .withContentType("image/png") .withBodyAsString("this is an image")); response.withoutBody(); assertThat(response.getContentType(), is("image/png")); assertThat(response.getContentType(), is("image/png")); assertThat(response.getBody(), is("<binary>".getBytes(UTF_8))); assertThat(response.getBodyAsString(), is("<binary>")); }
@Test void shouldNotReplaceTextBodyByDefault() throws IOException { final ResponseFilter filter = ResponseFilters.defaultValue(); final HttpResponse response = filter.filter(MockHttpResponse.create() .withContentType("text/plain") .withBodyAsString("Hello")); response.withBody(); assertThat(response.getBody(), is("Hello".getBytes(UTF_8))); assertThat(response.getBodyAsString(), is("Hello")); }