StartTlsLdapConnectionFactory implements LdapConnectionFactory { public LDAPConnection buildLdapConnection() throws GeneralSecurityException, LDAPException { final LDAPConnection ldapConnection = new LDAPConnection(ldapProperties.getHost(), ldapProperties.getPort()); ldapConnection.processExtendedOperation(new StartTLSExtendedRequest(SSL_UTIL.createSSLContext())); return ldapConnection; } StartTlsLdapConnectionFactory(final LdapProperties ldapProperties); LDAPConnection buildLdapConnection();  }
@Test public void shouldTryToBuildLdapConnection() { final LdapProperties properties = mock(LdapProperties.class); when(properties.getHost()).thenReturn("foo"); when(properties.getPort()).thenReturn(42); assertThrows(LDAPException.class, () -> { new StartTlsLdapConnectionFactory(properties).buildLdapConnection(); }); }