### Question:
OkHttpProtocolNegotiator { public String negotiate( SSLSocket sslSocket, String hostname, @Nullable List<Protocol> protocols) throws IOException { if (protocols != null) { configureTlsExtensions(sslSocket, hostname, protocols); } try { sslSocket.startHandshake(); String negotiatedProtocol = getSelectedProtocol(sslSocket); if (negotiatedProtocol == null) { throw new RuntimeException("TLS ALPN negotiation failed with protocols: " + protocols); } return negotiatedProtocol; } finally { platform.afterHandshake(sslSocket); } } @VisibleForTesting  OkHttpProtocolNegotiator(Platform platform); static OkHttpProtocolNegotiator get(); String negotiate(
      SSLSocket sslSocket, String hostname, @Nullable List<Protocol> protocols); String getSelectedProtocol(SSLSocket socket);  }### Answer:
@Test public void negotiate_android_handshakeFails() throws Exception { when(platform.getTlsExtensionType()).thenReturn(TlsExtensionType.ALPN_AND_NPN); AndroidNegotiator negotiator = new AndroidNegotiator(platform); FakeAndroidSslSocket androidSock = new FakeAndroidSslSocket() { @Override public void startHandshake() throws IOException { throw new IOException("expected"); } }; thrown.expect(IOException.class); thrown.expectMessage("expected"); negotiator.negotiate(androidSock, "hostname", ImmutableList.of(Protocol.HTTP_2)); }
@Test public void negotiate_noSelectedProtocol() throws Exception { Platform platform = mock(Platform.class); OkHttpProtocolNegotiator negotiator = new OkHttpProtocolNegotiator(platform); thrown.expect(RuntimeException.class); thrown.expectMessage("TLS ALPN negotiation failed"); negotiator.negotiate(sock, "hostname", ImmutableList.of(Protocol.HTTP_2)); }