### Question:
PacketRouter { public void route( final ByteBuf bb, final PacketSender sender, final InetSocketAddress peerAddress) { while (bb.isReadable()) { final HalfParsedPacket<?> halfParsed = Packet.parse(bb, ConnectionId.LENGTH); final ServerConnection conn = connections.get( halfParsed.getConnectionId(), listener, sender, peerAddress); if (validateVersion(halfParsed, sender, conn.getLocalConnectionId())) { final Packet packet = halfParsed.complete(conn::getAEAD); MDC.put("actor", "server"); if (packet instanceof FullPacket) { MDC.put("packetnumber", Long.toString(((FullPacket) packet).getPacketNumber())); } if (packet.getDestinationConnectionId().isPresent()) { MDC.put("connectionid", packet.getDestinationConnectionId().get().toString()); } conn.onPacket(packet); } else { break; } } } PacketRouter(
      final Version version, final Connections connections, final StreamListener listener); void route(
      final ByteBuf bb, final PacketSender sender, final InetSocketAddress peerAddress);  }### Answer:
@Test public void route() { final InitialPacket packet = InitialPacket.create( of(destConnId), empty(), 2, Version.DRAFT_18, empty(), new PaddingFrame(1)); final ByteBuf bb = Unpooled.buffer(); packet.write(bb, aead); router.route(bb, sender, peerAddress); verify(connection).onPacket(packet); }
@Test(expected = RuntimeException.class) public void invalidPacket() { final ByteBuf bb = Unpooled.wrappedBuffer("this is not a packet".getBytes()); router.route(bb, sender, peerAddress); }
@Test public void versionMismatch() { final InitialPacket packet = InitialPacket.create( of(destConnId), empty(), 2, Version.FINAL, empty(), new PaddingFrame(1)); final ByteBuf bb = Unpooled.buffer(); packet.write(bb, aead); router.route(bb, sender, peerAddress); final ArgumentCaptor<VersionNegotiationPacket> captor = ArgumentCaptor.forClass(VersionNegotiationPacket.class); verify(sender).send(captor.capture(), any()); final VersionNegotiationPacket verNeg = captor.getValue(); assertEquals(destConnId, verNeg.getDestinationConnectionId().get()); assertEquals(srcConnId, verNeg.getSourceConnectionId().get()); assertEquals(List.of(Version.DRAFT_18), verNeg.getSupportedVersions()); }