I can't figure out why there is a different conversion to the List<String> sort
when passing 1 or 2 sort options as follows from the test using MockMvc
:
List<String> sort = Arrays.asList("firstName,desc")
//some other test set ups
...
MockHttpServletRequestBuilder requestBuilder = get(uri);
if (Objects.nonNull(sort)) {
requestBuilder.queryParam("sort", sort.stream().toArray(String[]::new));
}
ResultActions apiCall = mvc.perform(requestBuilder.accept(APPLICATION_JSON)
.header("Accept-Language", language));
...
When checking in the debug, I do have a single item array containing just ["firstName,desc"]
.
When checking the parameters in the controller:
//in a controller class
...
public ResponseEntity<Contact> getContacts(@Valid List<String> sort,... other args) {
...
the sort
list contains 2 items:
- firstName
- desc
If I pass in 2 sort options to the MockHttpServletRequestBuilder
like this:
List<String> sort = Arrays.asList("firstName,desc", "lastName,asc")
//some other test set ups
...
MockHttpServletRequestBuilder requestBuilder = get(uri);
if (Objects.nonNull(sort)) {
requestBuilder.queryParam("sort", sort.stream().toArray(String[]::new));
}
in this case on the controller side, I do have 2 items in the sort list containing the same values as defined in the test "firstName,desc"
, "lastName,asc"
.
Why so?