Source:
public void test_SSLEngine_getHandshakeSession_duringHandshake() throws Exception { final TestSSLContext referenceContext = TestSSLContext.create(); final SSLEngine referenceEngine = referenceContext.clientContext.createSSLEngine(); TestSSLContext c = TestSSLContext.newBuilder() .clientTrustManager(new X509ExtendedTrustManager() { @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException { try { SSLSession session = sslEngine.getHandshakeSession(); assertNotNull(session); assertEquals(referenceContext.host.getHostName(), session.getPeerHost()); String sessionSuite = session.getCipherSuite(); String message = "Handshake session has invalid cipher suite: " + (sessionSuite == null ? "(null)" : sessionSuite); assertTrue(message, Arrays.asList(referenceEngine.getEnabledCipherSuites()) .contains(sessionSuite)); } catch (Exception e) { throw new CertificateException("Something broke", e); } } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }).build(); TestSSLEnginePair pair = TestSSLEnginePair.create(c); pair.close(); }

Target:
public void test_SSLEngine_getHandshakeSession_duringHandshake() throws Exception { final TestSSLContext referenceContext = TestSSLContext.create(); final SSLEngine referenceEngine = referenceContext.clientContext.createSSLEngine(); TestSSLContext c = TestSSLContext.newBuilder() .clientTrustManager(new X509ExtendedTrustManager() { @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException { try { SSLSession session = sslEngine.getHandshakeSession(); assertNotNull(session); assertEquals(referenceContext.host.getHostName(), session.getPeerHost()); String sessionSuite = session.getCipherSuite(); List<String> enabledSuites = Arrays.asList(referenceEngine.getEnabledCipherSuites()); String message = "Handshake session has invalid cipher suite: " + (sessionSuite == null ? "(null)" : sessionSuite); assertTrue("Expected enabled suites to contain " + sessionSuite + ", got: " + enabledSuites, Arrays.asList(enabledSuites).contains(sessionSuite)); } catch (Exception e) { throw new CertificateException("Something broke", e); } } @Override public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { throw new CertificateException("Shouldn't be called"); } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } }).build(); TestSSLEnginePair pair = TestSSLEnginePair.create(c); pair.close(); }