ReverseZoneUtils { protected static String getReverseZoneNetworkAddress(String baseIp, int range, int index) throws UnknownHostException { if (index < 0) { throw new IllegalArgumentException( String.format("Invalid index provided, must be positive: %d", index)); } if (range < 0) { throw new IllegalArgumentException( String.format("Invalid range provided, cannot be negative: %d", range)); } return calculateIp(baseIp, range, index); } private  ReverseZoneUtils();   }
@Test public void testGetReverseZoneNetworkAddress() throws Exception { assertEquals("172.17.4.0", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, RANGE, INDEX)); }
@Test public void testThrowIllegalArgumentExceptionIfIndexIsNegative() throws Exception { exception.expect(IllegalArgumentException.class); ReverseZoneUtils.getReverseZoneNetworkAddress(NET, RANGE, -1); }
@Test public void testThrowUnknownHostExceptionIfIpIsInvalid() throws Exception { exception.expect(UnknownHostException.class); ReverseZoneUtils .getReverseZoneNetworkAddress("213124.21231.14123.13", RANGE, INDEX); }
@Test public void testThrowIllegalArgumentExceptionIfRangeIsNegative() throws Exception { exception.expect(IllegalArgumentException.class); ReverseZoneUtils.getReverseZoneNetworkAddress(NET, -1, INDEX); }
@Test public void testVariousRangeAndIndexValues() throws Exception { assertEquals("172.17.9.0", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 256, 5)); assertEquals("172.17.4.128", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 128, 1)); assertEquals("172.18.0.0", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 256, 252)); assertEquals("172.17.12.0", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 1024, 2)); assertEquals("172.17.4.0", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 0, 1)); assertEquals("172.17.4.0", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 1, 0)); assertEquals("172.17.4.1", ReverseZoneUtils.getReverseZoneNetworkAddress(NET, 1, 1)); }