How to write the Unit test cases for WebClient. I was trying to register the test case for refreshing the Data refreshData()
. While writing the test cases I am getting NullPointerException "this.WebClient" is null
@Autowired
WebClient.Builder webClient
List<HumanDto> hdata = new ArrayList<>();
public List<HumanDto> refreshData(){
List<HumanDto> hdata2 = getAllHuman();
if(!hdata.isEmpty()){
hdata.clear();
hdata.addAll(hdata2)
}
return hdata;
}
private List<HumanDto> getAllHuman(){
HumanLookup response = webClient.build().get.uri("https://user.asp/web").header("Authorization" , "Bearer" + token).retrieve().onStatus(HttpStatus::isError, clientResponse -> Mono.error(RunTimeException())).bodyToMono(new ParametrizedTypeReference<HumanLookup>(){}).block();
return response.getUserInfo();
}
At webClient.build only it shows a null pointer exception. How can I pass mocked webclient and return mocked result