TimeoutDelegate extends Delegate { @Override public void applyDelegate(Config config) { if (timeout == null) { return; } if (config.getDefaultClientConnection() == null) { config.setDefaultClientConnection(new OutboundConnection()); } if (config.getDefaultServerConnection() == null) { config.setDefaultServerConnection(new InboundConnection()); } config.getDefaultClientConnection().setTimeout(timeout); config.getDefaultServerConnection().setTimeout(timeout); } TimeoutDelegate(); Integer getTimeout(); void setTimeout(int timeout); @Override void applyDelegate(Config config);  }
@Test public void testApplyDelegate() { Config config = Config.createConfig(); config.getDefaultClientConnection().setTimeout(1000); config.getDefaultServerConnection().setTimeout(1000); int expectedTimeout = 123; args = new String[2]; args[0] = "-timeout"; args[1] = Integer.toString(expectedTimeout); jcommander.parse(args); delegate.applyDelegate(config); assertThat(config.getDefaultClientConnection().getTimeout(), equalTo(expectedTimeout)); assertThat(config.getDefaultServerConnection().getTimeout(), equalTo(expectedTimeout)); }
@Test public void testNothingSetNothingChanges() { Config config = Config.createConfig(); Config config2 = Config.createConfig(); delegate.applyDelegate(config); assertTrue(EqualsBuilder.reflectionEquals(config, config2)); }