AutoCompleteController extends JsonExceptionHandlingController { @RequestMapping(value = "/json/suggestions", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") public String fetchTopSuggestions( @RequestParam(value = "query") String query, @RequestParam(value = "species", required = false, defaultValue = "") String species) { return GSON.toJson( suggesterService.fetchPropertiesWithHighlighting(query, species.split(",")).collect(toList())); } AutoCompleteController(SuggesterService suggesterService); @RequestMapping(value = "/json/suggestions", method = RequestMethod.GET, produces = "application/json;charset=UTF-8") String fetchTopSuggestions(
            @RequestParam(value = "query") String query,
            @RequestParam(value = "species", required = false, defaultValue = "") String species);  }
@Test public void fetchTopSuggestions() { Map<String, String> queryTerm1 = ImmutableMap.of("term", "Value1", "category", ""); Map<String, String> queryTerm2 = ImmutableMap.of("term", "Value2", "category", ""); when(suggesterServiceMock.fetchPropertiesWithHighlighting(QUERY_STRING, "Homo sapiens")) .thenReturn(Stream.of(queryTerm1, queryTerm2)); String jsonResponse = subject.fetchTopSuggestions(QUERY_STRING, HOMO_SAPIENS); ReadContext ctx = JsonPath.parse(jsonResponse); assertThat(ctx.<List<Map<String, String>>>read("$")).hasSize(2); assertThat(ctx.<List<Map<String, String>>>read("$")) .extracting("term", "category") .containsExactly( tuple("Value1", ""), tuple("Value2", "")); }