### Question:
PagingQueryResponseHandler extends QueryResponseHandler { @Override public boolean handleResource(ResourceResponse resource) { boolean needMore = currentOffset < endOffset - 1; if (currentOffset >= startOffset && currentOffset < endOffset) { needMore = delegate.handleResource(resource) && needMore; } currentOffset++; return needMore; } PagingQueryResponseHandler(final QueryResponseHandler delegate, final int pageSize,
            final int pageOffset); @Override boolean handleResource(ResourceResponse resource);  }### Answer:
@Test public void shouldOnlyReadUntilPageIsRead() { testHandler = new PagingQueryResponseHandler(mockHandler, 2, 0); given(mockHandler.handleResource(Matchers.any(ResourceResponse.class))).willReturn(true); boolean firstHandle = testHandler.handleResource(newResourceResponse("a", null, null)); boolean secondHandle = testHandler.handleResource(newResourceResponse("b", null, null)); assertThat(firstHandle).isTrue(); assertThat(secondHandle).isFalse(); }
@Test public void shouldRespectOffset() { testHandler = new PagingQueryResponseHandler(mockHandler, 1, 1); ResourceResponse expectedResource = newResourceResponse("b", null, null); testHandler.handleResource(newResourceResponse("ignored", null, null)); testHandler.handleResource(expectedResource); verify(mockHandler).handleResource(expectedResource); verifyNoMoreInteractions(mockHandler); }
@Test public void shouldIgnoreExtraResources() { testHandler = new PagingQueryResponseHandler(mockHandler, 1, 0); given(mockHandler.handleResource(Matchers.any(ResourceResponse.class))).willReturn(true); ResourceResponse expected = newResourceResponse("expected", null, null); testHandler.handleResource(expected); testHandler.handleResource(newResourceResponse("b", null, null)); verify(mockHandler).handleResource(expected); verifyNoMoreInteractions(mockHandler); }