DecodedStreamDataHandler extends ChannelInboundHandlerAdapter { private void frameComplete(boolean isIDR) { packetBuffer.frameComplete(isIDR ? PacketBuffer.FrameType.IDR : PacketBuffer.FrameType.NON_IDR); } DecodedStreamDataHandler(PacketBuffer packetBuffer); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }
@Test public void testWrongArgumentType() throws Exception { EmbeddedChannel channel = new EmbeddedChannel(new DecodedStreamDataHandler(packetBuffer)); channel.writeInbound("not a DecodedStreamData.class"); verify(packetBuffer, never()).frameComplete(any()); }
@Test public void testDetectIDR() throws Exception { List<NALUnit> nalUnitList = new LinkedList<>(); NALUnit nalUnit = new NALUnit(NALUnitType.IDR_SLICE, 0); nalUnitList.add(nalUnit); Mpeg4DecodedStreamData decodedStreamData = mock(Mpeg4DecodedStreamData.class); when(decodedStreamData.getNalUnits()).thenReturn(nalUnitList); doCallRealMethod().when(decodedStreamData).accept(any()); EmbeddedChannel channel = new EmbeddedChannel(new DecodedStreamDataHandler(packetBuffer)); channel.writeInbound(decodedStreamData); verify(packetBuffer).frameComplete(PacketBuffer.FrameType.IDR); }
@Test public void testDetectNonIDR() throws Exception { EmbeddedChannel channel = new EmbeddedChannel(new DecodedStreamDataHandler(packetBuffer)); List<NALUnit> nalUnitList = new LinkedList<>(); NALUnit nalUnit = new NALUnit(NALUnitType.NON_IDR_SLICE, 0); nalUnitList.add(nalUnit); Mpeg4DecodedStreamData decodedStreamData = mock(Mpeg4DecodedStreamData.class); when(decodedStreamData.getNalUnits()).thenReturn(nalUnitList); doCallRealMethod().when(decodedStreamData).accept(any()); channel.writeInbound(decodedStreamData); verify(packetBuffer).frameComplete(PacketBuffer.FrameType.NON_IDR); }