@Test public void test_RS_peeking_1() { ResultSetPeekable rs = makePeekable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); }
@Test public void test_RS_peeking_3() { // Expect that a rewindable result set will be peekable ResultSetPeekable rs = (ResultSetPeekable)makeRewindable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); }
@Test(expected=NoSuchElementException.class) public void test_RS_peeking_2() { ResultSetPeekable rs = makePeekable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); // Peeking beyond end of results throws an error rs.peek(); }
@Test(expected=NoSuchElementException.class) public void test_RS_peeking_4() { // Expect that a rewindable result set will be peekable ResultSetPeekable rs = (ResultSetPeekable) makeRewindable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); // Peeking beyond end of results throws an error rs.peek(); }
@Test(expected=IllegalStateException.class) public void test_RS_peeking_8() { // Peeking may fail if someone moves backwards in the result set // If we had moved past the first item this should be an error ResultSetRewindable inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local"))); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); assertNotNull(rs.next()); // Reset the inner result set independently inner.reset(); // Since we moved the underlying result set backwards and had moved somewhere we // are now in an illegal state rs.hasNext(); }