public static String truncate(String s, int length) {
    if (s == null) {
      return null;
    }

    if (s.length() > length) {
      return s.substring(0, length);
    } else {
      return s;
    }
  }
@Test
  public void test_truncate() {
    assertThat(StringUtils.truncate(null, 10), CoreMatchers.nullValue());
    assertThat(StringUtils.truncate("", 4), is(""));
    assertThat(StringUtils.truncate("1234", 4), is("1234"));
    assertThat(StringUtils.truncate("1234", 3), is("123"));
  }