### Question:
HostnameVerifierProvider { public HostnameVerifier verifierFor(String hostname) { if (!hostnameVerificationEnabled) { log.debug("hostname verification disabled"); return new HostnameVerifier() { @Override public boolean verify(final String str, final SSLSession sslSession) { return true; } }; } final String tHostname = hostname.endsWith(".") ? hostname.substring(0, hostname.length() - 1) : hostname; log.debug("configuring DefaultHostnameVerifier to expect hostname={}", tHostname); return new HostnameVerifier() { @Override public boolean verify(final String str, final SSLSession sslSession) { return delegate.verify(tHostname, sslSession); } }; } HostnameVerifierProvider(final boolean hostnameVerificationEnabled,
                                  final HostnameVerifier delegate); HostnameVerifier verifierFor(String hostname);  }### Answer:
@Test public void testHostnameVerificationDisabled() { final HostnameVerifierProvider provider = new HostnameVerifierProvider(false, delegate); final HostnameVerifier verifier = provider.verifierFor("any.host"); assertTrue(verifier.verify("example.com", sslSession)); verifyNoMoreInteractions(delegate, sslSession); }
@Test public void testHostnameVerificationEnabled() { final String hostname = "example.com"; final HostnameVerifierProvider provider = new HostnameVerifierProvider(true, delegate); final HostnameVerifier verifier = provider.verifierFor(hostname); when(delegate.verify(hostname, sslSession)).thenReturn(true); assertTrue(verifier.verify(hostname, sslSession)); when(delegate.verify(hostname, sslSession)).thenReturn(false); assertFalse(verifier.verify("foo.example.com", sslSession)); }