@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()); } }
@Test public void canRetrieveMetadata() throws IOException, SQLException { File file = new File("whatever"); try { writeObjectsToFile(file); Cursor cursor = new FileCursor(file); try { CursorMetadata actual = cursor.getMetadata(); assertThat(actual.getColumnCount(), equalTo(2)); assertThat(actual.getColumnName(1), equalTo("A")); assertThat(actual.getColumnName(2), equalTo("B")); } finally { cursor.close(); } } finally { assertTrue(file.delete()); } }
private void iterateThrough(Cursor cursor) { while (cursor.next()) {} }