Method to test (Example):
public RepeatStatus execute1()
{
List<Employee> response = webclient.get().uri("/emplist")
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(new ParameterizedTypeReference<List<Employee>>()
{}).blockOptional().get();
return RepeatStatus.FINISHED;
}
How I tested in test class:
when(collectionsWebClient.get()).thenReturn(requestHeadersUriSpec);
when(requestHeadersUriSpec.uri(ArgumentMatchers.anystring())).thenReturn(requestHeadersSpec);
when (requestHeadersSpec.accept(MediaType.APPLICATION_JSON)).thenReturn(requestHeadersSpec) ;
when (requestHeadersSpec.header(ArgumentMatchers.any () , ArgumentMatchers .any())). thenReturn(requestHeadersSpec);
when (requestHeadersSpec.retrieve()).thenReturn(responseSpec) ;
when (responseSpec. bodyToMono(new Parameter izedTypeReference<List<AdvantageResponse>> () {
]). thenReturn (Mono. just (response))) ;
Here in the below line i'm getting null pointer exception not sure what i need to give in body to mono...what ever i give it is throwing null pointer.When i evaluate the expression in IDE it ia giving value while debugging