### Question:
StringUtils { public static String truncateIfLengthMoreThan(final int maximumLengthAllowed, String string) { if (string.length() > maximumLengthAllowed) { return string.substring(0, maximumLengthAllowed - THREE_DOTS.length()).concat(THREE_DOTS); } else { return string; } }  static String join(Collection<?> collection, String delimiter); static String truncateIfLengthMoreThan(final int maximumLengthAllowed, String string); static String[] toStringArray(Object[] objects);  }### Answer:
@Test public void testLongStringLengthIsTruncatedAtMaximum() throws Exception { String string = StringUtils.truncateIfLengthMoreThan(SHORT_STRING_LENGTH, RANDOM_STRING); assertEquals(string.length(), SHORT_STRING_LENGTH); }
@Test public void testStringLengthUnchangedIfStringLengthIsLessThanMaximum() throws Exception { String truncatedString = StringUtils.truncateIfLengthMoreThan(LONG_STRING_LENGTH, RANDOM_STRING); assertEquals(truncatedString.length(), RANDOM_STRING.length()); }
@Test public void testLongStringHasThreeDotsWhenLengthIsMoreThanMaximum() throws Exception { String truncatedString = StringUtils.truncateIfLengthMoreThan(SHORT_STRING_LENGTH, RANDOM_STRING); assertEquals(String.valueOf(truncatedString.charAt(SHORT_STRING_LENGTH - 1)), THREE_DOTS); }
@Test public void testStringIsUntouchedWhenLengthIsLessThanMaximum() throws Exception { String truncatedString = StringUtils.truncateIfLengthMoreThan(LONG_STRING_LENGTH, RANDOM_STRING); assertEquals(RANDOM_STRING, truncatedString); }