### Question:
EnvironmentServiceImpl implements EnvironmentService { @Override public List<UserDTO> getUsers() { final Set<String> activeUsers = envDAO.fetchActiveEnvUsers(); log.trace("Active users: {}", activeUsers); final Set<String> notActiveUsers = envDAO.fetchUsersNotIn(activeUsers); log.trace("Not active users: {}", notActiveUsers); final Stream<UserDTO> activeUsersStream = activeUsers .stream() .map(u -> toUserDTO(u, ACTIVE)); final Stream<UserDTO> notActiveUsersStream = notActiveUsers .stream() .map(u -> toUserDTO(u, NOT_ACTIVE)); return Stream.concat(activeUsersStream, notActiveUsersStream) .collect(toList()); } @Inject  EnvironmentServiceImpl(EnvDAO envDAO, UserSettingsDAO settingsDAO, ExploratoryDAO exploratoryDAO,
								  ExploratoryService exploratoryService, ComputationalService computationalService,
								  SecurityService securityService, ProjectService projectService); @Override List<UserDTO> getUsers(); @Override List<UserResourceInfo> getAllEnv(UserInfo user); @Override void stopAll(); @Override void stopEnvironmentWithServiceAccount(String user); @Override void stopProjectEnvironment(String project); @ProjectAdmin @Override void stopExploratory(@User UserInfo userInfo, String user, @Project String project, String exploratoryName); @ProjectAdmin @Override void stopComputational(@User UserInfo userInfo, String user, @Project String project, String exploratoryName,
								  String computationalName); @ProjectAdmin @Override void terminateExploratory(@User UserInfo userInfo, String user, @Project String project, String exploratoryName); @ProjectAdmin @Override void terminateComputational(@User UserInfo userInfo, String user, @Project String project,
									   String exploratoryName, String computationalName);  }### Answer:
@Test public void getActiveUsers() { doReturn(Collections.singleton(USER)).when(envDAO).fetchActiveEnvUsers(); doReturn(Collections.singleton(USER + "2")).when(envDAO).fetchUsersNotIn(anySet()); when(userSettingsDAO.getAllowedBudget(anyString())).thenReturn(Optional.empty()); final List<UserDTO> activeUsers = environmentService.getUsers(); assertEquals(2, activeUsers.size()); assertEquals(USER, activeUsers.get(0).getName()); assertEquals(USER + "2", activeUsers.get(1).getName()); verify(userSettingsDAO).getAllowedBudget(USER); verify(userSettingsDAO).getAllowedBudget(USER + "2"); verify(envDAO).fetchActiveEnvUsers(); verify(envDAO).fetchUsersNotIn(Collections.singleton(USER)); verifyNoMoreInteractions(envDAO); }
@Test public void getActiveUsersWithException() { doThrow(new DlabException("Users not found")).when(envDAO).fetchActiveEnvUsers(); expectedException.expect(DlabException.class); expectedException.expectMessage("Users not found"); environmentService.getUsers(); }