HandlerFactory { public static HandshakeMessageHandler getHandshakeHandler(TlsContext context, HandshakeMessageType type) { try { switch (type) { case CERTIFICATE: return new CertificateMessageHandler(context); case CERTIFICATE_REQUEST: return new CertificateRequestHandler(context); case CERTIFICATE_STATUS: return new CertificateStatusHandler(context); case CERTIFICATE_VERIFY: return new CertificateVerifyHandler(context); case CLIENT_HELLO: return new ClientHelloHandler(context); case CLIENT_KEY_EXCHANGE: return getClientKeyExchangeHandler(context); case ENCRYPTED_EXTENSIONS: return new EncryptedExtensionsHandler(context); case END_OF_EARLY_DATA: return new EndOfEarlyDataHandler(context); case FINISHED: return new FinishedHandler(context); case HELLO_RETRY_REQUEST: return new HelloRetryRequestHandler(context); case HELLO_REQUEST: return new HelloRequestHandler(context); case HELLO_VERIFY_REQUEST: return new HelloVerifyRequestHandler(context); case NEW_SESSION_TICKET: return new NewSessionTicketHandler(context); case SERVER_HELLO: return new ServerHelloHandler(context); case SERVER_HELLO_DONE: return new ServerHelloDoneHandler(context); case SERVER_KEY_EXCHANGE: return getServerKeyExchangeHandler(context); case SUPPLEMENTAL_DATA: return new SupplementalDataHandler(context); case UNKNOWN: return new UnknownHandshakeHandler(context); } } catch (UnsupportedOperationException E) { LOGGER.debug("Could not retrieve correct Handler, returning UnknownHandshakeHandler", E); } return new UnknownHandshakeHandler(context); } private  HandlerFactory(); static ProtocolMessageHandler getHandler(TlsContext context, ProtocolMessageType protocolType,
            HandshakeMessageType handshakeType); static HandshakeMessageHandler getHandshakeHandler(TlsContext context, HandshakeMessageType type); static ExtensionHandler getExtensionHandler(TlsContext context, ExtensionType type,
            HandshakeMessageType handshakeMessageType);  }
@Test public void getHandshakeHandler() { assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.CERTIFICATE) instanceof CertificateMessageHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.CERTIFICATE_REQUEST) instanceof CertificateRequestHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.CERTIFICATE_VERIFY) instanceof CertificateVerifyHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.CLIENT_HELLO) instanceof ClientHelloHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.ENCRYPTED_EXTENSIONS) instanceof EncryptedExtensionsHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.END_OF_EARLY_DATA) instanceof EndOfEarlyDataHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.FINISHED) instanceof FinishedHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.HELLO_RETRY_REQUEST) instanceof HelloRetryRequestHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.HELLO_REQUEST) instanceof HelloRequestHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.HELLO_VERIFY_REQUEST) instanceof HelloVerifyRequestHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.NEW_SESSION_TICKET) instanceof NewSessionTicketHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.SERVER_HELLO) instanceof ServerHelloHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.SERVER_HELLO_DONE) instanceof ServerHelloDoneHandler); assertTrue(HandlerFactory.getHandshakeHandler(context, HandshakeMessageType.UNKNOWN) instanceof UnknownHandshakeHandler); }