### Question:
ServerTLSManager implements InboundHandler { @Override public void onReceivePacket(final Packet packet, final PipelineContext ctx) { final State state = ctx.getState(); if (state == State.Started) { if (packet instanceof InitialPacket) { final InitialPacket initialPacket = (InitialPacket) packet; if (initialPacket.getToken().isPresent()) { final CryptoFrame cf = (CryptoFrame) initialPacket.getPayload().getFrames().get(0); final ServerTlsSession.ServerHelloAndHandshake shah = tlsSession.handleClientHello(cf.getCryptoData()); ctx.send(new CryptoFrame(0, shah.getServerHello())); tlsSession.setHandshakeAead(shah.getHandshakeAEAD()); ctx.send(new CryptoFrame(0, shah.getServerHandshake())); tlsSession.setOneRttAead(shah.getOneRttAEAD()); ctx.setState(State.BeforeReady); } } else { throw new IllegalStateException("Unexpected packet in BeforeInitial: " + packet); } } else if (state == State.BeforeReady && packet instanceof HandshakePacket) { final HandshakePacket fp = (HandshakePacket) packet; final CryptoFrame cryptoFrame = (CryptoFrame) fp.getPayload().getFrames().get(0); tlsSession.handleClientFinished(cryptoFrame.getCryptoData()); tlsSession.unsetInitialAead(); tlsSession.unsetHandshakeAead(); ctx.setState(State.Ready); } ctx.next(packet); } ServerTLSManager(
      final ConnectionId connectionId,
      final TransportParameters transportParameters,
      final PrivateKey privateKey,
      final List<byte[]> certificates); @Override void onReceivePacket(final Packet packet, final PipelineContext ctx); AEAD getAEAD(final EncryptionLevel level); boolean available(final EncryptionLevel level);  }### Answer:
@Test public void handshake() throws CertificateInvalidException { final byte[] ch = clientTlsSession.startHandshake(); final PipelineContext ctx = mock(PipelineContext.class); when(ctx.getState()).thenReturn(State.Started); final Packet chPacket = ip(ch); manager.onReceivePacket(chPacket, ctx); final ArgumentCaptor<CryptoFrame> cfCaptor = ArgumentCaptor.forClass(CryptoFrame.class); verify(ctx, times(2)).send(cfCaptor.capture()); verify(ctx).setState(State.BeforeReady); verify(ctx).next(chPacket); clientTlsSession.handleServerHello(cfCaptor.getAllValues().get(0).getCryptoData()); final ClientTlsSession.HandshakeResult hr = clientTlsSession.handleHandshake(cfCaptor.getAllValues().get(1).getCryptoData()).get(); when(ctx.getState()).thenReturn(State.BeforeReady); final Packet finPacket = hp(hr.getFin()); manager.onReceivePacket(finPacket, ctx); verify(ctx, times(2)).send(any(CryptoFrame.class)); verify(ctx).setState(State.Ready); verify(ctx).next(finPacket); }