AlertsUIServiceImpl implements AlertsUIService { @Override public Map<String, AlertsUIUserSettings> findAllAlertsUIUserSettings() throws RestException { Map<String, AlertsUIUserSettings> allAlertUserSettings = new HashMap<>(); try { Map<String, Optional<String>> alertUserSettingsStrings = userSettingsClient.findAll(ALERT_USER_SETTING_TYPE); for (Map.Entry<String, Optional<String>> entry: alertUserSettingsStrings.entrySet()) { Optional<String> alertUserSettings = entry.getValue(); if (alertUserSettings.isPresent()) { allAlertUserSettings.put(entry.getKey(), _mapper.get().readValue(alertUserSettings.get(), AlertsUIUserSettings.class)); } } } catch (IOException e) { throw new RestException(e); } return allAlertUserSettings; } @Autowired  AlertsUIServiceImpl(final KafkaService kafkaService,
                             final Environment environment,
                             final UserSettingsClient userSettingsClient); @Override void escalateAlerts(List<Map<String, Object>> alerts); @Override Optional<AlertsUIUserSettings> getAlertsUIUserSettings(); @Override Map<String, AlertsUIUserSettings> findAllAlertsUIUserSettings(); @Override void saveAlertsUIUserSettings(AlertsUIUserSettings alertsUIUserSettings); @Override boolean deleteAlertsUIUserSettings(String user); void setClock(Clock clock); static final String ALERT_USER_SETTING_TYPE; static ThreadLocal<ObjectMapper> _mapper; }
@Test public void findAllShouldProperlyReturnActiveProfiles() throws Exception { AlertsUIUserSettings alertsProfile1 = new AlertsUIUserSettings(); alertsProfile1.setUser(user1); AlertsUIUserSettings alertsProfile2 = new AlertsUIUserSettings(); alertsProfile2.setUser(user1); when(userSettingsClient.findAll(AlertsUIServiceImpl.ALERT_USER_SETTING_TYPE)) .thenReturn(new HashMap<String, Optional<String>>() {{ put(user1, Optional.of(user1AlertUserSettings)); put(user2, Optional.of(user2AlertUserSettings)); }}); AlertsUIUserSettings expectedAlertsUIUserSettings1 = new AlertsUIUserSettings(); expectedAlertsUIUserSettings1.setTableColumns(Collections.singletonList("user1_field")); AlertsUIUserSettings expectedAlertsUIUserSettings2 = new AlertsUIUserSettings(); expectedAlertsUIUserSettings2.setTableColumns(Collections.singletonList("user2_field")); Map<String, AlertsUIUserSettings> actualAlertsProfiles = alertsUIService.findAllAlertsUIUserSettings(); assertEquals(2, actualAlertsProfiles.size()); assertEquals(expectedAlertsUIUserSettings1, actualAlertsProfiles.get(user1)); assertEquals(expectedAlertsUIUserSettings2, actualAlertsProfiles.get(user2)); verify(userSettingsClient, times(1)).findAll(AlertsUIServiceImpl.ALERT_USER_SETTING_TYPE); verifyNoMoreInteractions(userSettingsClient); }