ProtocolVersionDelegate extends Delegate { @Override public void applyDelegate(Config config) { if (protocolVersion == null) { return; } config.setHighestProtocolVersion(protocolVersion); config.setDefaultSelectedProtocolVersion(protocolVersion); TransportHandlerType th = TransportHandlerType.TCP; if (config.getHighestProtocolVersion().isDTLS()) { th = TransportHandlerType.UDP; } if (config.getDefaultClientConnection() == null) { config.setDefaultClientConnection(new OutboundConnection()); } if (config.getDefaultServerConnection() == null) { config.setDefaultServerConnection(new InboundConnection()); } config.getDefaultClientConnection().setTransportHandlerType(th); config.getDefaultServerConnection().setTransportHandlerType(th); } ProtocolVersionDelegate(); ProtocolVersion getProtocolVersion(); void setProtocolVersion(ProtocolVersion protocolVersion); @Override void applyDelegate(Config config);  }
@Test public void testApplyDelegate() { Config config = Config.createConfig(); config.setHighestProtocolVersion(ProtocolVersion.SSL2); config.getDefaultClientConnection().setTransportHandlerType(TransportHandlerType.EAP_TLS); config.getDefaultServerConnection().setTransportHandlerType(TransportHandlerType.EAP_TLS); args = new String[2]; args[0] = "-version"; args[1] = "TLS12"; assertThat(config.getHighestProtocolVersion(), equalTo(ProtocolVersion.SSL2)); assertThat(config.getDefaultClientConnection().getTransportHandlerType(), equalTo(TransportHandlerType.EAP_TLS)); assertThat(config.getDefaultServerConnection().getTransportHandlerType(), equalTo(TransportHandlerType.EAP_TLS)); jcommander.parse(args); delegate.applyDelegate(config); assertThat(config.getHighestProtocolVersion(), equalTo(ProtocolVersion.TLS12)); assertThat(config.getDefaultClientConnection().getTransportHandlerType(), equalTo(TransportHandlerType.TCP)); assertThat(config.getDefaultServerConnection().getTransportHandlerType(), equalTo(TransportHandlerType.TCP)); }
@Test public void testNothingSetNothingChanges() { Config config = Config.createConfig(); Config config2 = Config.createConfig(); delegate.applyDelegate(config); assertTrue(EqualsBuilder.reflectionEquals(config, config2, "keyStore", "ourCertificate")); }