I am trying to mock Spring WebClient and am having issues with the WebClient.builder() mocking. The mocks I've defined so far in my test are not being used, I think because this builder does not return my mock WebClient. How can I get the builder to return my mock?
WebClient webClient = WebClient.builder()
.exchangeStrategies(ExchangeStrategies.builder()
.codecs(configurer -> configurer
.defaultCodecs()
.maxInMemorySize(16 * 1024 * 1024))
.build())
.clientConnector(new ReactorClientHttpConnector(HttpClient.newConnection().compress(true)))
.build();
and the WebClient is used as so:
response = webClient
.get()
.uri(URLDecoder.decode(someEndpoint.replace("\"", ""), CLIENT_ENCODING))
.header(AUTHORIZATION, BEARER + accessToken)
.accept(MediaType.APPLICATION_JSON)
.retrieve().bodyToMono(JsonNode.class).block();
I do not see any problems with the mocks as I followed these solutions: How to mock Spring WebFlux WebClient? but the mocks are not being used. How can I mock the builder/return my mock from the builder?