From 06120a4fe2557d7a2716a2c85ad7aaa078a72aad Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 6 Jan 2016 13:37:56 +0100 Subject: [PATCH] Add tests to Tls12Java7SocketFactoryTest --- .../client/Tls12Java7SocketFactoryTest.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java index 5004acaec0e..b7b54c4c185 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java @@ -21,10 +21,12 @@ package org.sonarqube.ws.client; import java.io.IOException; import java.net.InetAddress; +import java.net.Socket; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -32,14 +34,14 @@ import static org.mockito.Mockito.when; public class Tls12Java7SocketFactoryTest { SSLSocketFactory delegate = mock(SSLSocketFactory.class); - SSLSocket socket = mock(SSLSocket.class); Tls12Java7SocketFactory underTest = new Tls12Java7SocketFactory(delegate); @Test public void createSocket_1() throws IOException { InetAddress address = mock(InetAddress.class); + SSLSocket socket = mock(SSLSocket.class); when(delegate.createSocket(address, 80)).thenReturn(socket); - SSLSocket socket = (SSLSocket) underTest.createSocket(address, 80); + socket = (SSLSocket) underTest.createSocket(address, 80); verify(socket).setEnabledProtocols(Tls12Java7SocketFactory.TLS_PROTOCOLS); } @@ -47,15 +49,35 @@ public class Tls12Java7SocketFactoryTest { public void createSocket_2() throws IOException { InetAddress address = mock(InetAddress.class); InetAddress address2 = mock(InetAddress.class); + SSLSocket socket = mock(SSLSocket.class); when(delegate.createSocket(address, 80, address2, 443)).thenReturn(socket); - SSLSocket socket = (SSLSocket) underTest.createSocket(address, 80, address2, 443); + socket = (SSLSocket) underTest.createSocket(address, 80, address2, 443); verify(socket).setEnabledProtocols(Tls12Java7SocketFactory.TLS_PROTOCOLS); } @Test public void createSocket_3() throws IOException { + SSLSocket socket = mock(SSLSocket.class); when(delegate.createSocket("", 80)).thenReturn(socket); - SSLSocket socket = (SSLSocket) underTest.createSocket("", 80); + socket = (SSLSocket) underTest.createSocket("", 80); verify(socket).setEnabledProtocols(Tls12Java7SocketFactory.TLS_PROTOCOLS); } + + @Test + public void support_non_ssl_sockets() throws IOException { + Socket regularSocket = mock(Socket.class); + when(delegate.createSocket("", 80)).thenReturn(regularSocket); + assertThat(underTest.createSocket("", 80)).isNotInstanceOf(SSLSocket.class); + } + + @Test + public void delegate_getters() { + String[] defaultCipherSuites = new String[0]; + String[] supportedCipherSuites = new String[0]; + when(delegate.getDefaultCipherSuites()).thenReturn(defaultCipherSuites); + when(delegate.getSupportedCipherSuites()).thenReturn(supportedCipherSuites); + + assertThat(underTest.getDefaultCipherSuites()).isSameAs(defaultCipherSuites); + assertThat(underTest.getSupportedCipherSuites()).isSameAs(supportedCipherSuites); + } } -- 2.39.5