### Question:
NetworkService { public BaseNetwork validate(BaseNetwork originalNetwork, EnvironmentEditDto editDto, Environment environment) { if (originalNetwork.getRegistrationType() == RegistrationType.CREATE_NEW) { throw new BadRequestException("Subnet could not be attached to this environment, because it is newly created by Cloudbreak. " + "You need to re-install the the environment into an existing VPC"); } EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(CloudPlatform.valueOf(environment.getCloudPlatform())); NetworkDto originalNetworkDto = environmentNetworkConverter.convertToDto(originalNetwork); NetworkDto cloneNetworkDto = NetworkDto.builder(originalNetworkDto) .withSubnetMetas(editDto.getNetworkDto().getSubnetMetas()) .build(); ValidationResultBuilder validationResultBuilder = networkCreationValidator.validateNetworkEdit(environment, cloneNetworkDto); ValidationResult validationResult = validationResultBuilder.build(); if (validationResult.hasError()) { throw new BadRequestException(validationResult.getFormattedErrors()); } return originalNetwork; } NetworkService(BaseNetworkRepository baseNetworkRepository,
            Map<CloudPlatform, EnvironmentNetworkConverter> environmentNetworkConverterMap, CloudNetworkService cloudNetworkService,
            EnvironmentNetworkService environmentNetworkService, NetworkCreationValidator networkCreationValidator); BaseNetwork saveNetwork(Environment environment, NetworkDto networkDto, String accountId, Map<String, CloudSubnet> subnetMetas); BaseNetwork validate(BaseNetwork originalNetwork, EnvironmentEditDto editDto, Environment environment); BaseNetwork refreshMetadataFromCloudProvider(BaseNetwork originalNetwork, EnvironmentEditDto editDto, Environment environment); @SuppressWarnings("unchecked") Optional<T> findByEnvironment(Long environmentId); @SuppressWarnings("unchecked") BaseNetwork save(BaseNetwork network);  }### Answer:
@Test public void testMergeNetworkDtoWithNetworkIfNetworkCreateNew() { AwsNetwork baseNetwork = new AwsNetwork(); baseNetwork.setSubnetMetas(Collections.emptyMap()); baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW); Environment environment = new Environment(); environment.setCloudPlatform("AWS"); environment.setNetwork(baseNetwork); NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build(); EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build(); when(environmentNetworkConverterMap.get(CloudPlatform.AWS)).thenReturn(environmentNetworkConverter); when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto); when(networkCreationValidator.validateNetworkEdit(eq(environment), any(NetworkDto.class))) .thenReturn(new ValidationResult.ValidationResultBuilder()); BadRequestException exception = Assertions.assertThrows(BadRequestException.class, () -> underTest.validate(baseNetwork, environmentEditDto, environment)); Assertions.assertEquals("Subnet could not be attached to this environment, because it is newly created by Cloudbreak. " + "You need to re-install the the environment into an existing VPC", exception.getMessage()); }