CloudAddressResolver { public String getAddress(final Set<String> addresses, final Set<String> backupAddresses, final SubnetInfo subnetInfo, final Pattern regex) { if (subnetInfo != null) { for (final String address : addresses) { if (subnetInfo.isInRange(address)) { return address; } } } if (regex != null) { for (final String address : addresses) { if (regex.matcher(address).matches()) { return address; } } } if (subnetInfo != null) { for (final String address : backupAddresses) { if (subnetInfo.isInRange(address)) { return address; } } } if (regex != null) { for (final String address : backupAddresses) { if (regex.matcher(address).matches()) { return address; } } } if (addresses.size() > 0) { return addresses.iterator().next(); } return null; }  String getAddress(final Set<String> addresses, final Set<String> backupAddresses,
			final SubnetInfo subnetInfo, final Pattern regex);  }
@Test public void testGetAddress_1() throws Exception { final CloudAddressResolver fixture = new CloudAddressResolver(); final Set<String> addresses = new HashSet(Arrays.asList("10.4.12.1")); final Set<String> backupAddresses = new HashSet(); final org.apache.commons.net.util.SubnetUtils.SubnetInfo subnetInfo = new SubnetUtils("10.4.12.0/22").getInfo(); final Pattern regex = null; final String result = fixture.getAddress(addresses, backupAddresses, subnetInfo, regex); assertEquals("10.4.12.1", result); }
@Test public void testGetAddress_2() throws Exception { final CloudAddressResolver fixture = new CloudAddressResolver(); final Set<String> addresses = new HashSet(); final Set<String> backupAddresses = new HashSet(); final org.apache.commons.net.util.SubnetUtils.SubnetInfo subnetInfo = new SubnetUtils("10.4.12.0/22").getInfo(); final Pattern regex = null; final String result = fixture.getAddress(addresses, backupAddresses, subnetInfo, regex); assertEquals(null, result); }
@Test public void testGetAddress_3() throws Exception { final CloudAddressResolver fixture = new CloudAddressResolver(); final Set<String> addresses = new HashSet(Arrays.asList("10.4.12.1")); final Set<String> backupAddresses = new HashSet(); final org.apache.commons.net.util.SubnetUtils.SubnetInfo subnetInfo = null; final Pattern regex = Pattern.compile("10.4.12.*"); final String result = fixture.getAddress(addresses, backupAddresses, subnetInfo, regex); assertEquals("10.4.12.1", result); }
@Test public void testGetAddress_4() throws Exception { final CloudAddressResolver fixture = new CloudAddressResolver(); final Set<String> addresses = new HashSet(Arrays.asList("10.4.12.1", "10.4.13.12")); final Set<String> backupAddresses = new HashSet(); final org.apache.commons.net.util.SubnetUtils.SubnetInfo subnetInfo = null; final Pattern regex = Pattern.compile("10.4.13.*"); final String result = fixture.getAddress(addresses, backupAddresses, subnetInfo, regex); assertEquals("10.4.13.12", result); }
@Test public void testGetAddress_5() throws Exception { final CloudAddressResolver fixture = new CloudAddressResolver(); final Set<String> addresses = new HashSet(); final Set<String> backupAddresses = new HashSet(Arrays.asList("10.4.12.1", "10.4.13.12")); final org.apache.commons.net.util.SubnetUtils.SubnetInfo subnetInfo = null; final Pattern regex = Pattern.compile("10.4.13.*"); final String result = fixture.getAddress(addresses, backupAddresses, subnetInfo, regex); assertEquals("10.4.13.12", result); }
@Test public void testGetAddress_6() throws Exception { final CloudAddressResolver fixture = new CloudAddressResolver(); final Set<String> addresses = new HashSet(); final Set<String> backupAddresses = new HashSet(Arrays.asList("10.4.12.1", "10.4.15.12")); final org.apache.commons.net.util.SubnetUtils.SubnetInfo subnetInfo = null; final Pattern regex = Pattern.compile("10.4.13.*"); final String result = fixture.getAddress(addresses, backupAddresses, subnetInfo, regex); assertEquals(null, result); }