### Question:
DistroXV1RequestToStackV4RequestConverter { public StackV4Request convert(DistroXV1Request source) { DetailedEnvironmentResponse environment = Optional.ofNullable(environmentClientService.getByName(source.getEnvironmentName())) .orElseThrow(() -> new BadRequestException("No environment name provided hence unable to obtain some important data")); if (environment != null && environment.getEnvironmentStatus() != EnvironmentStatus.AVAILABLE) { throw new BadRequestException(String.format("Environment state is %s instead of AVAILABLE", environment.getEnvironmentStatus())); } StackV4Request request = new StackV4Request(); SdxClusterResponse sdxClusterResponse = getSdxClusterResponse(environment); request.setName(source.getName()); request.setType(StackType.WORKLOAD); request.setCloudPlatform(getCloudPlatform(environment)); request.setEnvironmentCrn(environment.getCrn()); request.setAuthentication(getIfNotNull(environment.getAuthentication(), authenticationConverter::convert)); request.setImage(getIfNotNull(source.getImage(), imageConverter::convert)); request.setCluster(getIfNotNull(source, environment, clusterConverter::convert)); request.setInstanceGroups(getIfNotNull(source.getInstanceGroups(), igs -> instanceGroupConverter.convertTo(igs, environment))); request.setNetwork(getNetwork(source.getNetwork(), environment)); request.setAws(getIfNotNull(source.getAws(), stackParameterConverter::convert)); request.setAzure(getIfNotNull(source.getAzure(), stackParameterConverter::convert)); request.setGcp(getIfNotNull(source.getGcp(), stackParameterConverter::convert)); request.setYarn(getYarnProperties(source, environment)); request.setInputs(source.getInputs()); request.setTags(getIfNotNull(source.getTags(), this::getTags)); request.setPlacement(preparePlacement(environment)); request.setSharedService(sdxConverter.getSharedService(sdxClusterResponse)); request.setCustomDomain(null); request.setTimeToLive(source.getTimeToLive()); request.setTelemetry(getTelemetryRequest(source, environment, sdxClusterResponse)); request.setGatewayPort(source.getGatewayPort()); request.setExternalDatabase(getIfNotNull(source.getExternalDatabase(), databaseRequestConverter::convert)); return request; }  StackV4Request convert(DistroXV1Request source); StackV4Request convertAsTemplate(DistroXV1Request source); DistroXV1Request convert(StackV4Request source);  }### Answer:
@Test void convert() { when(environmentClientService.getByName(anyString())).thenReturn(createEnvironment()); when(networkConverter.convertToNetworkV4Request(any())).thenReturn(createNetworkV4Request()); when(databaseRequestConverter.convert(any(DistroXDatabaseRequest.class))).thenReturn(createDatabaseRequest()); DistroXV1Request source = new DistroXV1Request(); source.setEnvironmentName("envname"); DistroXDatabaseRequest databaseRequest = new DistroXDatabaseRequest(); databaseRequest.setAvailabilityType(DistroXDatabaseAvailabilityType.HA); source.setExternalDatabase(databaseRequest); StackV4Request convert = underTest.convert(source); assertThat(convert.getExternalDatabase()).isNotNull(); assertThat(convert.getExternalDatabase().getAvailabilityType()).isEqualTo(DatabaseAvailabilityType.HA); }
@Test void convertStackRequest() { when(databaseRequestConverter.convert(any(DatabaseRequest.class))).thenReturn(createDistroXDatabaseRequest()); StackV4Request source = new StackV4Request(); source.setName("stackname"); DatabaseRequest databaseRequest = new DatabaseRequest(); databaseRequest.setAvailabilityType(DatabaseAvailabilityType.HA); source.setExternalDatabase(databaseRequest); DistroXV1Request convert = underTest.convert(source); assertThat(convert.getExternalDatabase()).isNotNull(); assertThat(convert.getExternalDatabase().getAvailabilityType()).isEqualTo(DistroXDatabaseAvailabilityType.HA); }