FastCompactingJsonBodyFilter implements BodyFilter { @Override public String filter(@Nullable final String contentType, final String body) { if (!JsonMediaType.JSON.test(contentType)) { return body; } return compactor.compact(body); }  @Override String filter(@Nullable final String contentType, final String body);  }
@Test void shouldIgnoreEmptyBody() { final String filtered = unit.filter("application/json", ""); assertThat(filtered, is("")); }
@Test void shouldCompactInvalidContent() { final String invalidBody = "{\ninvalid}"; final String filtered = unit.filter("application/json", invalidBody); assertThat(filtered, is("{invalid}")); }
@Test void shouldIgnoreInvalidContentType() { final String filtered = unit.filter("text/plain", pretty); assertThat(filtered, is(pretty)); }
@Test void shouldTransformValidJsonRequestWithSimpleContentType() { final String filtered = unit.filter("application/json", pretty); assertThat(filtered, is(compacted)); }
@Test void shouldTransformValidJsonRequestWithCompatibleContentType() { final String filtered = unit.filter("application/custom+json", pretty); assertThat(filtered, is(compacted)); }
@Test void shouldSkipInvalidJsonLookingLikeAValidOne() { final String invalidJson = "{invalid}"; final String filtered = unit.filter("application/custom+json", invalidJson); assertThat(filtered, is(invalidJson)); }