Skip to content

Commit a3ecef4

Browse files
authored
Merge pull request TooTallNate#771 from marci4/Test765
Test for 765
2 parents 872ebf2 + 670607c commit a3ecef4

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2010-2018 Nathan Rajlich
3+
*
4+
* Permission is hereby granted, free of charge, to any person
5+
* obtaining a copy of this software and associated documentation
6+
* files (the "Software"), to deal in the Software without
7+
* restriction, including without limitation the rights to use,
8+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following
11+
* conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be
14+
* included in all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
* OTHER DEALINGS IN THE SOFTWARE.
24+
*
25+
*/
26+
27+
package org.java_websocket.issues;
28+
29+
import org.java_websocket.WebSocket;
30+
import org.java_websocket.WebSocketAdapter;
31+
import org.java_websocket.WebSocketImpl;
32+
import org.java_websocket.WebSocketServerFactory;
33+
import org.java_websocket.drafts.Draft;
34+
import org.java_websocket.handshake.ClientHandshake;
35+
import org.java_websocket.server.WebSocketServer;
36+
import org.junit.Assert;
37+
import org.junit.Test;
38+
39+
import java.io.IOException;
40+
import java.nio.channels.ByteChannel;
41+
import java.nio.channels.SelectionKey;
42+
import java.nio.channels.SocketChannel;
43+
import java.util.List;
44+
45+
public class Issue765Test {
46+
47+
boolean isClosedCalled = false;
48+
@Test
49+
public void testIssue() {
50+
WebSocketServer webSocketServer = new MyWebSocketServer();
51+
webSocketServer.setWebSocketFactory(new LocalWebSocketFactory());
52+
Assert.assertFalse("Close should not have been called yet",isClosedCalled);
53+
webSocketServer.setWebSocketFactory(new LocalWebSocketFactory());
54+
Assert.assertTrue("Close has been called", isClosedCalled);
55+
}
56+
57+
private static class MyWebSocketServer extends WebSocketServer {
58+
@Override
59+
public void onOpen(WebSocket conn, ClientHandshake handshake) {
60+
61+
}
62+
63+
@Override
64+
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
65+
66+
}
67+
68+
@Override
69+
public void onMessage(WebSocket conn, String message) {
70+
71+
}
72+
73+
@Override
74+
public void onError(WebSocket conn, Exception ex) {
75+
76+
}
77+
78+
@Override
79+
public void onStart() {
80+
81+
}
82+
}
83+
84+
private class LocalWebSocketFactory implements WebSocketServerFactory {
85+
@Override
86+
public WebSocketImpl createWebSocket(WebSocketAdapter a, Draft d) {
87+
return null;
88+
}
89+
90+
@Override
91+
public WebSocketImpl createWebSocket(WebSocketAdapter a, List<Draft> drafts) {
92+
return null;
93+
}
94+
95+
@Override
96+
public ByteChannel wrapChannel(SocketChannel channel, SelectionKey key) throws IOException {
97+
return null;
98+
}
99+
100+
@Override
101+
public void close() {
102+
isClosedCalled = true;
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)