LdapFilter { String filterString() { if (isSerialNumberSearch()) { return String.format(Locale.US, "(serialNumber=%s)", query); } else { return String.format(Locale.US, "(cn=*%s*)", query); } } LdapFilter(String query);   }
@Test public void shouldReturnSerialNumberFilterStringWhenSerialNumberQuery() { String filterString = new LdapFilter(SERIAL_NUMBER_QUERY).filterString(); assertThat(filterString, is("(serialNumber=" + SERIAL_NUMBER_QUERY + ")")); }
@Test public void shouldReturnCnFilterStringWhenNotSerialNumberQuery() { String filterString = new LdapFilter(CN_QUERY).filterString(); assertThat(filterString, is("(cn=*" + CN_QUERY + "*)")); }