You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2012/08/27 22:32:19 UTC
svn commit: r1377835 -
/tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
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
Re: svn commit: r1377835 - /tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
Posted by Mark Thomas <ma...@apache.org>.
On 27/08/2012 21:58, Konstantin Kolinko wrote:
> 2012/8/28 <ma...@apache.org>:
>> Author: markt
>> Date: Mon Aug 27 20:32:19 2012
>> New Revision: 1377835
>>
>> URL: http://svn.apache.org/viewvc?rev=1377835&view=rev
>> Log:
>
>> - Remove static imports (auto completes are easier without them)
>>
>
> In Eclipse settings
> Java -> Editor -> Content Assist -> Favorites
>
> My list there is:
> [[[
> org.hamcrest.CoreMatchers
> org.hamcrest.Matchers
> org.junit.Assert
> org.junit.matchers.JUnitMatchers
> ]]]
> (each line added with "New Type.." button)
>
> After that content assist begins suggesting the static methods.
Ah. Useful. Thanks. I'll remember that. I think I still prefer the
non-static approach (simply style reasons - not technical) but that
removes probably the biggest pain of the static approach.
Cheers,
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
Re: svn commit: r1377835 - /tomcat/trunk/test/org/apache/catalina/websocket/TestWebSocket.java
Posted by Konstantin Kolinko <kn...@gmail.com>.
2012/8/28 <ma...@apache.org>:
> Author: markt
> Date: Mon Aug 27 20:32:19 2012
> New Revision: 1377835
>
> URL: http://svn.apache.org/viewvc?rev=1377835&view=rev
> Log:
> - Remove static imports (auto completes are easier without them)
>
In Eclipse settings
Java -> Editor -> Content Assist -> Favorites
My list there is:
[[[
org.hamcrest.CoreMatchers
org.hamcrest.Matchers
org.junit.Assert
org.junit.matchers.JUnitMatchers
]]]
(each line added with "New Type.." button)
After that content assist begins suggesting the static methods.
We are not yet using Hamcrest library in Tomcat, but I think one time
we might start using it. (The library that provides matchers that are
used with org.junit.Assert.assertThat(..),
org.junit.rules.ErrorCollector.checkThat(...) etc.).
I am not insisting on reverting this. Just FYI.
> 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"));
>
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org