Abbreviation { public String abbreviate(String s) { if (s == null) { return null; } return s.replaceAll(pattern, replacement); }  String abbreviate(String s);  }
@Test public void testAbbreviate() { Abbreviation abbreviation = new Abbreviation("de.qaware", "Q"); assertThat(abbreviation.abbreviate("com.something"), is("com.something")); assertThat(abbreviation.abbreviate("de.something"), is("de.something")); assertThat(abbreviation.abbreviate("de.qaware"), is("Q")); assertThat(abbreviation.abbreviate("de.qaware.qav"), is("Q.qav")); assertThat(abbreviation.abbreviate(""), is("")); assertThat(abbreviation.abbreviate(null), nullValue()); }
@Test public void testAbbreviateWithRegExp() { Abbreviation abbreviation = new Abbreviation(".*\\.qaware", "Q"); assertThat(abbreviation.abbreviate("de.qaware"), is("Q")); assertThat(abbreviation.abbreviate("com.qaware"), is("Q")); assertThat(abbreviation.abbreviate("de.qaware.qav"), is("Q.qav")); assertThat(abbreviation.abbreviate("com.qaware.qav"), is("Q.qav")); }