### Question:
ReaperConnection implements ReaperQuery { @Override public Collection<String> nextPage() throws CoreTokenException { if (Thread.currentThread().isInterrupted()) { close(); return null; } if (failed) { throw new IllegalStateException(); } try { initConnection(); Collection<String> results = impl.nextPage(); endProcessing(results); return results; } catch (CoreTokenException e) { failed = true; close(); throw e; } } @Inject  ReaperConnection(@DataLayer(ConnectionType.CTS_REAPER) ConnectionFactory factory, ReaperImpl impl); @Override Collection<String> nextPage();  }### Answer:
@Test public void shouldRespondToInterrupt() throws CoreTokenException { Thread.currentThread().interrupt(); connection.nextPage(); verify(mockImpl, times(0)).nextPage(); }
@Test public void shouldOpenConnectionOnFirstCall() throws Exception { given(mockFactory.create()).willReturn(mockConnection); connection.nextPage(); verify(mockImpl).setConnection(eq(mockConnection)); }
@Test (expectedExceptions = IllegalStateException.class) public void shouldNotReturnFurtherPagesOnceFailed() throws Exception { given(mockFactory.create()).willReturn(mockConnection); given(mockImpl.nextPage()).willThrow(new CoreTokenException("")); try { connection.nextPage(); } catch (CoreTokenException e) {} connection.nextPage(); }