### Question:
EnvironmentNetworkService { public NetworkCidr getNetworkCidr(Network network, String cloudPlatform, Credential credential) { if (network == null) { LOGGER.info("Could not fetch network cidr from {}, because the network is null", cloudPlatform); return null; } NetworkConnector networkConnector = getNetworkConnector(cloudPlatform) .orElseThrow(() -> new BadRequestException("No network connector for cloud platform: " + cloudPlatform)); CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential); return networkConnector.getNetworkCidr(network, cloudCredential); } EnvironmentNetworkService(
            CloudPlatformConnectors cloudPlatformConnectors,
            NetworkCreationRequestFactory networkCreationRequestFactory,
            Map<CloudPlatform, EnvironmentNetworkConverter> environmentNetworkConverterMap,
            CredentialToCloudCredentialConverter credentialToCloudCredentialConverter); BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork); NetworkCidr getNetworkCidr(Network network, String cloudPlatform, Credential credential); void deleteNetwork(EnvironmentDto environment);  }### Answer:
@Test void testGetNetworkCidr() { Credential credential = mock(Credential.class); CloudCredential cloudCredential = mock(CloudCredential.class); Network network = mock(Network.class); String networkCidr = "10.0.0.0/16"; when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential); when(cloudConnector.networkConnector()).thenReturn(networkConnector); when(networkConnector.getNetworkCidr(network, cloudCredential)).thenReturn(new NetworkCidr(networkCidr)); NetworkCidr result = underTest.getNetworkCidr(network, "AWS", credential); assertEquals(networkCidr, result.getCidr()); }
@Test void testGetNetworkCidrWhenNetworkNull() { Credential credential = mock(Credential.class); NetworkCidr result = underTest.getNetworkCidr(null, "AWS", credential); assertNull(result); }
@Test void testGetNetworkCidrWhenNetworkConnectorNull() { Credential credential = mock(Credential.class); Network network = mock(Network.class); when(cloudConnector.networkConnector()).thenReturn(null); BadRequestException exception = assertThrows(BadRequestException.class, () -> underTest.getNetworkCidr(network, "AWS", credential)); assertEquals("No network connector for cloud platform: AWS", exception.getMessage()); }