0

I need to mock the call to onStatus. The probelem is that I am getting the below error.

org.mockito.exceptions.misusing.PotentialStubbingProblem: Strict stubbing argument mismatch. Please check:

when(responseSpec.onStatus(HttpStatus::isError,(clientResponse) -> {
  if (clientResponse.statusCode() == HttpStatus.resolve(402)) {
    return Mono.error(new Exception("402"));
  }
  if (clientResponse.statusCode() == HttpStatus.resolve(500)) {
    return Mono.error(new Exception("500"));
  }
  if (clientResponse.statusCode() == HttpStatus.resolve(512)) {
    return Mono.error(new Exception("512")));
  }
  return Mono.error(new Exception("Error while processing request"));
}))
        .thenReturn(responseSpec);

}

Nesan Mano
  • 1,892
  • 2
  • 26
  • 43
  • 1
    `when` is used to setup calls on mocks/stubs. Mocks/stubs don't do anything, what's the point in passing in a complicated lambda? It will never be executed and lambdas are not compared based on their "logic". Perhaps you want to `when(responseSpec.onStatus(any(), any()).thenReturn(responseSpec)`? – knittl Jan 10 '23 at 19:16
  • Does this answer your question? [How to unit test the WebClient.onStatus() in java?](https://stackoverflow.com/questions/75114698/how-to-unit-test-the-webclient-onstatus-in-java) – Alex Jan 18 '23 at 00:10

0 Answers0