### Question:
AwsCreatedSubnetProvider { Set<CreatedSubnet> provide(Map<String, String> output, List<SubnetRequest> subnetRequests, boolean privateSubnetEnabled) { Set<CreatedSubnet> subnets = new HashSet<>(); for (SubnetRequest subnetRequest : subnetRequests) { CreatedSubnet createdPublicSubnet = new CreatedSubnet(); createdPublicSubnet.setSubnetId(getValue(output, "id" + subnetRequest.getIndex())); createdPublicSubnet.setAvailabilityZone(subnetRequest.getAvailabilityZone()); if (!Strings.isNullOrEmpty(subnetRequest.getPrivateSubnetCidr()) && privateSubnetEnabled) { createdPublicSubnet.setCidr(subnetRequest.getPrivateSubnetCidr()); createdPublicSubnet.setPublicSubnet(false); createdPublicSubnet.setMapPublicIpOnLaunch(false); createdPublicSubnet.setIgwAvailable(false); } else { createdPublicSubnet.setCidr(subnetRequest.getPublicSubnetCidr()); createdPublicSubnet.setPublicSubnet(true); createdPublicSubnet.setMapPublicIpOnLaunch(true); createdPublicSubnet.setIgwAvailable(true); } createdPublicSubnet.setType(subnetRequest.getType()); subnets.add(createdPublicSubnet); } return subnets; }    }### Answer:
@Test public void testProvideShouldReturnTheSubnetsFromCloudformationOutput() { List<SubnetRequest> cidrs = Lists.newArrayList( publicSubnetRequest("10.0.0.16/19", 0), publicSubnetRequest("10.0.0.16/19", 1), publicSubnetRequest("10.0.0.16/19", 2)); Map<String, String> output = new HashMap<>(); output.put("id0", "public-subnet-0"); output.put("id1", "public-subnet-1"); output.put("id2", "public-subnet-1"); Set<CreatedSubnet> actual = underTest.provide(output, cidrs, true); assertEquals(cidrs.size(), actual.size()); assertTrue(actual.stream().allMatch(createdSubnet -> output.containsValue(createdSubnet.getSubnetId()))); }
@Test public void testProvideShouldReturnThePublicSubnetsWhenThePrivateSubnetsAreDisabled() { List<SubnetRequest> cidrs = Lists.newArrayList( publicSubnetRequest("10.0.0.16/19", 0), publicSubnetRequest("10.0.0.16/19", 1), publicSubnetRequest("10.0.0.16/19", 2)); Map<String, String> output = new HashMap<>(); output.put("id0", "public-subnet-0"); output.put("id1", "public-subnet-1"); output.put("id2", "public-subnet-1"); Set<CreatedSubnet> actual = underTest.provide(output, cidrs, true); assertEquals(cidrs.size(), actual.size()); assertTrue(actual.stream().allMatch(createdSubnet -> output.containsValue(createdSubnet.getSubnetId()))); }
@Test(expected = CloudConnectorException.class) public void testProvideShouldThrowAnExceptionWhenAValueIsMissingFromTheCloudformationOutput() { List<SubnetRequest> cidrs = Lists.newArrayList( publicSubnetRequest("10.0.0.16/19", 0), publicSubnetRequest("10.0.0.16/19", 1), publicSubnetRequest("10.0.0.16/19", 2)); underTest.provide(new HashMap<>(), cidrs, true); }