### Question:
SubnetSelectorService { List<CloudSubnet> collectPublicSubnets(Collection<CloudSubnet> subnetMetas) { List<CloudSubnet> result = new ArrayList<>(); for (CloudSubnet subnetMeta : subnetMetas) { if (isUsablePublicSubnet(subnetMeta)) { result.add(subnetMeta); } } LOGGER.debug("Public subnets for selections: {}", result); return result; }    }### Answer:
@Test public void testCollectOnePublicSubnetPerAzWhenEmptyThenReturnsEmpty() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertTrue(publicSubnetsPerAz.isEmpty()); }
@Test public void testCollectOnePublicSubnetPerAzWhenThreePublicInDifferentAzsThenReturnsAllSubnets() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPublicSubnet(AZ_A) .withPublicSubnet(AZ_B) .withPublicSubnet(AZ_C) .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertThat(publicSubnetsPerAz, hasSize(3)); }
@Test public void testCollectOnePublicSubnetPerAzWhenSubnetsInMoreThanThreeAzsThenReturnsSubnetsOfThreeAzsOnly() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPublicSubnet(AZ_A) .withPublicSubnet(AZ_B) .withPublicSubnet(AZ_C) .withPublicSubnet(AZ_D) .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertThat(publicSubnetsPerAz, hasSize(4)); }
@Test public void testCollectOnePublicSubnetPerAzWhenTwoPublicInOneAzThenReturnsOneSubnetOnly() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPublicSubnet(AZ_A) .withPublicSubnet(AZ_A) .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertThat(publicSubnetsPerAz, hasSize(2)); }
@Test public void testCollectOnePublicSubnetPerAzWhenOnePublicOnePrivateThenReturnsOnePublic() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPublicSubnet(AZ_A) .withPrivateSubnet(AZ_B) .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertThat(publicSubnetsPerAz, hasSize(1)); assertTrue(getSubnetByAz(publicSubnetsPerAz, AZ_A).isPresent()); }
@Test public void testCollectOnePublicSubnetPerAzWhenPrivateOnlyThenReturnsEmptyMap() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPrivateSubnet(AZ_A) .withPrivateSubnet(AZ_B) .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertTrue(publicSubnetsPerAz.isEmpty()); }
@Test public void testCollectOnePublicSubnetPerAzWhenPublicWithNoPublicIpThenReturnsEmptyMap() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPublicSubnetNoPublicIp(AZ_A) .build(); List<CloudSubnet> publicSubnetsPerAz = subnetSelectorService.collectPublicSubnets(cloudSubnets); assertTrue(publicSubnetsPerAz.isEmpty()); }