### Question:
ServerRetryHandler implements InboundHandler { @Override public void onReceivePacket(final Packet packet, final PipelineContext ctx) { requireNonNull(packet); requireNonNull(ctx); if (ctx.getState() == State.Started) { if (packet instanceof InitialPacket) { final InitialPacket initialPacket = (InitialPacket) packet; if (initialPacket.getToken().isPresent()) { if (retryTokenManager.validate( initialPacket.getToken().get(), ctx.getPeerAddress().getAddress(), now())) { } else { sendRetry(ctx, initialPacket); return; } } else { sendRetry(ctx, initialPacket); return; } } } ctx.next(packet); } ServerRetryHandler(
      final RetryToken retryTokenManager, final long ttl, final TimeUnit timeUnit); @Override void onReceivePacket(final Packet packet, final PipelineContext ctx);  }### Answer:
@Test public void retry() { final InitialPacket initialPacket = p(Optional.empty()); handler.onReceivePacket(initialPacket, ctx); assertToken(initialPacket.getSourceConnectionId()); verify(ctx, never()).next(any(Packet.class)); }
@Test public void withToken() { final InitialPacket initialPacket = p(of(retryToken.create(address, currentTimeMillis() + 10000))); handler.onReceivePacket(initialPacket, ctx); verify(ctx, never()).sendPacket(any(Packet.class)); verify(ctx).next(initialPacket); }
@Test public void withInvalidToken() { final InitialPacket initialPacket = p(of("this is not a token".getBytes())); handler.onReceivePacket(initialPacket, ctx); assertToken(initialPacket.getSourceConnectionId()); verify(ctx, never()).next(any(Packet.class)); }
@Test public void verifyState() { when(ctx.getState()).thenReturn(State.BeforeHello); final InitialPacket initialPacket = p(Optional.empty()); handler.onReceivePacket(initialPacket, ctx); verify(ctx, never()).sendPacket(any(RetryPacket.class)); verify(ctx).next(initialPacket); }