EndpointStatusDecorator { public void updateStatus(boolean success) { if (success) { counter.rise(); } else { counter.fall(); } if (previousStatus == null || previousStatus != counter.status()) { endpoint.setStatus(counter.status()); previousStatus = endpoint.getStatus(); } } EndpointStatusDecorator(Endpoint endpoint); void updateStatus(boolean success);  }
@Test public void testEndpointStatus_up() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus()); }
@Test public void testEndpointStatus_transitionallyDown() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(true); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); }
@Test public void testEndpointStatus_upAfterTransitionallyDown() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(true); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus()); }
@Test public void testEndpointStatus_upAfterTransitionallyDownAndFinallyDown() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus()); }
@Test public void testEndpointStatus_down() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(false); manager.updateStatus(false); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus()); }
@Test public void testEndpointStatus_downAfterTransitionallyUp() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(false); manager.updateStatus(false); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus()); }
@Test public void testEndpointStatus_downAfterTransitionallyUpAndFinallyUp() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); manager.updateStatus(false); manager.updateStatus(false); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus()); }
@Test public void testEndpointStatus_scenario() { Endpoint endpoint = createEndpoint(); EndpointStatusDecorator manager = new EndpointStatusDecorator(endpoint); Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.DOWN, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_UP, endpoint.getStatus()); manager.updateStatus(true); Assert.assertEquals(Endpoint.Status.UP, endpoint.getStatus()); manager.updateStatus(false); Assert.assertEquals(Endpoint.Status.TRANSITIONALLY_DOWN, endpoint.getStatus()); }