0

I am creating a Spring WebClient and adding some personalized headers to the builder:

@Component
public class ApiClient {

    private final WebClient client;
    
    public Mono<Optional<String>> getApiInfo(final String header) {
        return client
                .get()
                .uri(URI)
                .headers(requestHeaders -> {
                    requestHeaders.add("Header_name", "Header_Value");
                    if (StringUtils.isNotBlank(forwardedHost)) {
                        requestHeaders.add("Second_header", header);
                    }
                })
                .retrieve()
                .
                .
                .
    }
}

How can I validate that headers were added by just using Mockito?

I mocked every builder step, but I can't perform any verify() on the headers() function.

user16217248
  • 3,119
  • 19
  • 19
  • 37
  • 1
    Does this answer your question? [Mockito verify that a specific lambda has been passed as an argument in mock's method](https://stackoverflow.com/questions/41462913/mockito-verify-that-a-specific-lambda-has-been-passed-as-an-argument-in-mocks-m) – Gastón Schabas May 18 '23 at 01:10
  • 1
    What do you mean by "I can't perform any verify() on the headers() function." I don't see any verify in your question, and you haven't explained what happens when you call it. – tgdavies May 18 '23 at 06:25
  • Thank you Gastón. You are right, that answered my question. – Milton Ortegon May 22 '23 at 00:13
  • This answers my question [https://stackoverflow.com/questions/41462913/mockito-verify-that-a-specific-lambda-has-been-passed-as-an-argument-in-mocks-m](https://stackoverflow.com/questions/41462913/mockito-verify-that-a-specific-lambda-has-been-passed-as-an-argument-in-mocks-m) – Milton Ortegon May 22 '23 at 00:15

0 Answers0