+
+ @Test
+ public void testInetAddressConflict() throws UnknownHostException {
+
+ // test a ipv4 testAddress in the same subnet as the filter
+ // the method should return false as there is no conflict
+ Assert.assertFalse(NetUtils.inetAddressConflict(
+ InetAddress.getByName("9.9.1.1"),
+ InetAddress.getByName("9.9.1.0"), null,
+ InetAddress.getByName("255.255.255.0")));
+
+ // test a ipv4 testAddress not in the same subnet as the filter
+ // the method should return true as there is a conflict
+ Assert.assertTrue(NetUtils.inetAddressConflict(
+ InetAddress.getByName("9.9.2.1"),
+ InetAddress.getByName("9.9.1.0"), null,
+ InetAddress.getByName("255.255.255.0")));
+
+ // test a ipv4 testAddress more generic than the filter
+ // the method should return true as there is a conflict
+ Assert.assertTrue(NetUtils.inetAddressConflict(
+ InetAddress.getByName("9.9.1.1"),
+ InetAddress.getByName("9.9.1.0"),
+ InetAddress.getByName("255.255.0.0"),
+ InetAddress.getByName("255.255.255.0")));
+
+ // test a ipv4 testAddress less generic than the filter and in the same
+ // subnet as the filter
+ // the method should return false as there is no conflict
+ Assert.assertFalse(NetUtils.inetAddressConflict(
+ InetAddress.getByName("9.9.1.0"),
+ InetAddress.getByName("9.9.0.0"),
+ InetAddress.getByName("255.255.255.0"),
+ InetAddress.getByName("255.255.0.0")));
+
+ // test a ipv4 testAddress less generic than the filter and not in the
+ // same subnet as the filter
+ // the method should return true as there is a conflict
+ Assert.assertTrue(NetUtils.inetAddressConflict(
+ InetAddress.getByName("9.8.1.0"),
+ InetAddress.getByName("9.9.0.0"),
+ InetAddress.getByName("255.255.255.0"),
+ InetAddress.getByName("255.255.0.0")));
+
+ }