WebSocketServerHandler extends SimpleChannelInboundHandler<Object> { @Override public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof FullHttpRequest) { handleHttpRequest(ctx, (FullHttpRequest) msg); } else if (msg instanceof WebSocketFrame) { WebSocketFrame frame = (WebSocketFrame) msg; boolean handle = handleWebSocketFrame(ctx, frame); if (handle) { ctx.fireChannelRead(frame.content().retain()); } } } WebSocketServerHandler(List<String> supportedProtocols, int maxFramePayloadLength); @Override void channelRead0(ChannelHandlerContext ctx, Object msg); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); HttpRequest getHttpRequest();  }
@Test public void testRead0HandleContinuationFrame() throws Exception { ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); Object msg = new ContinuationWebSocketFrame(); spy.channelRead0(ctx, msg); verify(spy).channelRead0(ctx, msg); verify(ctx).fireChannelRead(any(ByteBuf.class)); verifyNoMoreInteractions(spy, ctx); }
@Test public void testRead0HandleBinaryFrame() throws Exception { ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); Object msg = new BinaryWebSocketFrame(); spy.channelRead0(ctx, msg); verify(spy).channelRead0(ctx, msg); verify(ctx).fireChannelRead(any(ByteBuf.class)); verifyNoMoreInteractions(spy, ctx); }
@Test public void testRead0HandleTextFrame() throws Exception { ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); Object msg = new TextWebSocketFrame(); spy.channelRead0(ctx, msg); verify(spy).channelRead0(ctx, msg); verify(ctx).fireChannelRead(any(ByteBuf.class)); verifyNoMoreInteractions(spy, ctx); }