ClientConfigurationParser { public ClientConfiguration parseConfig(HierarchicalConfiguration config) throws ConfigurationException { InetAddress address = null; int port = config.getInt("[@port]", 0); String listenRep = config.getString("[@remote]"); if(StringUtils.isBlank(listenRep)) throw new ConfigurationException("remote attribute required"); try { address = InetAddress.getByName(listenRep); } catch (UnknownHostException e) { log.error("failed to parse remote address: " + listenRep, e); throw new ConfigurationException(e); } return new ClientConfigurationImpl(new InetSocketAddress(address, port)); }  ClientConfiguration parseConfig(HierarchicalConfiguration config);  }
@Test public void testAddressOnlyClientConfig() throws ConfigurationException { ClientConfiguration clientConfig = parser.parseConfig(config.configurationAt("Client(0)")); Assert.assertEquals(0, clientConfig.getRemoteAddress().getPort()); Assert.assertEquals("192.168.4.1", clientConfig.getRemoteAddress().getHostName()); }
@Test public void testAddressPortClientConfig() throws ConfigurationException { ClientConfiguration clientConfig = parser.parseConfig(config.configurationAt("Client(1)")); Assert.assertEquals(17179, clientConfig.getRemoteAddress().getPort()); Assert.assertEquals("192.168.4.1", clientConfig.getRemoteAddress().getHostName()); }
@Test(expected=ConfigurationException.class) public void testDefaultClientConfig() throws ConfigurationException { parser.parseConfig(config.configurationAt("Client(2)")); }
@Test(expected=ConfigurationException.class) public void testPortOnlyClientConfig() throws ConfigurationException { parser.parseConfig(config.configurationAt("Client(3)")); }