### Question:
AggregatingAlertProvider implements AlertProvider, AlertSourceAggregator, AlertNotifyReceiver, Consumer<Event<Alert>> { @Override public void alertsAvailable(int count) { LOG.debug("Alerts available: {}", count); this.availableAlertsExecutor.execute(() -> { final AtomicReference<DateTime> sinceTime = new AtomicReference<>(AggregatingAlertProvider.this.lastAlertsTime); Map<String, AlertSource> sources = snapshotAllSources(); combineAlerts(criteria().asServiceAccount(true).after(sinceTime.get()), sources).forEach(alert -> { LOG.debug("Alert {} received from {}", alert.getId(), alert.getSource()); notifyListeners(alert); if (alert.isActionable()) { notifyResponders(alert); } sinceTime.set(alert.getCreatedTime()); }); AggregatingAlertProvider.this.lastAlertsTime = sinceTime.get(); }); } AggregatingAlertProvider(); void setAvailableAlertsExecutor(Executor availableAlertsExecutor); @Override void accept(Event<Alert> event); @Override AlertCriteria criteria(); @Override ID resolve(Serializable value); @Override ID resolve(ID id, AlertSource source); @Override void addListener(AlertListener listener); @Override void addResponder(AlertResponder responder); @Override boolean addAlertSource(AlertSource src); @Override boolean removeAlertSource(AlertSource src); @Override boolean addAlertManager(AlertManager mgr); @Override boolean removeAlertManager(AlertManager mgr); @Override Optional<Alert> getAlert(ID id); Optional<Alert> getAlertAsServiceAccount(ID id); @Override Iterator<? extends Alert> getAlerts(AlertCriteria criteria); Iterator<? extends AlertSummary> getAlertsSummary(AlertCriteria criteria); @Override Iterator<? extends Alert> getAlertsAfter(DateTime time); @Override Iterator<? extends Alert> getAlertsModifiedAfter(DateTime time); @Override Iterator<? extends Alert> getAlertsBefore(DateTime time); @Override void respondTo(ID id, AlertResponder responder); @Override void alertsAvailable(int count); Optional<Alert> getAlert(Alert.ID id, AlertSource src, boolean asServiceAccount); Alert unwrapAlert(Alert proxy);  }### Answer:
@Test public void testAlertsAvailable() throws InterruptedException { TestAlert mgrAlert = new TestAlert(this.manager, true); TestAlert srcAlert = new TestAlert(this.source); CountDownLatch latch = new CountDownLatch(3); this.provider.addAlertSource(this.source); this.provider.addAlertManager(this.manager); when(this.source.getAlerts(any(AlertCriteria.class))).thenAnswer(iteratorAnswer(srcAlert)); when(this.manager.getAlerts(any(AlertCriteria.class))).thenAnswer(iteratorAnswer(mgrAlert)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { latch.countDown(); return null; } }).when(this.listener).alertChange(any(Alert.class)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { latch.countDown(); return null; } }).when(this.responder).alertChange(any(Alert.class), any(AlertResponse.class)); this.provider.alertsAvailable(2); latch.await(10, TimeUnit.SECONDS); verify(this.listener, times(2)).alertChange(any(Alert.class)); verify(this.responder, times(1)).alertChange(any(Alert.class), any(AlertResponse.class)); }