### Question:
IpAddressValidator { public boolean validateIpAddress(String addr) { boolean valid = false; if (addr == null) { return false; } if (anyIP) { valid = true; } else { if (ipaddr.contains(addr)) { valid = true; } else { if (!wildCardIPs.isEmpty()) { for (String ip : wildCardIPs) { if (addr.startsWith(ip)) { valid = true; break; } } } } } return valid; } IpAddressValidator(String commaSeparatedIpAddresses); boolean validateIpAddress(String addr); boolean allowsAnyIP(); List<String> getIPAddresses();  }### Answer:
@Test public void testExplicitIpAddress() throws Exception { IpAddressValidator ipv = new IpAddressValidator(test); assertTrue("Should have validated 127.0.0.1", ipv.validateIpAddress("127.0.0.1")); assertFalse("Should not have validated 127.0.0.2", ipv.validateIpAddress("127.0.0.2")); assertTrue("Should have validated 0:0:0:0:0:0:0:1", ipv.validateIpAddress("0:0:0:0:0:0:0:1")); assertFalse("Should not have validated 1:0:0:0:0:0:0:1", ipv.validateIpAddress("1:0:0:0:0:0:0:1")); ipv = new IpAddressValidator(testWeirdConfig); assertTrue("Should have validated 127.0.0.1", ipv.validateIpAddress("127.0.0.1")); assertFalse("Should not have validated 127.0.0.2", ipv.validateIpAddress("127.0.0.2")); }
@Test public void testNullConfig() throws Exception { IpAddressValidator ipv = new IpAddressValidator(testNullConfig); assertTrue("Should have validated 127.0.0.1", ipv.validateIpAddress("127.0.0.1")); }
@Test public void testNullRemoteIP() throws Exception { IpAddressValidator ipv = new IpAddressValidator(testNullConfig); assertFalse("Should not have validated null", ipv.validateIpAddress(null)); }
@Test public void testWildcardIpAddress() throws Exception { IpAddressValidator ipv = new IpAddressValidator(test); assertTrue("Should have validated 192.168.1.1", ipv.validateIpAddress("192.168.1.1")); assertFalse("Should not have validated 192.168.2.1", ipv.validateIpAddress("192.168.2.1")); assertTrue("Should have validated 0:0:0:0:0:0:0:2", ipv.validateIpAddress("0:0:0:0:0:0:0:2")); assertFalse("Should not have validated 0:0:0:0:0:0:2:2", ipv.validateIpAddress("0:0:0:0:0:2:2:2")); assertTrue("Should have validated 193.168.1.1", ipv.validateIpAddress("193.168.1.1")); assertFalse("Should not have validated 194.168.2.1", ipv.validateIpAddress("194.168.2.1")); ipv = new IpAddressValidator(testWeirdConfig); assertTrue("Should have validated 293.168.1.1", ipv.validateIpAddress("293.168.1.1")); }