### Question:
ApplicationHealthMonitor implements ServiceAware { @Override public void setServices(Set<Service> services) { if (monitorInterval > 0) { startActiveMonitoring(monitorRegistry.getStatusAggregator()); } else { startPassiveMonitoring(monitorRegistry.getStatusAggregator()); } } ApplicationHealthMonitor(final ExecutionVenueNioServer nioServer,
                                    HealthMonitorStrategy strategy,
                                    long monitorInterval,
                                    MonitorRegistry monitorRegistry); @Override void setServices(Set<Service> services);  }### Answer:
@Test public void testActiveMonitoringOK() throws InterruptedException { final boolean[] result = new boolean[1]; AbstractHealthMonitorStrategy stategy = new AbstractHealthMonitorStrategy() { @Override public void update(boolean isHealthy) { result[0] = isHealthy; } }; ApplicationHealthMonitor sut = new ApplicationHealthMonitor(executionVenueNioServer, stategy, 50, monitorRegistry); sut.setServices(null); when(aggregator.getStatus()).thenReturn(Status.OK); Thread.sleep(100); Assert.assertEquals(true, result[0]); }
@Test public void testActiveMonitoringFAIL() throws InterruptedException { final boolean[] result = new boolean[1]; AbstractHealthMonitorStrategy stategy = new AbstractHealthMonitorStrategy() { @Override public void update(boolean isHealthy) { result[0] = isHealthy; } }; ApplicationHealthMonitor sut = new ApplicationHealthMonitor(executionVenueNioServer, stategy, 50, monitorRegistry); sut.setServices(null); when(aggregator.getStatus()).thenReturn(Status.FAIL); Thread.sleep(100); Assert.assertEquals(false, result[0]); }
@Test public void testActiveMonitoringWARN() throws InterruptedException { final boolean[] result = new boolean[1]; AbstractHealthMonitorStrategy stategy = new AbstractHealthMonitorStrategy() { @Override public void update(boolean isHealthy) { result[0] = isHealthy; } }; ApplicationHealthMonitor sut = new ApplicationHealthMonitor(executionVenueNioServer, stategy, 50, monitorRegistry); sut.setServices(null); when(aggregator.getStatus()).thenReturn(Status.WARN); Thread.sleep(100); Assert.assertEquals(true, result[0]); }
@Test public void testPassiveMonitoringUpdateFAIL() { final boolean[] result = new boolean[1]; AbstractHealthMonitorStrategy stategy = new AbstractHealthMonitorStrategy() { @Override public void update(boolean isHealthy) { result[0] = isHealthy; } }; ApplicationHealthMonitor sut = new ApplicationHealthMonitor(executionVenueNioServer, stategy, 0, monitorRegistry); sut.setServices(null); when(aggregator.getStatus()).thenReturn(Status.OK); Assert.assertEquals(true, result[0]); ArgumentCaptor<StatusChangeListener> captor = ArgumentCaptor.forClass(StatusChangeListener.class); verify(aggregator).addStatusChangeListener(captor.capture()); StatusChangeListener listener = captor.getValue(); listener.statusChanged(new StatusChangeEvent(statusSource, null, Status.FAIL)); Assert.assertEquals(false, result[0]); }
@Test public void testPassiveMonitoringUpdateWARN() { final boolean[] result = new boolean[1]; AbstractHealthMonitorStrategy stategy = new AbstractHealthMonitorStrategy() { @Override public void update(boolean isHealthy) { result[0] = isHealthy; } }; ApplicationHealthMonitor sut = new ApplicationHealthMonitor(executionVenueNioServer, stategy, 0, monitorRegistry); sut.setServices(null); when(aggregator.getStatus()).thenReturn(Status.OK); Assert.assertEquals(true, result[0]); ArgumentCaptor<StatusChangeListener> captor = ArgumentCaptor.forClass(StatusChangeListener.class); verify(aggregator).addStatusChangeListener(captor.capture()); StatusChangeListener listener = captor.getValue(); listener.statusChanged(new StatusChangeEvent(statusSource, null, Status.WARN)); Assert.assertEquals(true, result[0]); }