### Question:
SimpleHealthMonitor extends OnDemandMonitor { @Override public String getName() { return monitorName; } SimpleHealthMonitor(String monitorName, HealthAware component, MonitorRegistry registry, Status failState); @Override String getName(); @Override Status checkStatus();  }### Answer:
@Test public void testLoad() { TestingComponent component = new TestingComponent(); final MonitorRegistry registry = mock(MonitorRegistry.class); SimpleHealthMonitor monitor = new SimpleHealthMonitor("blah", component, registry, Status.FAIL); ArgumentCaptor<Monitor> captor = ArgumentCaptor.forClass(Monitor.class); verify(registry, times(1)).addMonitor(captor.capture()); assertSame(monitor, captor.getValue()); assertEquals("blah",monitor.getName()); component.healthy = false; assertEquals(Status.FAIL, monitor.getStatus()); component.healthy = true; assertEquals(Status.OK, monitor.getStatus()); component.healthy = false; assertEquals(Status.FAIL, monitor.getStatus()); }
@Test public void testFailState() { TestingComponent component = new TestingComponent(); final MonitorRegistry registry = mock(MonitorRegistry.class); SimpleHealthMonitor monitor = new SimpleHealthMonitor("blah", component, registry, Status.WARN); ArgumentCaptor<Monitor> captor = ArgumentCaptor.forClass(Monitor.class); verify(registry, times(1)).addMonitor(captor.capture()); assertSame(monitor, captor.getValue()); assertEquals("blah",monitor.getName()); component.healthy = false; assertEquals(Status.WARN, monitor.getStatus()); component.healthy = true; assertEquals(Status.OK, monitor.getStatus()); component.healthy = false; assertEquals(Status.WARN, monitor.getStatus()); }