@Test
public void testGetTriggerFiredDatapointTime() {

    UserService userService = system.getServiceFactory().getUserService();
    Alert alert = new Alert(userService.findAdminUser(), userService.findAdminUser(), "alert-name_test", EXPRESSION, "* * * * *");
    Metric metric = new Metric("scope", "metric");
    double thresholdValue = 90;
    long inertia = 10;
    long startTime = 1;
    long expectedTriggerTime;
    Trigger trigger = new Trigger(alert, TriggerType.GREATER_THAN_OR_EQ, "name_test", thresholdValue, inertia);
    Map<Long, String> datapoints = new HashMap<Long, String>();
    datapoints.putAll(_createDatapoints(inertia + 1, thresholdValue, startTime, true));
    metric.setDatapoints(_convertDatapoints(datapoints));
    expectedTriggerTime = datapoints.size();
    long actualValue = alertService.getTriggerFiredDatapointTime(trigger, metric, alert.getExpression(), startTime);
    assertEquals(expectedTriggerTime, actualValue);
    startTime = datapoints.size() + 1;
    datapoints.putAll(_createDatapoints(201, thresholdValue, startTime, false));
    metric.setDatapoints(_convertDatapoints(datapoints));
    actualValue = alertService.getTriggerFiredDatapointTime(trigger, metric, alert.getExpression(), startTime);
    assertEquals(expectedTriggerTime, actualValue);
    startTime = datapoints.size() + 1;
    datapoints.putAll(_createDatapoints(inertia - 1, thresholdValue, startTime, true));
    metric.setDatapoints(_convertDatapoints(datapoints));
    actualValue = alertService.getTriggerFiredDatapointTime(trigger, metric, alert.getExpression(), startTime);
    assertEquals(expectedTriggerTime, actualValue);
    startTime = datapoints.size() + 1;
    datapoints.putAll(_createDatapoints(inertia + 1, thresholdValue, startTime, true));
    metric.setDatapoints(_convertDatapoints(datapoints));
    actualValue = alertService.getTriggerFiredDatapointTime(trigger, metric, alert.getExpression(), startTime);
    expectedTriggerTime = datapoints.size();
    assertEquals(expectedTriggerTime, actualValue);
    startTime = datapoints.size() + 1;
    datapoints.putAll(_createDatapoints(201, thresholdValue, startTime, false));
    metric.setDatapoints(_convertDatapoints(datapoints));
    actualValue = alertService.getTriggerFiredDatapointTime(trigger, metric, alert.getExpression(), startTime);
    assertEquals(expectedTriggerTime, actualValue);
}