### Question:
FreeIpaConverter { public FreeIpaResponse convert(FreeIpaCreationDto freeIpaCreation) { if (freeIpaCreation == null) { return null; } else { FreeIpaResponse response = new FreeIpaResponse(); response.setInstanceCountByGroup(freeIpaCreation.getInstanceCountByGroup()); Optional.ofNullable(freeIpaCreation.getAws()) .map(this::convertAws) .ifPresent(response::setAws); return response; } }  FreeIpaResponse convert(FreeIpaCreationDto freeIpaCreation); FreeIpaCreationDto convert(AttachedFreeIpaRequest request);  }### Answer:
@Test public void testConvertWithNull() { FreeIpaCreationDto request = null; FreeIpaResponse result = underTest.convert(request); assertNull(result); }
@Test public void testConvertWithDefaults() { FreeIpaCreationDto request = FreeIpaCreationDto.builder().build(); FreeIpaResponse result = underTest.convert(request); assertNotNull(result); assertNotNull(result.getInstanceCountByGroup()); assertEquals(1, result.getInstanceCountByGroup()); assertNull(result.getAws()); }
@Test public void testConvertWithTwoInstancesAndOnlySpotInstances() { FreeIpaCreationDto request = FreeIpaCreationDto.builder() .withInstanceCountByGroup(2) .withAws(FreeIpaCreationAwsParametersDto.builder() .withSpot(FreeIpaCreationAwsSpotParametersDto.builder() .withPercentage(100) .withMaxPrice(0.9) .build()) .build()) .build(); FreeIpaResponse result = underTest.convert(request); assertNotNull(result); assertNotNull(result.getInstanceCountByGroup()); assertEquals(2, result.getInstanceCountByGroup()); assertEquals(100, result.getAws().getSpot().getPercentage()); assertEquals(0.9, result.getAws().getSpot().getMaxPrice()); }