BodyFilters { @API(status = EXPERIMENTAL) public static BodyFilter truncate(final int maxSize) { return (contentType, body) -> body.length() <= maxSize ? body : body.substring(0, maxSize) + "..."; } private  BodyFilters(); @API(status = MAINTAINED) static BodyFilter defaultValue(); @API(status = EXPERIMENTAL) static BodyFilter oauthRequest(); @API(status = EXPERIMENTAL) static BodyFilter replaceFormUrlEncodedProperty(final Set<String> properties, final String replacement); @API(status = EXPERIMENTAL) static BodyFilter truncate(final int maxSize); @API(status = EXPERIMENTAL) static BodyFilter compactXml();  }
@Test void shouldTruncateBodyIfTooLong() { final BodyFilter unit = truncate(5); final String actual = unit.filter("application/json", "{\"foo\":\"secret\"}"); assertThat(actual, is("{\"foo...")); }
@Test void shouldNotTruncateBodyIfTooShort() { final BodyFilter unit = truncate(50); final String actual = unit.filter("application/json", "{\"foo\":\"secret\"}"); assertThat(actual, is("{\"foo\":\"secret\"}")); }