@@ -0,0 +1,3328 @@
+/*%0A * Copyright (c) 2010-2018 Nathan Rajlich%0A *%0A * Permission is hereby granted, free of charge, to any person%0A * obtaining a copy of this software and associated documentation%0A * files (the %22Software%22), to deal in the Software without%0A * restriction, including without limitation the rights to use,%0A * copy, modify, merge, publish, distribute, sublicense, and/or sell%0A * copies of the Software, and to permit persons to whom the%0A * Software is furnished to do so, subject to the following%0A * conditions:%0A *%0A * The above copyright notice and this permission notice shall be%0A * included in all copies or substantial portions of the Software.%0A *%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND,%0A * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES%0A * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND%0A * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT%0A * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,%0A * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING%0A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR%0A * OTHER DEALINGS IN THE SOFTWARE.%0A *%0A */%0A%0Apackage org.java_websocket.issues;%0A%0Aimport org.java_websocket.WebSocket;%0Aimport org.java_websocket.WebSocketAdapter;%0Aimport org.java_websocket.WebSocketImpl;%0Aimport org.java_websocket.WebSocketServerFactory;%0Aimport org.java_websocket.drafts.Draft;%0Aimport org.java_websocket.handshake.ClientHandshake;%0Aimport org.java_websocket.server.WebSocketServer;%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0A%0Aimport java.io.IOException;%0Aimport java.nio.channels.ByteChannel;%0Aimport java.nio.channels.SelectionKey;%0Aimport java.nio.channels.SocketChannel;%0Aimport java.util.List;%0A%0Apublic class Issue765Test %7B%0A%0A    boolean isClosedCalled = false;%0A    @Test%0A    public void testIssue() %7B%0A        WebSocketServer webSocketServer = new MyWebSocketServer();%0A        webSocketServer.setWebSocketFactory(new LocalWebSocketFactory());%0A        Assert.assertFalse(%22Close should not have been called yet%22,isClosedCalled);%0A        webSocketServer.setWebSocketFactory(new LocalWebSocketFactory());%0A        Assert.assertTrue(%22Close has been called%22, isClosedCalled);%0A    %7D%0A%0A    private static class MyWebSocketServer extends WebSocketServer %7B%0A        @Override%0A        public void onOpen(WebSocket conn, ClientHandshake handshake) %7B%0A%0A        %7D%0A%0A        @Override%0A        public void onClose(WebSocket conn, int code, String reason, boolean remote) %7B%0A%0A        %7D%0A%0A        @Override%0A        public void onMessage(WebSocket conn, String message) %7B%0A%0A        %7D%0A%0A        @Override%0A        public void onError(WebSocket conn, Exception ex) %7B%0A%0A        %7D%0A%0A        @Override%0A        public void onStart() %7B%0A%0A        %7D%0A    %7D%0A%0A    private class LocalWebSocketFactory implements WebSocketServerFactory %7B%0A        @Override%0A        public WebSocketImpl createWebSocket(WebSocketAdapter a, Draft d) %7B%0A            return null;%0A        %7D%0A%0A        @Override%0A        public WebSocketImpl createWebSocket(WebSocketAdapter a, List%3CDraft%3E drafts) %7B%0A            return null;%0A        %7D%0A%0A        @Override%0A        public ByteChannel wrapChannel(SocketChannel channel, SelectionKey key) throws IOException %7B%0A            return null;%0A        %7D%0A%0A        @Override%0A        public void close() %7B%0A            isClosedCalled = true;%0A        %7D%0A    %7D%0A%7D%0A

Test for 765