HandlerFactory { public static ProtocolMessageHandler getHandler(TlsContext context, ProtocolMessageType protocolType, HandshakeMessageType handshakeType) { if (protocolType == null) { throw new RuntimeException("Cannot retrieve Handler, ProtocolMessageType is null"); } try { switch (protocolType) { case HANDSHAKE: HandshakeMessageType hmt = HandshakeMessageType.getMessageType(handshakeType.getValue()); return HandlerFactory.getHandshakeHandler(context, hmt); case CHANGE_CIPHER_SPEC: return new ChangeCipherSpecHandler(context); case ALERT: return new AlertHandler(context); case APPLICATION_DATA: return new ApplicationMessageHandler(context); case HEARTBEAT: return new HeartbeatMessageHandler(context); default: return new UnknownHandler(context); } } catch (UnsupportedOperationException 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 getHandler() { assertTrue(HandlerFactory.getHandler(context, ProtocolMessageType.HANDSHAKE, HandshakeMessageType.UNKNOWN) instanceof UnknownHandshakeHandler); assertTrue(HandlerFactory.getHandler(context, ProtocolMessageType.CHANGE_CIPHER_SPEC, null) instanceof ChangeCipherSpecHandler); assertTrue(HandlerFactory.getHandler(context, ProtocolMessageType.ALERT, null) instanceof AlertHandler); assertTrue(HandlerFactory.getHandler(context, ProtocolMessageType.APPLICATION_DATA, null) instanceof ApplicationMessageHandler); assertTrue(HandlerFactory.getHandler(context, ProtocolMessageType.HEARTBEAT, null) instanceof HeartbeatMessageHandler); assertTrue(HandlerFactory.getHandler(context, ProtocolMessageType.UNKNOWN, null) instanceof UnknownHandler); }