I need to mock a service. i m getting null in ResponseEntity<?>
resp while mocking the class.
Method which need to mock:
public List<Expression> getExpression(String expressView, Localdate date) {
List<Expression> =new ArrayList<>();
Map<String, Object> uri = new HashMap<>();
UriComponenetsBuilder build =
UriComponentsBuilder.fromHttpUrl("someUrl" + "/" + expressView);
build.queryParam(someParameter, someParameter);
build.queryParam(someParameter, someParameter);
build.queryParam(someParameter, someParameter);
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
RestClient client = new RestClient(
build.build().encode.toUriString, HttpMethod.GET.Uri, header
);
ResponseEntity<?> resp = restC.SomeMethod(client);
if (resp = !null) {
//it goes to these line
}
}
In my mock method:
when(restC.SomeMethod(client)).thenReturn(resp);
So above method call a service get some data get the value of expressView and save as list. when i mocked the method when(restC.SomeMethod(client)).thenReturn(resp);
it hit the URL but the value i m getting as response resp
is null .
So here i m getting the resp
value as null
. I checked the URL(someUrl) in postman its returning the value.
How to mock the ResponseEntity<?>
?
Thanks.