### Question:
ElasticSearchFilter implements CollectionFilter { protected ObjectNode elaborateQuery(String elasticSearchQuery, String fromValue, int preferredPageSize) throws IOException { try { ObjectNode node = (ObjectNode) mapper.readTree(elasticSearchQuery); node.put("size", preferredPageSize); if (fromValue != null && !fromValue.isEmpty()) { node.set("from", new IntNode(getFrom(fromValue))); } else { node.remove("from"); } ArrayNode sortNode = (ArrayNode) node.findValue("sort"); if (sortNode == null) { sortNode = node.putArray("sort"); } if (sortNode.findValue(UNIQUE_FIELD_NAME) == null) { ObjectNode objNode = JsonNodeFactory.instance.objectNode(); objNode.put(UNIQUE_FIELD_NAME, "desc"); sortNode.add(objNode); } return node; } catch (IOException e) { throw new IOException("Elasticsearch query is not a wellformed JSON document", e); } } @JsonCreator  ElasticSearchFilter(@JsonProperty("hostname") String hostname, @JsonProperty("port") int port,
                             @JsonProperty("username") Optional<String> username,
                             @JsonProperty("password") Optional<String> password); @Override EsFilterResult query(String dataSetId, String fieldName, String elasticSearchQuery, String token,
                              int preferredPageSize); @Override Tuple<Boolean, String> isHealthy(); static final String UNIQUE_FIELD_NAME; static final ObjectMapper OBJECT_MAPPER; static final Logger LOG; }### Answer:
@Test public void elaborateEmptyQuery() throws Exception { String query = "{}"; String expectedSort = "{\"" + ElasticSearchFilter.UNIQUE_FIELD_NAME + "\":\"desc\"}"; JsonNode node = eSearch.elaborateQuery(query, null, 5); JsonNode sizeNode = node.findValue("size"); assertThat(sizeNode.asInt(), equalTo(5)); assertThat(node.has("from"), equalTo(false)); JsonNode sortNode = node.findValue("sort"); assertThat(sortNode.elements().next().toString(), equalTo(expectedSort)); String expected = "{\"size\":5,\"sort\":[" + expectedSort + "]}"; assertThat(node.toString(), equalTo(expected)); expected = "{\"size\":6,\"from\":123,\"sort\":[" + expectedSort + "]}"; node = eSearch.elaborateQuery(query, "123", 6); sizeNode = node.findValue("size"); assertThat(sizeNode.asInt(), equalTo(6)); JsonNode from = node.findValue("from"); assertThat(from.asInt(), equalTo(123)); sortNode = node.findValue("sort"); assertThat(sortNode.elements().next().toString(), equalTo(expectedSort)); assertThat(node.toString(), equalTo(expected)); }