jdk/test/java/net/httpclient/BasicWebSocketAPITest.java
changeset 38864 bf2b41533aed
parent 37874 02589df0999a
child 39133 b5641ce64cf7
equal deleted inserted replaced
38863:e031aa31b25f 38864:bf2b41533aed
    28 import java.net.URI;
    28 import java.net.URI;
    29 import java.net.http.HttpClient;
    29 import java.net.http.HttpClient;
    30 import java.net.http.WebSocket;
    30 import java.net.http.WebSocket;
    31 import java.net.http.WebSocket.CloseCode;
    31 import java.net.http.WebSocket.CloseCode;
    32 import java.nio.ByteBuffer;
    32 import java.nio.ByteBuffer;
       
    33 import java.nio.CharBuffer;
    33 import java.nio.channels.SocketChannel;
    34 import java.nio.channels.SocketChannel;
    34 import java.util.concurrent.CompletableFuture;
    35 import java.util.concurrent.CompletableFuture;
    35 import java.util.concurrent.TimeUnit;
    36 import java.util.concurrent.TimeUnit;
    36 import java.util.function.Consumer;
    37 import java.util.function.Consumer;
    37 import java.util.stream.Stream;
    38 import java.util.stream.Stream;
    90                                 "message",
    91                                 "message",
    91                                 () -> ws.sendBinary((ByteBuffer) null, true))
    92                                 () -> ws.sendBinary((ByteBuffer) null, true))
    92         );
    93         );
    93         checkAndClose(
    94         checkAndClose(
    94                 (ws) ->
    95                 (ws) ->
       
    96                         TestKit.assertThrows(IllegalArgumentException.class,
       
    97                                 ".*message.*",
       
    98                                 () -> ws.sendPing(ByteBuffer.allocate(126)))
       
    99         );
       
   100         checkAndClose(
       
   101                 (ws) ->
    95                         TestKit.assertThrows(NullPointerException.class,
   102                         TestKit.assertThrows(NullPointerException.class,
    96                                 "message",
   103                                 "message",
    97                                 () -> ws.sendPing(null))
   104                                 () -> ws.sendPing(null))
    98         );
   105         );
    99         checkAndClose(
   106         checkAndClose(
   100                 (ws) ->
   107                 (ws) ->
       
   108                         TestKit.assertThrows(IllegalArgumentException.class,
       
   109                                 ".*message.*",
       
   110                                 () -> ws.sendPong(ByteBuffer.allocate(126)))
       
   111         );
       
   112         checkAndClose(
       
   113                 (ws) ->
   101                         TestKit.assertThrows(NullPointerException.class,
   114                         TestKit.assertThrows(NullPointerException.class,
   102                                 "message",
   115                                 "message",
   103                                 () -> ws.sendPong(null))
   116                                 () -> ws.sendPong(null))
   104         );
   117         );
   105         checkAndClose(
   118         checkAndClose(
   106                 (ws) ->
   119                 (ws) ->
   107                         TestKit.assertThrows(NullPointerException.class,
   120                         TestKit.assertThrows(NullPointerException.class,
   108                                 "message",
   121                                 "message",
   109                                 () -> ws.sendText((CharSequence) null, true))
   122                                 () -> ws.sendText(null, true))
   110         );
   123         );
   111         checkAndClose(
   124         checkAndClose(
   112                 (ws) ->
   125                 (ws) ->
   113                         TestKit.assertThrows(NullPointerException.class,
   126                         TestKit.assertThrows(NullPointerException.class,
   114                                 "message",
   127                                 "message",
   117         checkAndClose(
   130         checkAndClose(
   118                 (ws) ->
   131                 (ws) ->
   119                         TestKit.assertThrows(NullPointerException.class,
   132                         TestKit.assertThrows(NullPointerException.class,
   120                                 "message",
   133                                 "message",
   121                                 () -> ws.sendText((Stream<? extends CharSequence>) null))
   134                                 () -> ws.sendText((Stream<? extends CharSequence>) null))
       
   135         );
       
   136         checkAndClose(
       
   137                 (ws) ->
       
   138                         TestKit.assertThrows(IllegalArgumentException.class,
       
   139                                 "(?i).*reason.*",
       
   140                                 () -> ws.sendClose(CloseCode.NORMAL_CLOSURE, CharBuffer.allocate(124)))
   122         );
   141         );
   123         checkAndClose(
   142         checkAndClose(
   124                 (ws) ->
   143                 (ws) ->
   125                         TestKit.assertThrows(NullPointerException.class,
   144                         TestKit.assertThrows(NullPointerException.class,
   126                                 "code",
   145                                 "code",