44 |
43 |
45 public class SendTest { |
44 public class SendTest { |
46 |
45 |
47 private static final Class<NullPointerException> NPE = NullPointerException.class; |
46 private static final Class<NullPointerException> NPE = NullPointerException.class; |
48 |
47 |
49 private DummyWebSocketServer server; |
|
50 private WebSocket webSocket; |
|
51 |
|
52 @AfterTest |
|
53 public void cleanup() { |
|
54 server.close(); |
|
55 webSocket.abort(); |
|
56 } |
|
57 |
|
58 @Test |
48 @Test |
59 public void sendMethodsThrowNPE() throws IOException { |
49 public void sendMethodsThrowNPE() throws IOException { |
60 server = new DummyWebSocketServer(); |
50 try (var server = new DummyWebSocketServer()) { |
61 server.open(); |
51 server.open(); |
62 webSocket = newBuilder().proxy(NO_PROXY).build().newWebSocketBuilder() |
52 var webSocket = newBuilder().proxy(NO_PROXY).build().newWebSocketBuilder() |
63 .buildAsync(server.getURI(), new WebSocket.Listener() { }) |
53 .buildAsync(server.getURI(), new WebSocket.Listener() { }) |
64 .join(); |
54 .join(); |
|
55 try { |
|
56 assertThrows(NPE, () -> webSocket.sendText(null, false)); |
|
57 assertThrows(NPE, () -> webSocket.sendText(null, true)); |
|
58 assertThrows(NPE, () -> webSocket.sendBinary(null, false)); |
|
59 assertThrows(NPE, () -> webSocket.sendBinary(null, true)); |
|
60 assertThrows(NPE, () -> webSocket.sendPing(null)); |
|
61 assertThrows(NPE, () -> webSocket.sendPong(null)); |
|
62 assertThrows(NPE, () -> webSocket.sendClose(NORMAL_CLOSURE, null)); |
65 |
63 |
66 assertThrows(NPE, () -> webSocket.sendText(null, false)); |
64 webSocket.abort(); |
67 assertThrows(NPE, () -> webSocket.sendText(null, true)); |
|
68 assertThrows(NPE, () -> webSocket.sendBinary(null, false)); |
|
69 assertThrows(NPE, () -> webSocket.sendBinary(null, true)); |
|
70 assertThrows(NPE, () -> webSocket.sendPing(null)); |
|
71 assertThrows(NPE, () -> webSocket.sendPong(null)); |
|
72 assertThrows(NPE, () -> webSocket.sendClose(NORMAL_CLOSURE, null)); |
|
73 |
65 |
74 webSocket.abort(); |
66 assertThrows(NPE, () -> webSocket.sendText(null, false)); |
75 |
67 assertThrows(NPE, () -> webSocket.sendText(null, true)); |
76 assertThrows(NPE, () -> webSocket.sendText(null, false)); |
68 assertThrows(NPE, () -> webSocket.sendBinary(null, false)); |
77 assertThrows(NPE, () -> webSocket.sendText(null, true)); |
69 assertThrows(NPE, () -> webSocket.sendBinary(null, true)); |
78 assertThrows(NPE, () -> webSocket.sendBinary(null, false)); |
70 assertThrows(NPE, () -> webSocket.sendPing(null)); |
79 assertThrows(NPE, () -> webSocket.sendBinary(null, true)); |
71 assertThrows(NPE, () -> webSocket.sendPong(null)); |
80 assertThrows(NPE, () -> webSocket.sendPing(null)); |
72 assertThrows(NPE, () -> webSocket.sendClose(NORMAL_CLOSURE, null)); |
81 assertThrows(NPE, () -> webSocket.sendPong(null)); |
73 } finally { |
82 assertThrows(NPE, () -> webSocket.sendClose(NORMAL_CLOSURE, null)); |
74 webSocket.abort(); |
|
75 } |
|
76 } |
83 } |
77 } |
84 |
78 |
85 // TODO: request in onClose/onError |
79 // TODO: request in onClose/onError |
86 // TODO: throw exception in onClose/onError |
80 // TODO: throw exception in onClose/onError |
87 // TODO: exception is thrown from request() |
81 // TODO: exception is thrown from request() |
88 |
82 |
89 @Test |
83 @Test |
90 public void sendCloseCompleted() throws IOException { |
84 public void sendCloseCompleted() throws IOException { |
91 server = new DummyWebSocketServer(); |
85 try (var server = new DummyWebSocketServer()) { |
92 server.open(); |
86 server.open(); |
93 webSocket = newBuilder().proxy(NO_PROXY).build().newWebSocketBuilder() |
87 var webSocket = newBuilder().proxy(NO_PROXY).build().newWebSocketBuilder() |
94 .buildAsync(server.getURI(), new WebSocket.Listener() { }) |
88 .buildAsync(server.getURI(), new WebSocket.Listener() { }) |
95 .join(); |
89 .join(); |
96 webSocket.sendClose(NORMAL_CLOSURE, "").join(); |
90 try { |
97 assertTrue(webSocket.isOutputClosed()); |
91 webSocket.sendClose(NORMAL_CLOSURE, "").join(); |
98 assertEquals(webSocket.getSubprotocol(), ""); |
92 assertTrue(webSocket.isOutputClosed()); |
99 webSocket.request(1); // No exceptions must be thrown |
93 assertEquals(webSocket.getSubprotocol(), ""); |
|
94 webSocket.request(1); // No exceptions must be thrown |
|
95 } finally { |
|
96 webSocket.abort(); |
|
97 } |
|
98 } |
100 } |
99 } |
101 } |
100 } |
|
101 |