### Question:
LdapClientProvider { public LdapClient getClient(){ if(ldapClient == null){ throw new IllegalStateException("LDAP is not properly configured. Maybe you forgot to put LDAP properties inside cloudstore.properties?"); } return ldapClient; } protected  LdapClientProvider(); protected  LdapClientProvider(OneTimePadRegistry adminPasswordRegistry); LdapClient getClient(); static LdapClientProvider getInstance(); static final String LDAP_TEMPLATE_PATTERN; static final String LDAP_URL; static final String LDAP_QUERY; static final String LDAP_ADMIN_DN; static final String LDAP_QUERY_DN; }### Answer:
@Test(expected = IllegalStateException.class) public void when_query_is_empty_and_templates_list_is_empty_then_provider_can_be_created_but_throws_ISE_when_getClient_called(){ setSystemProperty(LdapClientProvider.LDAP_QUERY, ""); helper.setPatterns(); provider = new LdapClientProvider(); provider.getClient(); }
@Test public void when_templates_are_proper_and_query_is_empty_then_simple_client_is_created(){ setSystemProperty(LdapClientProvider.LDAP_QUERY, ""); String template = "cn=${login}+sn=secret, ou=users, dc=example, dc=com"; helper.setPatterns(template); provider = new LdapClientProvider(); assertThat(provider.getClient()).isNotNull().isInstanceOf(SimpleLdapClient.class); }
@Test public void when_query_is_not_empty_and_other_required_properties_are_set_then_query_client_is_created(){ setSystemProperty(LdapClientProvider.LDAP_QUERY, "(|(cn=${login})(&(email=${login})(objectClass=inetOrgPerson))(emailAlias=${login}))"); setSystemProperty(LdapClientProvider.LDAP_QUERY_DN, "ou=users, dc=example, dc=com"); setSystemProperty(LdapClientProvider.LDAP_ADMIN_DN, "cn=admin"); OneTimePadRegistry registry = new OneTimePadRegistry("NOT_EXISTING_FILE_ONLY_FOR_TESTS"); registry.encryptAndStorePassword("password".toCharArray()); provider = new LdapClientProvider(registry); assertThat(provider.getClient()).isNotNull().isInstanceOf(QueryLdapClient.class); }