@Test
public void testInitializeCache() {

    AlertDefinitionsCache cache = new AlertDefinitionsCache(alertService, false);
    AlertDefinitionsCacheRefresherThread refresherThread = new AlertDefinitionsCacheRefresherThread(cache, alertService);
    refresherThread.interrupt();
    Alert alert = TestUtils.generateAlert("alert-name", admin, EXPRESSION);
    Trigger trigger = TestUtils.generateTrigger("trigger-name", alert);
    Notification notification = TestUtils.generateNotification("notification-name", alert, Arrays.asList(new Trigger[]{trigger}));
    alert.setNotifications(Arrays.asList(new Notification[]{notification}));
    alert.setTriggers(Arrays.asList(new Trigger[]{trigger}));
    alert.setEnabled(true);
    Alert expectedAlert = alertService.updateAlert(alert);
    refresherThread.initializeAlertDefinitionsCache();
    Map<BigInteger, Alert> alertsMapById = cache.getAlertsMapById();
    assertEquals(1, alertsMapById.size());
    Alert actualAlert = (Alert) alertsMapById.values().toArray()[0];
    assertTrue(actualAlert.equals(expectedAlert));
    assertTrue(actualAlert.getTriggers().toArray()[0].equals(trigger));
    assertTrue(actualAlert.getNotifications().toArray()[0].equals(notification));
}