tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1377835 - /tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
Date Mon, 27 Aug 2012 20:32:19 GMT
Author: markt
Date: Mon Aug 27 20:32:19 2012
New Revision: 1377835

URL: http://svn.apache.org/viewvc?rev=1377835&view=rev
Log:
Clean-up
- Fix FindBugs NPE warnings
- Java 7 <>
- Remove static imports (auto completes are easier without them)

Modified:
    tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java

Modified: tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java?rev=1377835&r1=1377834&r2=1377835&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java (original)
+++ tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java Mon Aug 27 20:32:19
2012
@@ -38,10 +38,7 @@ import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.servlet.http.HttpServletRequest;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
+import org.junit.Assert;
 import org.junit.Test;
 
 import org.apache.catalina.Context;
@@ -84,11 +81,12 @@ public class TestWebSocket extends Tomca
 
         // Make sure we got an upgrade response
         String responseLine = client.reader.readLine();
-        assertTrue(responseLine.startsWith("HTTP/1.1 101"));
+        Assert.assertNotNull(responseLine);
+        Assert.assertTrue(responseLine.startsWith("HTTP/1.1 101"));
 
         // Swallow the headers
         String responseHeaderLine = client.reader.readLine();
-        while (!responseHeaderLine.equals("")) {
+        while (!"".equals(responseHeaderLine)) {
             responseHeaderLine = client.reader.readLine();
         }
 
@@ -96,7 +94,7 @@ public class TestWebSocket extends Tomca
         client.sendMessage("foo", false);
         client.sendMessage("foo", true);
 
-        assertEquals("foofoo", client.readMessage());
+        Assert.assertEquals("foofoo", client.readMessage());
 
         // Finished with the socket
         client.close();
@@ -123,17 +121,18 @@ public class TestWebSocket extends Tomca
 
         // Make sure we got an upgrade response
         String responseLine = client.reader.readLine();
-        assertTrue(responseLine.startsWith("HTTP/1.1 426"));
+        Assert.assertNotNull(responseLine);
+        Assert.assertTrue(responseLine.startsWith("HTTP/1.1 426"));
 
-        List<String> headerlines = new ArrayList<String>();
+        List<String> headerlines = new ArrayList<>();
 
         String responseHeaderLine = client.reader.readLine();
-        while (!responseHeaderLine.equals("")) {
+        while (!"".equals(responseHeaderLine)) {
             headerlines.add(responseHeaderLine);
             responseHeaderLine = client.reader.readLine();
         }
 
-        assertTrue(headerlines.contains("Sec-WebSocket-Version: 13"));
+        Assert.assertTrue(headerlines.contains("Sec-WebSocket-Version: 13"));
         // Finished with the socket
         client.close();
     }
@@ -159,7 +158,8 @@ public class TestWebSocket extends Tomca
 
         // Make sure we got an upgrade response
         String responseLine = client.reader.readLine();
-        assertTrue(responseLine.startsWith("HTTP/1.1 400"));
+        Assert.assertNotNull(responseLine);
+        Assert.assertTrue(responseLine.startsWith("HTTP/1.1 400"));
 
         // Finished with the socket
         client.close();
@@ -186,7 +186,8 @@ public class TestWebSocket extends Tomca
 
         // Make sure we got an upgrade response
         String responseLine = client.reader.readLine();
-        assertTrue(responseLine.startsWith("HTTP/1.1 400"));
+        Assert.assertNotNull(responseLine);
+        Assert.assertTrue(responseLine.startsWith("HTTP/1.1 400"));
 
         // Finished with the socket
         client.close();
@@ -213,28 +214,29 @@ public class TestWebSocket extends Tomca
 
         // Make sure we got an upgrade response
         String responseLine = client.reader.readLine();
-        assertTrue(responseLine.startsWith("HTTP/1.1 101"));
+        Assert.assertNotNull(responseLine);
+        Assert.assertTrue(responseLine.startsWith("HTTP/1.1 101"));
 
         String accept = null;
         String responseHeaderLine = client.reader.readLine();
-        while (!responseHeaderLine.equals("")) {
+        while (!"".equals(responseHeaderLine)) {
             if(responseHeaderLine.startsWith("Sec-WebSocket-Accept: ")) {
                 accept = responseHeaderLine.substring(responseHeaderLine.indexOf(":")+2);
                 break;
             }
             responseHeaderLine = client.reader.readLine();
         }
-        assertTrue(accept != null);
+        Assert.assertTrue(accept != null);
         MessageDigest sha1Helper = MessageDigest.getInstance("SHA1");
         sha1Helper.reset();
         sha1Helper.update("TODO".getBytes(B2CConverter.ISO_8859_1));
         String source = Base64.encode(sha1Helper.digest(WS_ACCEPT));
-        assertEquals(source,accept);
+        Assert.assertEquals(source,accept);
 
         sha1Helper.reset();
         sha1Helper.update("TOD".getBytes(B2CConverter.ISO_8859_1));
         source = Base64.encode(sha1Helper.digest(WS_ACCEPT));
-        assertFalse(source.equals(accept));
+        Assert.assertFalse(source.equals(accept));
         // Finished with the socket
         client.close();
     }
@@ -275,17 +277,18 @@ public class TestWebSocket extends Tomca
 
         // Make sure we got an upgrade response
         String responseLine = client.reader.readLine();
-        assertTrue(responseLine.startsWith("HTTP/1.1 101"));
+        Assert.assertNotNull(responseLine);
+        Assert.assertTrue(responseLine.startsWith("HTTP/1.1 101"));
 
         // Swallow the headers
         String responseHeaderLine = client.reader.readLine();
-        while (!responseHeaderLine.equals("")) {
+        while (!"".equals(responseHeaderLine)) {
             responseHeaderLine = client.reader.readLine();
         }
 
         // Now we can do WebSocket
         String msg = client.readMessage();
-        assertEquals(Bug53339WsInbound.TEST_MESSAGE, msg);
+        Assert.assertEquals(Bug53339WsInbound.TEST_MESSAGE, msg);
 
         // Finished with the socket
         client.close();
@@ -377,7 +380,7 @@ public class TestWebSocket extends Tomca
             c2b.flushBuffer();
 
             int len = bc.getLength();
-            assertTrue(len < 126);
+            Assert.assertTrue(len < 126);
 
             byte first;
             if (isContinuation) {
@@ -416,7 +419,7 @@ public class TestWebSocket extends Tomca
 
             // Get payload length
             int len = is.read() & 0x7F;
-            assertTrue(len < 126);
+            Assert.assertTrue(len < 126);
 
             // Read payload
             int read = 0;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message