@Test
void tryBuildTrustedCertFromUrlReturningEmpty() throws Exception {

    //Set up mock socket factory
    SSLSocketFactory sf = mock(SSLSocketFactory.class);
    SSLSocket socket = mock(SSLSocket.class);
    SSLSession sslSession = mock(SSLSession.class);
    when(sf.createSocket(anyString(), anyInt())).thenReturn(socket);
    when(socket.getSession()).thenReturn(sslSession);
    when(sslSession.getPeerCertificates()).thenReturn(new X509Certificate[]{});
    final TrustedCertEntityBuilder builder = new TrustedCertEntityBuilder(new IdGenerator(), sf, certFact);
    final Bundle bundle = new Bundle();
    final TrustedCert trustedCert = new TrustedCert(ImmutableMap.of(VERIFY_HOSTNAME, true), null);
    bundle.putAllTrustedCerts(ImmutableMap.of(URL_NAME, trustedCert));
    assertThrows(EntityBuilderException.class, () -> builder.build(bundle, EntityBuilder.BundleType.ENVIRONMENT, DocumentTools.INSTANCE.getDocumentBuilder().newDocument()));
}