### Question:
CloudResourceRetrieverService implements ResourceRetriever { @Override public Optional<CloudResource> findByResourceReferenceAndStatusAndType(String resourceReference, CommonStatus status, ResourceType resourceType) { Optional<Resource> optionalResource = resourceService.findByResourceReferenceAndStatusAndType(resourceReference, status, resourceType); LOGGER.debug("Resource retrieved by optionalResource reference: {}, status: {} and type: {}. Is present: {}", resourceReference, status, resourceType, optionalResource.isPresent()); return optionalResource .map(resource -> conversionService.convert(resource, CloudResource.class)); }  @Override Optional<CloudResource> findByResourceReferenceAndStatusAndType(String resourceReference, CommonStatus status, ResourceType resourceType);  }### Answer:
@Test public void testGetByResourceReferenceShouldReturnCloudResource() { Resource resource = createResource(); CloudResource cloudResource = createCloudResource(); when(resourceService.findByResourceReferenceAndStatusAndType(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE)).thenReturn(Optional.of(resource)); when(conversionService.convert(resource, CloudResource.class)).thenReturn(cloudResource); Optional<CloudResource> actual = underTest.findByResourceReferenceAndStatusAndType(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE); assertTrue(actual.isPresent()); assertEquals(cloudResource, actual.get()); verify(resourceService).findByResourceReferenceAndStatusAndType(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE); verify(conversionService).convert(resource, CloudResource.class); }
@Test public void testGetByResourceReferenceShouldReturnEmptyList() { when(resourceService.findByResourceReferenceAndStatusAndType(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE)).thenReturn(Optional.empty()); Optional<CloudResource> actual = underTest.findByResourceReferenceAndStatusAndType(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE); assertTrue(actual.isEmpty()); verify(resourceService).findByResourceReferenceAndStatusAndType(RESOURCE_REFERENCE, REQUESTED, AZURE_MANAGED_IMAGE); verifyNoInteractions(conversionService); }