We're calling an external API that return a simple List, not DTO/Json, like ResponseEntity<List<String>>
In my tests I'm trying to mock the response using mockServer
but failed to return the result as List (just String as it not helped me):
mockServer.when(restTemplate.getForObject(any(), any()))
.respond(HttpResponse.response("{\"40\", \"50\"}")
.withStatusCode(200)
.withDelay(TimeUnit.SECONDS, 1));
String user = "user";
String password = "password";
RestTemplate restTemplate = new RestTemplate();
restTemplate.getInterceptors().add(new BasicAuthenticationInterceptor(user, password));
List<String> retList = restTemplate.getForObject(URI, List.class);
I tried with [
, ]
, {
, }
, none of them, double parenthesis but failed to return the response as List..
How can I do that correctly?
P.s. in the code all works well with the real API, response came as list as well. The issue is only in the tests, the error is:
"Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.List] and content type [application/octet-stream]"