@Test
public void testAcceptHandshake() throws Exception {

    Session session = new Session(communications, options, new HandshakeHandler(), new RequestHandler(screen));
    SocketChannel channel = createNiceMock(SocketChannel.class);
    SocketAddress addr = createNiceMock(SocketAddress.class);
    Socket socket = createNiceMock(Socket.class);
    channel.getRemoteAddress();
    expectLastCall().andReturn(addr);
    channel.socket();
    expectLastCall().andReturn(socket);
    socket.getInputStream();
    expectLastCall().andReturn(new ByteArrayInputStream("".getBytes())); // We are going to ignore this part anyway.
    replay(channel, addr, socket);
    session.handle(channel);
    session.setExpecting(PACKETS.HANDSHAKE_OPEN);
    HandshakePacket handshakePacket = new HandshakePacket();
    handshakePacket.getFlags().setHandshakeRequest(true).setRegistered(false);
    handshakePacket.setKey(new PublicKey(new OpenSSLRSAPEM(OpenSSLRSAPEM.INTEGER.valueOf(65537), OpenSSLRSAPEM.INTEGER.randomINTEGER(64))));
    PacketBuffer packetBuffer = new PacketBuffer();
    handler.initPacketBuffer(packetBuffer);
    packetBuffer.write(handshakePacket.getParser().serialize());
    assertEquals(CONNECTION_PHASE.HANDSHAKE_ACCEPTED, handler.handlePacket(packetBuffer, session));
}