### Question:
AzureSubnetSelectorService { public SubnetSelectionResult select(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters) { Optional<String> errorMessage = quickValidate(subnetMetas, subnetSelectionParameters); if (errorMessage.isPresent()) { LOGGER.debug("{}", errorMessage.get()); return new SubnetSelectionResult(errorMessage.get()); } LOGGER.debug("Azure selected subnets: '{}'", String.join(", ", subnetMetas.stream().toString())); return new SubnetSelectionResult(subnetMetas.stream().collect(Collectors.toList())); }  SubnetSelectionResult select(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters);  }### Answer:
@Test public void testSelectWhenNoSubnetsThenReturnsError() { List<CloudSubnet> subnets = new SubnetBuilder().build(); SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().build()); assertTrue(subnetSelectionResult.hasError()); assertEquals("Azure subnet selection: there are no subnets to choose from.", subnetSelectionResult.getErrorMessage()); }
@Test public void testSelectWhenSubnetmetasNullThenReturnsError() { SubnetSelectionResult subnetSelectionResult = underTest.select(null, SubnetSelectionParameters.builder().build()); assertTrue(subnetSelectionResult.hasError()); assertEquals("Azure subnet selection: there are no subnets to choose from.", subnetSelectionResult.getErrorMessage()); }
@Test public void testSelectWhenParametersNullThenReturnsError() { List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().build(); SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, null); assertTrue(subnetSelectionResult.hasError()); assertEquals("Azure subnet selection: parameters were not specified.", subnetSelectionResult.getErrorMessage()); }
@Test public void testselectWhenNotDatabaseOneSubnetThenReturnsIt() { List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().build(); SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().build()); assertEquals(1, subnetSelectionResult.getResult().size()); }
@Test public void testselectWhenNotDatabaseTwoSubnetsThenOneIsSelected() { List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().withPrivateSubnet().build(); SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().build()); assertEquals(2, subnetSelectionResult.getResult().size()); }
@Test public void testselectWhenDatabaseThreeSubnetsThenAllAreReturned() { List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().withPrivateSubnet().withPrivateSubnet().build(); SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters .builder() .withPreferPrivateIfExist() .build()); assertEquals(3, subnetSelectionResult.getResult().size()); List<String> selectedSubnetIds = subnetSelectionResult.getResult().stream().map(CloudSubnet::getId).collect(Collectors.toList()); assertThat(selectedSubnetIds, hasItem("subnet-1")); assertThat(selectedSubnetIds, hasItem("subnet-2")); assertThat(selectedSubnetIds, hasItem("subnet-3")); }