Skip to content

Commit 8a74a87

Browse files
authored
Merge pull request TooTallNate#880 from marci4/Fix661Test
Update Issue661Test.java
2 parents 36a8102 + b423f70 commit 8a74a87

File tree

1 file changed

+30
-40
lines changed

1 file changed

+30
-40
lines changed

‎src/test/java/org/java_websocket/issues/Issue661Test.java‎

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@
3939
importjava.net.InetSocketAddress;
4040
importjava.util.concurrent.CountDownLatch;
4141

42-
importstaticorg.junit.Assert.assertTrue;
43-
importstaticorg.junit.Assert.fail;
42+
importstaticorg.junit.Assert.*;
4443

4544
publicclassIssue661Test{
4645

@@ -50,42 +49,30 @@ public class Issue661Test{
5049
privateCountDownLatchcountServerDownLatch = newCountDownLatch( 1 );
5150

5251
privatebooleanwasError = false;
52+
privatebooleanwasBindException = false;
5353

54-
classTestPrintStreamextendsPrintStream{
55-
publicTestPrintStream( OutputStreamout ){
56-
super( out );
57-
}
58-
59-
@Override
60-
publicvoidprintln( Objecto ){
61-
wasError = true;
62-
super.println( o );
63-
}
64-
}
65-
66-
//@Test(timeout = 2000)
54+
@Test(timeout = 2000)
6755
publicvoidtestIssue() throwsException{
68-
System.setErr( newTestPrintStream( System.err ) );
6956
intport = SocketUtil.getAvailablePort();
70-
WebSocketServerserver0 = newWebSocketServer(newInetSocketAddress(port ) ){
57+
WebSocketServerserver0 = newWebSocketServer(newInetSocketAddress(port)){
7158
@Override
72-
publicvoidonOpen(WebSocketconn, ClientHandshakehandshake){
73-
fail("There should be no onOpen");
59+
publicvoidonOpen(WebSocketconn, ClientHandshakehandshake){
60+
fail("There should be no onOpen");
7461
}
7562

7663
@Override
77-
publicvoidonClose(WebSocketconn, intcode, Stringreason, booleanremote){
78-
fail("There should be no onClose");
64+
publicvoidonClose(WebSocketconn, intcode, Stringreason, booleanremote){
65+
fail("There should be no onClose");
7966
}
8067

8168
@Override
82-
publicvoidonMessage(WebSocketconn, Stringmessage){
83-
fail("There should be no onMessage");
69+
publicvoidonMessage(WebSocketconn, Stringmessage){
70+
fail("There should be no onMessage");
8471
}
8572

8673
@Override
87-
publicvoidonError(WebSocketconn, Exceptionex){
88-
fail("There should be no onError!");
74+
publicvoidonError(WebSocketconn, Exceptionex){
75+
fail("There should be no onError!");
8976
}
9077

9178
@Override
@@ -96,42 +83,45 @@ public void onStart(){
9683
server0.start();
9784
try{
9885
countServerDownLatch.await();
99-
} catch (InterruptedExceptione){
86+
} catch (InterruptedExceptione){
10087
//
10188
}
102-
WebSocketServerserver1 = newWebSocketServer(newInetSocketAddress(port ) ){
89+
WebSocketServerserver1 = newWebSocketServer(newInetSocketAddress(port)){
10390
@Override
104-
publicvoidonOpen(WebSocketconn, ClientHandshakehandshake){
105-
fail("There should be no onOpen");
91+
publicvoidonOpen(WebSocketconn, ClientHandshakehandshake){
92+
fail("There should be no onOpen");
10693
}
10794

10895
@Override
109-
publicvoidonClose(WebSocketconn, intcode, Stringreason, booleanremote){
110-
fail("There should be no onClose");
96+
publicvoidonClose(WebSocketconn, intcode, Stringreason, booleanremote){
97+
fail("There should be no onClose");
11198
}
11299

113100
@Override
114-
publicvoidonMessage(WebSocketconn, Stringmessage){
115-
fail("There should be no onMessage");
101+
publicvoidonMessage(WebSocketconn, Stringmessage){
102+
fail("There should be no onMessage");
116103
}
117104

118105
@Override
119-
publicvoidonError( WebSocketconn, Exceptionex ){
120-
if( !( exinstanceofBindException ) ){
121-
fail( "There should be no onError" );
106+
publicvoidonError(WebSocketconn, Exceptionex){
107+
if (exinstanceofBindException){
108+
wasBindException = true;
109+
} else{
110+
wasError = true;
122111
}
123112
}
124113

125114
@Override
126115
publicvoidonStart(){
127-
fail("There should be no onStart!");
116+
fail("There should be no onStart!");
128117
}
129118
};
130119
server1.start();
131-
Thread.sleep(1000);
120+
Thread.sleep(1000);
132121
server1.stop();
133122
server0.stop();
134-
Thread.sleep( 100 );
135-
assertTrue( "There was an error using System.err", !wasError );
123+
Thread.sleep(100);
124+
assertFalse("There was an unexpected exception!", wasError);
125+
assertTrue("There was no bind exception!", wasBindException);
136126
}
137127
}

0 commit comments

Comments
(0)