]> source.dussan.org Git - sonarqube.git/commitdiff
Add tests to Tls12Java7SocketFactoryTest
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 6 Jan 2016 12:37:56 +0000 (13:37 +0100)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Tue, 12 Jan 2016 11:06:21 +0000 (12:06 +0100)
sonar-ws/src/test/java/org/sonarqube/ws/client/Tls12Java7SocketFactoryTest.java

index 5004acaec0e0598134c91057517abae4b2ebcba2..b7b54c4c185673ab94088130858529c023bef47a 100644 (file)
@@ -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);
+  }
 }