### Question:
CloudResourceToResourceConverter extends AbstractConversionServiceAwareConverter<CloudResource, Resource> { @Override public Resource convert(CloudResource source) { Resource domainResource = new Resource(); domainResource.setResourceType(source.getType()); domainResource.setResourceName(source.getName()); domainResource.setResourceReference(source.getReference()); domainResource.setResourceStatus(source.getStatus()); domainResource.setInstanceGroup(source.getGroup()); domainResource.setInstanceId(source.getInstanceId()); Optional.ofNullable(source.getParameters().get(CloudResource.ATTRIBUTES)).ifPresent(attributes -> { try { Json attributesJson = new Json(attributes); domainResource.setAttributes(attributesJson); } catch (IllegalArgumentException e) { LOGGER.info("Failed to parse resource attributes. Attributes: [{}]", source.getStringParameter(CloudResource.ATTRIBUTES), e); throw new IllegalStateException("Cannot parse stored resource attributes"); } }); return domainResource; }  @Override Resource convert(CloudResource source);  }### Answer:
@Test void convertPartial() { Resource convertedResource = underTest.convert(CloudResource.builder() .type(ResourceType.AWS_ENCRYPTED_AMI) .status(CommonStatus.REQUESTED) .name("ami-01231h231") .params(Map.of()) .build()); assertEquals(ResourceType.AWS_ENCRYPTED_AMI, convertedResource.getResourceType()); assertEquals(CommonStatus.REQUESTED, convertedResource.getResourceStatus()); assertEquals("ami-01231h231", convertedResource.getResourceName()); assertNull(convertedResource.getResourceReference()); assertNull(convertedResource.getInstanceGroup()); assertNull(convertedResource.getInstanceId()); assertNull(convertedResource.getAttributes()); }
@Test void convert() throws JsonProcessingException { Map<String, Object> parameters = Map.of("key", "test"); Json attributes = new Json(parameters); Resource convertedResource = underTest.convert(CloudResource.builder() .type(ResourceType.AWS_ENCRYPTED_AMI) .status(CommonStatus.REQUESTED) .name("ami-01231h231") .group("group") .instanceId("id") .params(Map.of(CloudResource.ATTRIBUTES, Map.of("key", "test"))) .reference("ref") .build()); assertEquals(ResourceType.AWS_ENCRYPTED_AMI, convertedResource.getResourceType()); assertEquals(CommonStatus.REQUESTED, convertedResource.getResourceStatus()); assertEquals("ami-01231h231", convertedResource.getResourceName()); assertEquals("ref", convertedResource.getResourceReference()); assertEquals("group", convertedResource.getInstanceGroup()); assertEquals("id", convertedResource.getInstanceId()); assertEquals(attributes.getValue(), convertedResource.getAttributes().getValue()); }