### Question:
SubnetSelectorService { List<CloudSubnet> collectPrivateSubnets(Collection<CloudSubnet> subnetMetas) { List<CloudSubnet> result = new ArrayList<>(); for (CloudSubnet subnetMeta : subnetMetas) { if (subnetMeta.isPrivateSubnet()) { result.add(subnetMeta); } } LOGGER.debug("Private subnets for selections: {}", result); return result; }    }### Answer:
@Test public void testCollectOnePrivateSubnetPerAzWhenEmptyThenReturnsEmtpyMap() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .build(); List<CloudSubnet> privateSubnetsPerAz = subnetSelectorService.collectPrivateSubnets(cloudSubnets); assertTrue(privateSubnetsPerAz.isEmpty()); }
@Test public void testCollectOnePrivateSubnetPerAzWhenOnePrivateSubnetInThreeDifferentAzsThenReturnsAllSubnets() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPrivateSubnet(AZ_A) .withPrivateSubnet(AZ_B) .withPrivateSubnet(AZ_C) .build(); List<CloudSubnet> privateSubnetsPerAz = subnetSelectorService.collectPrivateSubnets(cloudSubnets); assertThat(privateSubnetsPerAz, hasSize(3)); }
@Test public void testCollectOnePrivateSubnetPerAzWhenSubnetsInMoreThanThreeAzsThenReturnsSubnetsFromThreeAzsOnly() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPrivateSubnet(AZ_A) .withPrivateSubnet(AZ_B) .withPrivateSubnet(AZ_C) .withPrivateSubnet(AZ_D) .build(); List<CloudSubnet> privateSubnetsPerAz = subnetSelectorService.collectPrivateSubnets(cloudSubnets); assertThat(privateSubnetsPerAz, hasSize(4)); }
@Test public void testCollectOnePrivateSubnetPerAzWhenTwoInOneAzThenReturnsOnlyOneSubnet() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPrivateSubnet(AZ_A) .withPrivateSubnet(AZ_A) .build(); List<CloudSubnet> privateSubnetsPerAz = subnetSelectorService.collectPrivateSubnets(cloudSubnets); assertThat(privateSubnetsPerAz, hasSize(2)); }
@Test public void testCollectOnePrivateSubnetPerAzWhenOnePublicOnePrivateThenReturnsOnlyThePrivateSubnet() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPrivateSubnet(AZ_A) .withPublicSubnet(AZ_B) .build(); List<CloudSubnet> privateSubnetsPerAz = subnetSelectorService.collectPrivateSubnets(cloudSubnets); assertThat(privateSubnetsPerAz, hasSize(1)); assertTrue(getSubnetByAz(privateSubnetsPerAz, AZ_A).isPresent()); }
@Test public void testCollectOnePrivateSubnetPerAzWhenPublicOnlyThenReturnsEmptyMap() { List<CloudSubnet> cloudSubnets = new SubnetBuilder() .withPublicSubnet(AZ_A) .withPublicSubnet(AZ_B) .build(); List<CloudSubnet> privateSubnetsPerAz = subnetSelectorService.collectPrivateSubnets(cloudSubnets); assertTrue(privateSubnetsPerAz.isEmpty()); }