### Question:
LdapConfigService extends AbstractArchivistService<LdapConfig> { public String testConnection(String environmentCrn, LdapConfig ldapConfig) { if (environmentCrn == null && ldapConfig == null) { throw new BadRequestException("Either an environment or an LDAP 'validationRequest' needs to be specified in the request. "); } try { if (environmentCrn != null) { ldapConfig = get(environmentCrn); } ldapConfigValidator.validateLdapConnection(ldapConfig); return "connected"; } catch (BadRequestException e) { return e.getMessage(); } }  LdapConfig createLdapConfig(LdapConfig ldapConfig); LdapConfig createLdapConfig(LdapConfig ldapConfig, String accountId); LdapConfig get(String environmentCrn); List<LdapConfig> findAllByEnvironmentAndAccountIdEvenIfArchived(String environmentCrn, String accountId); Optional<LdapConfig> find(String environmentCrn, String accountId, String clusterName); void delete(String environmentCrn); void delete(String environmentCrn, String accountId); void delete(String environmentCrn, String accountId, String clusterName); void deleteAllInEnvironment(String environmentCrn, String accountId); String testConnection(String environmentCrn, LdapConfig ldapConfig); @Override JpaRepository repository();  }### Answer:
@Test public void testTestConnectionWithEnvironmentId() { LdapConfig ldapConfig = new LdapConfig(); Mockito.when(crnService.getCurrentAccountId()).thenReturn(ACCOUNT_ID); Mockito.when(ldapConfigRepository.findByAccountIdAndEnvironmentCrnAndClusterNameIsNullAndArchivedIsFalse(ACCOUNT_ID, ENVIRONMENT_ID)) .thenReturn(Optional.of(ldapConfig)); String actualResult = underTest.testConnection(ENVIRONMENT_ID, null); assertEquals("connected", actualResult); }
@Test public void testTestConnectionWithLdapConfig() { LdapConfig ldapConfig = new LdapConfig(); String actualResult = underTest.testConnection(null, ldapConfig); assertEquals("connected", actualResult); }
@Test public void testTestConnectionWithLdapConfigShouldThrowBadRequest() { LdapConfig ldapConfig = new LdapConfig(); Mockito.doThrow(new BadRequestException("connection failed")).when(ldapConfigValidator).validateLdapConnection(ldapConfig); String actualResult = underTest.testConnection(null, ldapConfig); assertEquals("connection failed", actualResult); }