@Test
public void testExecuteScheduledAlerts_ClearNotificationWithRefocusNotifier() {

    UserService userService = system.getServiceFactory().getUserService();
    final AtomicInteger notificationCount = new AtomicInteger(0);
    final AtomicInteger clearCount = new AtomicInteger(0);
    Metric metric = new Metric("scope", "metric");
    Map<Long, String> dps = new HashMap<Long, String>();
    dps.put(4000L, "11");
    dps.put(5000L, "20");
    dps.put(6000L, "30");
    metric.setDatapoints(_convertDatapoints(dps));
    Alert alert = new Alert(userService.findAdminUser(), userService.findAdminUser(), "testAlert", "-1h:scope:metric:avg", "* * * * *");
    _setAlertId(alert, "100001");
    Trigger trigger = new Trigger(alert, TriggerType.GREATER_THAN_OR_EQ, "testTrigger", 10, 0);
    _setTriggerId(trigger, "100002");
    Notification notification = new Notification("testNotification", alert, RefocusNotifier.class.getName(), new ArrayList<String>(), 0);
    _setNotificationId(notification, "100003");
    alert.setTriggers(Arrays.asList(new Trigger[] { trigger }));
    alert.setNotifications(Arrays.asList(new Notification[] { notification }));
    notification.setTriggers(alert.getTriggers());
    alert.setEnabled(true);
    DefaultAlertService spyAlertService = _initializeSpyAlertServiceWithStubs(notificationCount, clearCount,
            Arrays.asList(metric), alert, notification, false);
    assertEquals(new Integer(1), spyAlertService.executeScheduledAlerts(10, 1000));
    assertEquals(1, notificationCount.get());
    assertEquals(false, notification.isActiveForTriggerAndMetric(trigger, metric)); // refocus notification is stateless
    notificationCount.set(0);
    clearCount.set(0);
    dps = new HashMap<Long, String>();
    dps.put(4000L, "1");
    dps.put(5000L, "2");
    dps.put(6000L, "3");
    metric.setDatapoints(_convertDatapoints(dps));
    spyAlertService = _initializeSpyAlertServiceWithStubs(notificationCount, clearCount, Arrays.asList(metric),
            alert, notification, false);
    spyAlertService.executeScheduledAlerts(10, 1000);
    assertEquals(0, notificationCount.get());
    assertEquals(1, clearCount.get());
    assertEquals(false, notification.isActiveForTriggerAndMetric(trigger, metric)); // refocus notification is stateless
}