### Question:
LogSanitizer { public String sanitize(Object maybeContaminated, int maxLength) { String objAsString = null; if (maybeContaminated!=null) { objAsString = maybeContaminated.toString(); } return sanitize(objAsString, maxLength); }  String sanitize(Object maybeContaminated, int maxLength); String sanitize(String maybeContaminated, int maxLength);  }### Answer:
@Test public void empty_keeps_empty() { assertEquals("", sanitizerToTest.sanitize("", -1)); }
@Test public void null_keeps_null() { assertEquals(null, sanitizerToTest.sanitize(null, -1)); assertEquals(null, sanitizerToTest.sanitize(null, 11)); assertEquals(null, sanitizerToTest.sanitize(null, 0)); }
@Test public void object_with_to_string_containing_aaa_max_n1_will_NOT_be_sanitized() { assertEquals("aaa", sanitizerToTest.sanitize(new TestLogObject("aaa"), -1)); }
@Test public void object_with_to_string_containing_aaa_max_2_will_be_sanitized_to_aa() { assertEquals("aa", sanitizerToTest.sanitize(new TestLogObject("aaa"), 2)); }
@Test public void text_is_not_shortend_when_max_smaller_than_1() { assertEquals("I am full here", sanitizerToTest.sanitize("I am full here", -1)); assertEquals("I am full here", sanitizerToTest.sanitize("I am full here", 0)); assertEquals("I am full here", sanitizerToTest.sanitize("I am full here", -3331)); }
@Test public void text_longer_than_max_is_shortend_to_maximum() { assertEquals("I am reduced", sanitizerToTest.sanitize("I am reduced in my length", "I am reduced".length())); assertEquals("I", sanitizerToTest.sanitize("I am reduced in my length", 1)); }
@Test public void text_is_not_shortend_when_text_is_lower_than_50_and_50_is_set_as_maxlength() { assertEquals("I am not reduced", sanitizerToTest.sanitize("I am not reduced", 50)); }