### Question:
NetworkToNetworkV4ResponseConverter extends AbstractConversionServiceAwareConverter<Stack, NetworkV4Response> { @Override public NetworkV4Response convert(Stack source) { NetworkV4Response networkResp = null; Network network = source.getNetwork(); if (network != null) { networkResp = new NetworkV4Response(); networkResp.setSubnetCIDR(network.getSubnetCIDR()); if (network.getAttributes() != null) { Map<String, Object> parameters = cleanMap(network.getAttributes().getMap()); putNetworkResourcesIntoResponse(source, parameters); providerParameterCalculator.parse(parameters, networkResp); } } return networkResp; }  @Override NetworkV4Response convert(Stack source);  }### Answer:
@Test public void testConvertShouldReturnNullWhenTheStackDoesNotHaveAssignedNetwork() { when(stack.getNetwork()).thenReturn(null); NetworkV4Response result = underTest.convert(stack); assertNull(result); }
@Test public void testConvertShouldReturnResponseWithSubnetCIDRWhenTheStackNetworkDoesNotContainAttributes() { when(network.getSubnetCIDR()).thenReturn(DEFAULT_CIDR); when(stack.getNetwork()).thenReturn(network); when(network.getAttributes()).thenReturn(null); NetworkV4Response result = underTest.convert(stack); assertNotNull(result); assertEquals(DEFAULT_CIDR, result.getSubnetCIDR()); }
@Test public void testConvertShouldRCallTheParserWhenTheStackStackDoesNotContainNetworkRelatedResources() throws JsonProcessingException { Resource gcpDisk = new Resource(); gcpDisk.setResourceType(ResourceType.GCP_DISK); gcpDisk.setResourceName("myproject-attachedworkerdisk"); when(stack.getResources()).thenReturn(Set.of(gcpDisk)); when(stack.getNetwork()).thenReturn(network); Map<String, Object> attributes = Map.of("cloudPlatform", "GCP"); when(network.getAttributes()).thenReturn(new Json(attributes)); when(network.getSubnetCIDR()).thenReturn(DEFAULT_CIDR); NetworkV4Response result = underTest.convert(stack); verify(providerParameterCalculator).parse(eq(attributes), any()); assertNotNull(result); assertEquals(DEFAULT_CIDR, result.getSubnetCIDR()); }
@Test public void testConvertShouldRCallTheParserWhenTheStackStackContainsNetworkRelatedResources() throws JsonProcessingException { Resource vpc = new Resource(); vpc.setResourceType(ResourceType.AWS_VPC); vpc.setResourceName("idOfTheCreatedVPC"); Resource subnet = new Resource(); subnet.setResourceType(ResourceType.AWS_SUBNET); subnet.setResourceName("idOfTheCreatedSubnet"); Resource azureNetwork = new Resource(); azureNetwork.setResourceType(ResourceType.AZURE_NETWORK); azureNetwork.setResourceName("idOfTheCreatedAzureNetwork"); when(stack.getResources()).thenReturn(Set.of(vpc, subnet, azureNetwork)); when(stack.getNetwork()).thenReturn(network); Map<String, Object> attributes = Map.of("cloudPlatform", "MOCK"); when(network.getAttributes()).thenReturn(new Json(attributes)); when(network.getSubnetCIDR()).thenReturn(DEFAULT_CIDR); NetworkV4Response result = underTest.convert(stack); Map<String, Object> expectedParameters = new HashMap<>(attributes); expectedParameters.put("vpcId", vpc.getResourceName()); expectedParameters.put("subnetId", subnet.getResourceName()); expectedParameters.put("networkId", azureNetwork.getResourceName()); verify(providerParameterCalculator).parse(eq(expectedParameters), any()); assertNotNull(result); assertEquals(DEFAULT_CIDR, result.getSubnetCIDR()); }