### Question:
CountingHealthMonitorStrategy extends AbstractHealthMonitorStrategy { @Override public synchronized void update(boolean isHealthy) { if (currentState == null) { adviseListeners(isHealthy); currentState = isHealthy; } else if (isHealthy != currentState) { if (++changesReceived >= requiredUpdateCount) { adviseListeners(isHealthy); currentState = isHealthy; changesReceived = 0; } } else { changesReceived = 0; } } CountingHealthMonitorStrategy(int requiredUpdateCount); @Override synchronized void update(boolean isHealthy);  }### Answer:
@Test public void testInitialUpdate() { CountingHealthMonitorStrategy sut = new CountingHealthMonitorStrategy(3); final boolean[] result = new boolean[1]; sut.registerListener(new HealthMonitorStrategyListener() { @Override public void onUpdate(boolean isHealthy) { result[0]= isHealthy; } }); sut.update(true); Assert.assertEquals(true, result[0]); }
@Test public void testUpdate() { CountingHealthMonitorStrategy sut = new CountingHealthMonitorStrategy(3); final boolean[] result = new boolean[1]; sut.registerListener(new HealthMonitorStrategyListener() { @Override public void onUpdate(boolean isHealthy) { result[0]= isHealthy; } }); sut.update(true); Assert.assertEquals(true, result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(false,result[0]); }
@Test public void testResetCount() { CountingHealthMonitorStrategy sut = new CountingHealthMonitorStrategy(3); final boolean[] result = new boolean[1]; sut.registerListener(new HealthMonitorStrategyListener() { @Override public void onUpdate(boolean isHealthy) { result[0]= isHealthy; } }); sut.update(true); Assert.assertEquals(true, result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(true); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(true,result[0]); sut.update(false); Assert.assertEquals(false,result[0]); }
@Test public void testUpdateAfterListenersAdvised() { CountingHealthMonitorStrategy sut = new CountingHealthMonitorStrategy(3); final boolean[] result = new boolean[1]; sut.registerListener(new HealthMonitorStrategyListener() { @Override public void onUpdate(boolean isHealthy) { result[0]= isHealthy; } }); sut.update(true); Assert.assertEquals(true, result[0]); sut.update(false); Assert.assertEquals(true, result[0]); sut.update(false); Assert.assertEquals(true, result[0]); sut.update(false); Assert.assertEquals(false, result[0]); sut.update(true); Assert.assertEquals(false, result[0]); }