My rest endpoint looks like:
@GetMapping("/mango/{id}")
public Mono<Mango> getMango(@PathVariable("id") final String id){
validateId(id);
return serviceLayer.someMonoData();
}
My Junit looks like:
@Test
public void method(){
when(serviceLayer.someMonoData()).thenReturn(someResponse);
webTestClient.get()
.uri(ENDPOINT_URL)
.headers(headers)
.exchange()
.expectStatus()
.isBadRequest();
}
The validateId(id); method is supposed to throw custom bad request exception for an invalid id. This method is not reactive.
But the Junit seems to bypass the validate() method and proceeds with the service call stub..
What am i missing?
In reactive you need to construct the flow using reactive operators that will be executed when web flux subscribes to this flow. In you case validateId is not part of the flow.
Not sure what is the contract of the validateId() but, assuming it's not reactive, you can use
return Mono.fromRunnable(() -> validateId(id))
.then(serviceLayer.someMonoData());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With