CircuitBreaker { public boolean isClosed() { final Status currentStatus = this.updateAndGetStatus(); return currentStatus != Status.OPEN; } private  CircuitBreaker(final Builder builder); void openCircuit(); void closeCircuit(); boolean isClosed(); void markSuccess(); void markFailure();  }
@Test public void testInitiallyClosed() { LOGGER.info("Test: expect initial status is CLOSED"); assertThat(this.circuitBreaker.isClosed()).withFailMessage("Initial status should be CLOSED").isTrue(); }
@Test public void testOpenAfter2Failures() { LOGGER.info("Test: expect status is OPEN after two consecutive failures"); this.markTwoFailures(); assertThat(this.circuitBreaker.isClosed()).withFailMessage("Status should be OPEN after 2 failures").isFalse(); }
@Test public void testClosedAfter2FailuresAndWait() { LOGGER.info("Test: expect status is CLOSED after two failures and waiting longer than the initial duration"); this.markTwoFailures(); this.wait(35); assertThat(this.circuitBreaker.isClosed()).withFailMessage("Status should be CLOSED after waiting for 35 ms") .isTrue(); }