@Test
public void sortTest() {

    String query = "{\"query\" : { \"term\" : { \"name\" : \"Milano\" } }}";
    Action search = new Search.Builder(query)
            .addSort(Arrays.asList(sortByPopulationAsc, sortByPopulationDesc, sortByPopulation)).build();
    JsonParser parser = new JsonParser();
    JsonElement parsed = parser.parse(search.getData(new Gson()).toString());
    JsonObject obj = parsed.getAsJsonObject();
    JsonArray sort = obj.getAsJsonArray("sort");
    assertEquals(3, sort.size());
    // sort 0
    JsonObject test = sort.get(0).getAsJsonObject();
    assertTrue(test.has("population"));
    test = test.getAsJsonObject("population");
    assertTrue(test.has("order"));
    assertEquals("asc", test.get("order").getAsString());
    // sort 1
    test = sort.get(1).getAsJsonObject();
    assertTrue(test.has("population"));
    test = test.getAsJsonObject("population");
    assertTrue(test.has("order"));
    assertEquals("desc", test.get("order").getAsString());
    // sort 2
    test = sort.get(2).getAsJsonObject();
    assertTrue(test.has("population"));
    test = test.getAsJsonObject("population");
    assertFalse(test.has("order"));
    assertFalse(test.has("order"));
    AbstractAction srch = (AbstractAction) search;
    assertTrue(srch.getParameter(Parameters.TRACK_SCORES).size() == 0);
    search = new Search.Builder(query)
            .addSort(Arrays.asList(sortByPopulationAsc, sortByPopulationDesc, sortByPopulation))
            .enableTrackScores()
            .build();
    srch = (AbstractAction) search;
    assertTrue(srch.getParameter(Parameters.TRACK_SCORES).size() == 1);
    assertTrue((Boolean) srch.getParameter(Parameters.TRACK_SCORES).iterator().next());
}