RawUdpDataToMTSPacketDecoder extends MessageToMessageDecoder<DatagramPacket> { public void setMtsParser(MTSParser mtsParser) { this.mtsParser = mtsParser; } RawUdpDataToMTSPacketDecoder(
      PacketBuffer packetBuffer, UdpStreamProcessor udpStreamProcessor); void setMtsParser(MTSParser mtsParser); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelActive(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); static final byte TS_SYNC; static final int BUFFER_SIZE; static final int TS_PACKET_SIZE; static final long TOKEN_CHECK_PERIOD; }
@SuppressWarnings("unchecked") @Test public void testCorruptedData() throws Exception { RawUdpDataToMTSPacketDecoder.MTSParser mtsParser = mock(RawUdpDataToMTSPacketDecoder.MTSParser.class); ResettableMTSSource resettable = mock(ResettableMTSSource.class); Mockito.when(mtsParser.parse(Mockito.any())).thenReturn(resettable); MTSPacket mtsPacket = mock(MTSPacket.class); Mockito.when(resettable.nextPacket()).thenThrow(RuntimeException.class).thenReturn(mtsPacket); int packetCount = 2; List<DatagramPacket> datagramPackets = toDatagrams(flatten(createTsPackets(packetCount))); PacketBuffer packetBuffer = mock(PacketBuffer.class); RawUdpDataToMTSPacketDecoder rawUdpDataToMTSPacketDecoder = new RawUdpDataToMTSPacketDecoder(packetBuffer, mock(UdpStreamProcessor.class)); rawUdpDataToMTSPacketDecoder.setMtsParser(mtsParser); EmbeddedChannel channel = new EmbeddedChannel(rawUdpDataToMTSPacketDecoder); datagramPackets.forEach(channel::writeInbound); List<Object> outputList = NettyUtility.read(channel); assertThat(outputList, hasSize(packetCount - 1)); }