SelectResultSet extends AbstractResultSet { @Override public void next() { super.next(); this.current = jenaResult.next(); } SelectResultSet(QueryExecution execution, ResultSet jenaResult); @Override int findColumn(String variableName); @Override int getColumnCount(); @Override boolean isBound(int variableIndex); @Override boolean isBound(String variableName); @Override boolean getBoolean(int variableIndex); @Override boolean getBoolean(String variableName); @Override byte getByte(int variableIndex); @Override byte getByte(String variableName); @Override double getDouble(int variableIndex); @Override double getDouble(String variableName); @Override float getFloat(int variableIndex); @Override float getFloat(String variableName); @Override int getInt(int variableIndex); @Override int getInt(String variableName); @Override long getLong(int variableIndex); @Override long getLong(String variableName); @Override Object getObject(int variableIndex); @Override Object getObject(String variableName); @Override T getObject(int variableIndex, Class<T> cls); @Override T getObject(String variableName, Class<T> cls); @Override short getShort(int variableIndex); @Override short getShort(String variableName); @Override String getString(int variableIndex); @Override String getString(String variableName); @Override boolean hasNext(); @Override void next(); @Override void close();  }
@Test void nextThrowsNoSuchElementExceptionWhenNextIsCalledButNoMoreRowsAreAvailable() { model.add(SUBJECT, RDF.type, TYPE_ONE); this.selectResult = resultFor(QUERY); selectResult.next(); assertThrows(NoSuchElementException.class, () -> selectResult.next()); }
@Test void relativeMovesSpecifiedNumberOfRowsForward() { model.add(SUBJECT, RDF.type, TYPE_ONE); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); this.selectResult = resultFor(QUERY); selectResult.next(); assertEquals(0, selectResult.getRowIndex()); reset(resultSet); selectResult.relative(2); verify(resultSet, times(2)).next(); assertEquals(2, selectResult.getRowIndex()); }
@Test void relativeThrowsUnsupportedOperationForNegativeArgument() { model.add(SUBJECT, RDF.type, TYPE_ONE); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); this.selectResult = resultFor(QUERY); selectResult.next(); assertEquals(0, selectResult.getRowIndex()); final UnsupportedOperationException ex = assertThrows(UnsupportedOperationException.class, () -> selectResult.relative(-2)); assertThat(ex.getMessage(), containsString("Moving back is not supported by this result set.")); }
@Test void setRowIndexMovesToTargetRowIndex() { model.add(SUBJECT, RDF.type, TYPE_ONE); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); this.selectResult = resultFor(QUERY); selectResult.next(); assertEquals(0, selectResult.getRowIndex()); reset(resultSet); selectResult.setRowIndex(1); assertEquals(1, selectResult.getRowIndex()); verify(resultSet).next(); }
@Test void setRowIndexThrowsUnsupportedOperationForIndexLessThanCurrent() { model.add(SUBJECT, RDF.type, TYPE_ONE); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); this.selectResult = resultFor(QUERY); selectResult.next(); selectResult.next(); final UnsupportedOperationException ex = assertThrows(UnsupportedOperationException.class, () -> selectResult.setRowIndex(0)); assertThat(ex.getMessage(), containsString("Moving back is not supported by this result set.")); }
@Test void isFirstReturnsTrueForFirstRowInResult() { model.add(SUBJECT, RDF.type, TYPE_ONE); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); model.add(SUBJECT, RDF.type, createResource(Generator.generateUri().toString())); this.selectResult = resultFor(QUERY); assertFalse(selectResult.isFirst()); selectResult.next(); assertTrue(selectResult.isFirst()); selectResult.next(); assertFalse(selectResult.isFirst()); }