File tree Expand file tree Collapse file tree 3 files changed +27
-16
lines changed
main/java/org/neo4j/driver
test/java/org/neo4j/driver/internal Expand file tree Collapse file tree 3 files changed +27
-16
lines changed Original file line number Diff line number Diff line change @@ -246,19 +246,22 @@ public Record single()
246246 public Record peek ()
247247 {
248248 assertOpen ();
249- Record nextRecord = recordBuffer .peek ();
250- if ( nextRecord != null )
251- {
252- return nextRecord ;
253- }
254- else if ( done )
255- {
256- return null ;
257- }
258- else
249+
250+ while ( true )
259251 {
260252 tryFetching ();
261- return peek ();
253+ Record nextRecord = recordBuffer .peek ();
254+ if ( nextRecord == null )
255+ {
256+ if ( done )
257+ {
258+ throw new NoSuchRecordException ( "Cannot peek past the last record" );
259+ }
260+ }
261+ else
262+ {
263+ return nextRecord ;
264+ }
262265 }
263266 }
264267
Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ public interface StatementResult extends Iterator<Record>
7070
7171 /**
7272 * Navigate to and retrieve the next {@link Record} in this result.
73+ *
74+ * @throws NoSuchRecordException if there is no record left in the stream
7375 * @return the next record
7476 */
7577 @ Override Record next ();
@@ -78,7 +80,7 @@ public interface StatementResult extends Iterator<Record>
7880 * Return the first record in the result, failing if there is not exactly
7981 * one record left in the stream
8082 *
81- * Calling this method exhausts the result, even when failing.
83+ * Calling this method always exhausts the result, even when failing.
8284 *
8385 * @return the first and only record in the stream
8486 * @throws NoSuchRecordException if there is not exactly one record left in the stream
@@ -88,7 +90,8 @@ public interface StatementResult extends Iterator<Record>
8890 /**
8991 * Investigate the next upcoming record without moving forward in the result.
9092 *
91- * @return the next record, or null if there is no next record
93+ * @throws NoSuchRecordException if there is no record left in the stream
94+ * @return the next record
9295 */
9396 Record peek ();
9497
Original file line number Diff line number Diff line change @@ -334,18 +334,23 @@ public void shouldPeekIntoTheFuture()
334334 result .next ();
335335
336336 // THEN
337- assertNull ( result .peek () );
337+ expectedException .expect ( NoSuchRecordException .class );
338+
339+ // WHEN
340+ result .peek ();
338341 }
339342
340343 @ Test
341344 public void shouldNotPeekIntoTheFutureWhenResultIsEmpty ()
342345 {
343346 // GIVEN
344347 StatementResult result = createResult ( 0 );
345- Record future = result .peek ();
348+
349+ // THEN
350+ expectedException .expect ( NoSuchRecordException .class );
346351
347352 // WHEN
348- assertNull ( future );
353+ Record future = result . peek ( );
349354 }
350355
351356 private StatementResult createResult ( int numberOfRecords )
You can’t perform that action at this time.
0 commit comments