### Question:
EsFilterResult implements FilterResult { @Override public String getPrevToken() { final int currentFrom = queryNode.has("from") ? queryNode.get("from").asInt() : 0; if (currentFrom > 0) { final int size = queryNode.get("size").asInt(); return "" + Math.max(currentFrom - size, 0); } return null; } EsFilterResult(JsonNode queryNode, JsonNode resultNode);  EsFilterResult(JsonNode queryNode, JsonNode resultNode, String idField); @Override List<String> getUriList(); @Override String getNextToken(); @Override String getPrevToken(); @Override int getTotal(); void findFacets(Facet facet, ObjectNode data); @Override List<Facet> getFacets(); final String idField; }### Answer:
@Test public void getPrevTokenReturnsNullWhenCurrentFromIsZero() { final ObjectNode queryNode = jsnO("from", jsn(0), "size", jsn(10)); final ObjectNode resultNode = jsnO("hits", jsnO("total", jsn(20))); final EsFilterResult instance = new EsFilterResult(queryNode, resultNode); final String prevToken = instance.getPrevToken(); assertThat(prevToken, is(nullValue())); }
@Test public void getPrevTokenReturnsNonNullWhenCurrentFromIsBiggerThatZero() { final ObjectNode queryNode = jsnO("from", jsn(10), "size", jsn(10)); final ObjectNode resultNode = jsnO("hits", jsnO("total", jsn(20))); final EsFilterResult instance = new EsFilterResult(queryNode, resultNode); final String prevToken = instance.getPrevToken(); assertThat(prevToken, is(notNullValue())); }
@Test public void getPrevTokenReturnsZeroWhenCurrentFromMinusSizeIsSmallerThanZero() { final ObjectNode queryNode = jsnO("from", jsn(10), "size", jsn(12)); final ObjectNode resultNode = jsnO("hits", jsnO("total", jsn(20))); final EsFilterResult instance = new EsFilterResult(queryNode, resultNode); final String prevToken = instance.getPrevToken(); assertThat(prevToken, is("0")); }