CircuitBreakerDelegate implements CircuitBreaker<ET> { @Override public ET executeBlockingCall(Callable<ET> eventSupplier) throws Exception { final EventHolder<ET> origEventHolder = new EventHolder<>(); Callable<Del_ET> coreSupplier = () -> { ET origEvent = eventSupplier.call(); origEventHolder.event = origEvent; return eventConverter.apply(origEvent); }; delegate.executeBlockingCall(coreSupplier); return origEventHolder.event; } CircuitBreakerDelegate(CircuitBreaker<Del_ET> delegate, Function<ET, Del_ET> eventConverter); @Override ManualModeTask<ET> newManualModeTask(); @Override CompletableFuture<ET> executeAsyncCall(Supplier<CompletableFuture<ET>> eventFutureSupplier); @Override ET executeBlockingCall(Callable<ET> eventSupplier); @Override CircuitBreakerDelegate<ET, Del_ET> onClose(Runnable listener); @Override CircuitBreakerDelegate<ET, Del_ET> onHalfOpen(Runnable listener); @Override CircuitBreakerDelegate<ET, Del_ET> onOpen(Runnable listener); @Override String getId();  }
@Test public void executeBlockingCall_calls_delegate_with_callable_that_provides_converted_event_and_returns_the_original_event() throws Exception { CircuitBreaker<String> delegateCbSpy = spy(new CircuitBreakerImpl<>()); CircuitBreakerDelegate<Integer, String> wrapperCb = new CircuitBreakerDelegate<>(delegateCbSpy, eventConverter); int event = 42; Callable<Integer> wrapperSupplier = () -> event; Integer wrapperCallResult = wrapperCb.executeBlockingCall(wrapperSupplier); ArgumentCaptor<Callable> delegateCallArgumentCaptor = ArgumentCaptor.forClass(Callable.class); verify(delegateCbSpy).executeBlockingCall(delegateCallArgumentCaptor.capture()); Callable<String> delegateCallable = delegateCallArgumentCaptor.getValue(); assertThat(wrapperCallResult).isEqualTo(event); assertThat(delegateCallable.call()).isEqualTo(eventConverter.apply(event)); }