ServerDelegate extends Delegate { @Override public void applyDelegate(Config config) { config.setDefaultRunningMode(RunningModeType.SERVER); int parsedPort = parsePort(port); InboundConnection inboundConnection = config.getDefaultServerConnection(); if (inboundConnection != null) { inboundConnection.setPort(parsedPort); } else { inboundConnection = new InboundConnection(parsedPort); config.setDefaultServerConnection(inboundConnection); } } ServerDelegate(); Integer getPort(); void setPort(int port); @Override void applyDelegate(Config config);  }
@Test public void testApplyDelegate() { Config config = Config.createConfig(); int expectedDefaultTimeout = 390121; config.getDefaultServerConnection().setTimeout(expectedDefaultTimeout); args = new String[2]; args[0] = "-port"; args[1] = "1234"; jcommander.parse(args); delegate.applyDelegate(config); AliasedConnection actual = config.getDefaultServerConnection(); assertNotNull(actual); assertThat(actual.getPort(), equalTo(1234)); assertThat(actual.getLocalConnectionEndType(), equalTo(ConnectionEndType.SERVER)); assertThat(actual.getTimeout(), equalTo(expectedDefaultTimeout)); }
@Test public void applyingEmptyDelegateThrowsException() { Config config = Config.createConfig(); exception.expect(ParameterException.class); exception.expectMessage("Port must be set, but was not specified"); delegate.applyDelegate(config); }
@Test @Ignore public void testNothingSetNothingChanges() { Config config = Config.createConfig(); Config config2 = Config.createConfig(); delegate.applyDelegate(config); List<String> excludeFields = new LinkedList<>(); excludeFields.add("keyStore"); excludeFields.add("ourCertificate"); excludeFields.add("connectionEnd"); assertTrue(EqualsBuilder.reflectionEquals(config, config2, excludeFields)); }