diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-01-06 13:37:56 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2016-01-12 12:06:21 +0100 |
commit | 06120a4fe2557d7a2716a2c85ad7aaa078a72aad (patch) | |
tree | c848715673bb6db931f0f17528a13aad134ef26f | |
parent | be9f3cf76b14964c742cd15a1966733651fdeb21 (diff) | |
download | sonarqube-06120a4fe2557d7a2716a2c85ad7aaa078a72aad.tar.gz sonarqube-06120a4fe2557d7a2716a2c85ad7aaa078a72aad.zip |
Add tests to Tls12Java7SocketFactoryTest
-rw-r--r-- | sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java | 30 |
1 files 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); + } } |