@Test public void nextOnNonEmptyCursor_shouldReturnTrue() throws IOException, SQLException { File file = new File("whatever"); try { writeObjectsToFile(file); Cursor cursor = new FileCursor(file); try { assertTrue(cursor.next()); } finally { cursor.close(); } } finally { assertTrue(file.delete()); } }
@Test public void afterReseting_nextReturnsTrue() throws IOException, SQLException { File file = new File("whatever"); try { writeObjectsToFile(file); Cursor cursor = new FileCursor(file); try { iterateThrough(cursor); cursor.reset(); assertTrue(cursor.next()); } finally { cursor.close(); } } finally { assertTrue(file.delete()); } }
@Test public void testGetObject() throws IOException, SQLException { File file = new File("whatever"); try { writeObjectsToFile(file); Cursor cursor = new FileCursor(file); try { cursor.next(); assertEquals("1", cursor.getObject(1)); assertEquals("2", cursor.getObject(2)); } finally { cursor.close(); } } finally { assertTrue(file.delete()); } }
private void iterateThrough(Cursor cursor) { while (cursor.next()) {} }