@Test
  public void testAlertNoticeSkippedForTarget() throws Exception {
    AlertTargetEntity alertTarget = createMock(AlertTargetEntity.class);
    AlertGroupEntity alertGroup = createMock(AlertGroupEntity.class);
    List<AlertGroupEntity> groups = new ArrayList<>();
    Set<AlertTargetEntity> targets = new HashSet<>();

    targets.add(alertTarget);
    groups.add(alertGroup);

    EasyMock.expect(alertGroup.getAlertTargets()).andReturn(targets).once();
    EasyMock.expect(alertTarget.isEnabled()).andReturn(Boolean.TRUE).atLeastOnce();
    EasyMock.expect(alertTarget.getAlertStates()).andReturn(
        EnumSet.of(AlertState.OK, AlertState.CRITICAL)).atLeastOnce();

    EasyMock.expect(
        dispatchDao.findGroupsByDefinition(
            EasyMock.anyObject(AlertDefinitionEntity.class))).andReturn(
        groups).once();


    AlertDefinitionEntity definition = getMockAlertDefinition();

    AlertCurrentEntity current = getMockedAlertCurrentEntity();
    AlertHistoryEntity history = createNiceMock(AlertHistoryEntity.class);
    AlertStateChangeEvent event = createNiceMock(AlertStateChangeEvent.class);
    Alert alert = createNiceMock(Alert.class);

    EasyMock.expect(current.getAlertHistory()).andReturn(history).anyTimes();
    EasyMock.expect(current.getFirmness()).andReturn(AlertFirmness.HARD).atLeastOnce();

    // use WARNING to ensure that the target (which only cares about OK/CRIT)
    // does not receive the alert notice
    EasyMock.expect(history.getAlertState()).andReturn(AlertState.WARNING).atLeastOnce();
    EasyMock.expect(history.getAlertDefinition()).andReturn(definition).atLeastOnce();
    EasyMock.expect(alert.getText()).andReturn("The HDFS Foo Alert Is Not Good").atLeastOnce();
    EasyMock.expect(alert.getState()).andReturn(AlertState.WARNING).atLeastOnce();
    EasyMock.expect(event.getCurrentAlert()).andReturn(current).atLeastOnce();
    EasyMock.expect(event.getNewHistoricalEntry()).andReturn(history).atLeastOnce();
    EasyMock.expect(event.getAlert()).andReturn(alert).atLeastOnce();

    replayAll();
    eventPublisher.publish(event);
    verifyAll();
  }
Tests that an {@link AlertNoticeEntity} is not created for a target that
does not match the {@link AlertState} of the alert.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertStateChangedEventTest.java