@Test
  public void testDigestDispatch() throws Exception {
    MockEmailDispatcher dispatcher = new MockEmailDispatcher();
    List<AlertNoticeEntity> notices = getSingleMockNotice(dispatcher.getType());
    AlertNoticeEntity notice = notices.get(0);

    EasyMock.expect(m_dao.findPendingNotices()).andReturn(notices).once();
    EasyMock.expect(m_dispatchFactory.getDispatcher("EMAIL")).andReturn(dispatcher).once();
    EasyMock.expect(m_dao.merge(notice)).andReturn(notice).atLeastOnce();

    EasyMock.replay(m_dao, m_dispatchFactory);

    // "startup" the service so that its initialization is done
    AlertNoticeDispatchService service = m_injector.getInstance(AlertNoticeDispatchService.class);
    service.startUp();

    // service trigger with mock executor that blocks
    service.setExecutor(new MockExecutor());
    service.runOneIteration();

    EasyMock.verify(m_dao, m_dispatchFactory);

    Notification notification = dispatcher.getNotification();
    assertNotNull(notification);

    assertTrue(notification.Subject.contains("OK[1]"));
    assertTrue(notification.Subject.contains("Critical[0]"));
    assertTrue(notification.Body.contains(ALERT_UNIQUE_TEXT));
  }
Tests a digest dispatch for email.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/state/services/AlertNoticeDispatchServiceTest.java