class LdapFilter {

    String filterString() {
        if (isSerialNumberSearch()) {
            return String.format(Locale.US, "(serialNumber=%s)", query);
        } else {
            return String.format(Locale.US, "(cn=*%s*)", query);
        }
    }

}

class LdapFilterTest {

    private static final String SERIAL_NUMBER_QUERY;
    private static final String CN_QUERY;

    @Test
    public void shouldReturnCnFilterStringWhenNotSerialNumberQuery() {

        String filterString = new LdapFilter(CN_QUERY).filterString();
        assertThat(filterString, is("(cn=*" + CN_QUERY + "*)"));
    }

}