@Test
public void getDefaultHttpStatusCodeCircuitBreakerForKey_with_custom_scheduler_and_executor_service_creates_and_stores_instances() {

    // given
    String key = UUID.randomUUID().toString();
    ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
    ExecutorService scne = mock(ExecutorService.class);
    // when
    CircuitBreakerForHttpStatusCode cb =
        (CircuitBreakerForHttpStatusCode) CircuitBreakerForHttpStatusCode
            .getDefaultHttpStatusCodeCircuitBreakerForKey(key,
                                                          Optional.of(scheduler),
                                                          Optional.of(scne));
    // then
    assertThat(cb.scheduler).isSameAs(scheduler);
    assertThat(cb.stateChangeNotificationExecutor).isSameAs(scne);
    assertThat(cb.maxConsecutiveFailuresAllowed).isSameAs(cb.FALLBACK_DEFAULT_MAX_CONSECUTIVE_FAILURES_ALLOWED);
    assertThat(cb.resetTimeoutNanos).isEqualTo(Duration.ofSeconds(cb.DEFAULT_RESET_TIMEOUT_SECONDS).toNanos());
    assertThat(cb.callTimeoutNanos).isEqualTo(Optional.empty());
    assertThat(cb.id).isEqualTo("default-http-status-cb-for-" + key);
    assertThat(cb.breakingEventStrategy).isSameAs(cb.DEFAULT_HTTP_RESPONSE_BREAKING_EVENT_STRATEGY);
    assertThat(cb.breakingExceptionStrategy).isSameAs(cb.DEFAULT_BREAKING_EXCEPTION_STRATEGY);
    // and when
    CircuitBreaker<Integer> subsequentCallCb =
        CircuitBreakerForHttpStatusCode.getDefaultHttpStatusCodeCircuitBreakerForKey(key,
                                                                                     Optional.of(scheduler),
                                                                                     Optional.of(scne));
    // then
    assertThat(subsequentCallCb).isSameAs(cb);
    // and when
    CircuitBreakerForHttpStatusCode cbFromOtherMethod =
        (CircuitBreakerForHttpStatusCode) CircuitBreakerForHttpStatusCode
            .getDefaultHttpStatusCodeCircuitBreakerForKey(key);
    // then
    assertThat(cbFromOtherMethod).isSameAs(cb);
    // Since it was first created with custom scheduler and executor service it continues to stay that way
    assertThat(cbFromOtherMethod.scheduler).isSameAs(scheduler);
    assertThat(cbFromOtherMethod.stateChangeNotificationExecutor).isSameAs(scne);
}