### Question:
CustomerServiceProxy { public Mono<Optional<GetCustomerResponse>> findCustomerById(String customerId) { Mono<ClientResponse> response = client .get() .uri(customerServiceUrl + "/customers/{customerId}", customerId) .exchange(); return response.flatMap(resp -> { switch (resp.statusCode()) { case OK: return resp.bodyToMono(GetCustomerResponse.class).map(Optional::of); case NOT_FOUND: Mono<Optional<GetCustomerResponse>> notFound = Mono.just(Optional.empty()); return notFound; default: return Mono.error(new UnknownProxyException("Unknown: " + resp.statusCode())); } }) .transformDeferred(TimeLimiterOperator.of(timeLimiter)) .transformDeferred(CircuitBreakerOperator.of(cb)) ; } CustomerServiceProxy(WebClient client, CircuitBreakerRegistry circuitBreakerRegistry, String customerServiceUrl, TimeLimiterRegistry timeLimiterRegistry); Mono<Optional<GetCustomerResponse>> findCustomerById(String customerId);  }### Answer:
@Test public void shouldCallCustomerService() throws JSONException { JSONObject json = new JSONObject(); json.put("customerId", 101); json.put("name", "Fred"); json.put("creditLimit", "12.34"); String expectedResponse = json.toString(); stubFor(get(urlEqualTo("/customers/101")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", "application/json") .withBody(expectedResponse))); GetCustomerResponse customer = customerServiceProxy.findCustomerById("101").block().get(); assertEquals(new Long(101L), customer.getCustomerId()); verify(getRequestedFor(urlMatching("/customers/101"))); }
@Test(expected = CallNotPermittedException.class) public void shouldTimeoutAndTripCircuitBreaker() { String expectedResponse = "{}"; stubFor(get(urlEqualTo("/customers/99")) .willReturn(aResponse() .withStatus(500) .withHeader("Content-Type", "application/json") .withBody(expectedResponse))); IntStream.range(0, 100).forEach(i -> { try { customerServiceProxy.findCustomerById("99").block(); } catch (CallNotPermittedException e) { throw e; } catch (UnknownProxyException e) { } } ); verify(getRequestedFor(urlMatching("/customers/99"))); }