### Question:
ImageExploratoryServiceImpl implements ImageExploratoryService { @Override public ImageInfoRecord getImage(String user, String name, String project, String endpoint) { return imageExploratoryDao.getImage(user, name, project, endpoint).orElseThrow(() -> new ResourceNotFoundException(String.format(IMAGE_NOT_FOUND_MSG, name, user))); }  @Override String createImage(UserInfo user, String project, String exploratoryName, String imageName, String imageDescription); @Override void finishImageCreate(Image image, String exploratoryName, String newNotebookIp); @Override List<ImageInfoRecord> getNotFailedImages(String user, String dockerImage, String project, String endpoint); @Override ImageInfoRecord getImage(String user, String name, String project, String endpoint); @Override List<ImageInfoRecord> getImagesForProject(String project);  }### Answer:
@Test public void getImage() { ImageInfoRecord expectedImageInfoRecord = getImageInfoRecord(); when(imageExploratoryDao.getImage(anyString(), anyString(), anyString(), anyString())) .thenReturn(Optional.of(expectedImageInfoRecord)); ImageInfoRecord actualImageInfoRecord = imageExploratoryService.getImage(USER, "someName", "someProject", "someEndpoint"); assertNotNull(actualImageInfoRecord); assertEquals(expectedImageInfoRecord, actualImageInfoRecord); verify(imageExploratoryDao).getImage(USER, "someName", "someProject", "someEndpoint"); verifyNoMoreInteractions(imageExploratoryDao); }
@Test public void getImageWhenMethodGetImageReturnsOptionalEmpty() { when(imageExploratoryDao.getImage(anyString(), anyString(), anyString(), anyString())).thenReturn(Optional.empty()); expectedException.expect(ResourceNotFoundException.class); expectedException.expectMessage(String.format("Image with name %s was not found for user %s", "someImageName", USER)); imageExploratoryService.getImage(USER, "someImageName", "someProject", "someEndpoint"); }