### Question:
ExploratoryServiceImpl implements ExploratoryService { @Override public Optional<UserInstanceDTO> getUserInstance(String user, String project, String exploratoryName) { try { return Optional.of(exploratoryDAO.fetchExploratoryFields(user, project, exploratoryName)); } catch (DlabException e) { log.warn("User instance with exploratory {}, project {} for user {} not found.", exploratoryName, project, user); } return Optional.empty(); }  @BudgetLimited @Override String start(UserInfo userInfo, String exploratoryName, @Project String project); @Override String stop(UserInfo userInfo, String project, String exploratoryName); @Override String terminate(UserInfo userInfo, String project, String exploratoryName); @BudgetLimited @Override String create(UserInfo userInfo, Exploratory exploratory, @Project String project); @Override void updateProjectExploratoryStatuses(String project, String endpoint, UserInstanceStatus status); @Override void updateClusterConfig(UserInfo userInfo, String project, String exploratoryName, List<ClusterConfig> config); @Override Optional<UserInstanceDTO> getUserInstance(String user, String project, String exploratoryName); @Override Optional<UserInstanceDTO> getUserInstance(String user, String project, String exploratoryName, boolean includeCompResources); @Override List<UserInstanceDTO> findAll(); @Override List<UserInstanceDTO> findAll(Set<ProjectDTO> projects); @Override List<ClusterConfig> getClusterConfig(UserInfo user, String project, String exploratoryName); @Override ExploratoryCreatePopUp getUserInstances(UserInfo user);  }### Answer:
@Test public void getUserInstance() { when(exploratoryDAO.fetchExploratoryFields(anyString(), anyString(), anyString())).thenReturn(userInstance); Optional<UserInstanceDTO> expectedInstance = Optional.of(userInstance); Optional<UserInstanceDTO> actualInstance = exploratoryService.getUserInstance(USER, PROJECT, EXPLORATORY_NAME); assertEquals(expectedInstance, actualInstance); verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME); verifyNoMoreInteractions(exploratoryDAO); }
@Test public void getUserInstanceWithException() { doThrow(new ResourceNotFoundException("Exploratory for user not found")) .when(exploratoryDAO).fetchExploratoryFields(anyString(), anyString(), anyString()); Optional<UserInstanceDTO> expectedInstance = Optional.empty(); Optional<UserInstanceDTO> actualInstance = exploratoryService.getUserInstance(USER, PROJECT, EXPLORATORY_NAME); assertEquals(expectedInstance, actualInstance); verify(exploratoryDAO).fetchExploratoryFields(USER, PROJECT, EXPLORATORY_NAME); verifyNoMoreInteractions(exploratoryDAO); }