TextUtils { public static String truncateByDoubleColons(String source, int level) { if (isEmpty(source)) { return source; } if (level <= 0) { throw new IllegalArgumentException("Level must be larger than 0"); } List<String> original = Arrays.asList(source.split("::")); if (original.size() <= level) { return source; } List<String> result = original.subList(level, original.size()); return join("::", result.toArray(new String[0])); }  static boolean isEmpty(String url); static String getLastSevenNumbers(String uniqueId); @NonNull static String lintUrl(String url); static String truncateByDoubleColons(String source, int level);  }
@Test public void should_truncate_string_by_double_colon_when_source_level_smaller_than_2() { String result = TextUtils.truncateByDoubleColons("L0", 2); assertThat(result, is("L0")); }
@Test public void should_truncate_string_by_double_colon_when_source_level_equals_2() { String result = TextUtils.truncateByDoubleColons("L0::L1", 2); assertThat(result, is("L0::L1")); }
@Test public void should_truncate_string_by_double_colon_when_source_level_larger_than_2() { String result = TextUtils.truncateByDoubleColons("L0::L1::L2::L3", 2); assertThat(result, is("L2::L3")); }
@Test(expected = IllegalArgumentException.class) public void should_truncate_string_by_double_colon_when_target_level_smaller_than_0() { String result = TextUtils.truncateByDoubleColons("L0::L1::L2::L3", -1); assertThat(result, is("L2::L3")); }
@Test(expected = IllegalArgumentException.class) public void should_truncate_string_by_double_colon_when_target_level_equals_0() { String result = TextUtils.truncateByDoubleColons("L0::L1::L2::L3", 0); assertThat(result, is("L2::L3")); }