### Question:
ConfigurationValidator { public void validate(ConnectionConfig config) throws InvalidConfigurationException { if (config.getLDAPURLs() == null || config.getLDAPURLs().isEmpty()) { throw new InvalidConfigurationException("Invalid host URL."); } for (LDAPURL url : config.getLDAPURLs()) { if (url.getPort() < 0 || url.getPort() > 65535) { throw new InvalidConfigurationException("Port outside of valid range."); } } if (config.getBindDN() == null) { throw new InvalidConfigurationException("Bind DN missing"); } if (config.getBindPassword() == null) { throw new InvalidConfigurationException("Bind Password missing"); } if (config.getMaxConnections() < 0) { throw new InvalidConfigurationException("Invalid maximum connections"); } }  void validate(ConnectionConfig config);  }### Answer:
@Test public void shouldDemonstrateMockConfigIsValid() throws InvalidConfigurationException { validator.validate(mockConfig); }
@Test public void shouldEnsureLDAPURLIsPresent() { given(mockConfig.getLDAPURLs()).willReturn(null); try { validator.validate(mockConfig); fail(); } catch (InvalidConfigurationException e) { } }
@Test public void shouldEnsurePortNumberIsInValid() { ldapurl = LDAPURL.valueOf("badger", -1); given(mockConfig.getLDAPURLs()).willReturn(new HashSet<LDAPURL>(Arrays.asList(ldapurl))); try { validator.validate(mockConfig); fail(); } catch (InvalidConfigurationException e) { } }
@Test public void shouldEnsureBindDNIsNotNull() { given(mockConfig.getBindDN()).willReturn(null); try { validator.validate(mockConfig); fail(); } catch (InvalidConfigurationException e) { } }
@Test public void shouldEnsureBindPasswordIsNotNull() { given(mockConfig.getBindPassword()).willReturn(null); try { validator.validate(mockConfig); fail(); } catch (InvalidConfigurationException e) { } }