|
41 | 41 | import static java.util.Arrays.asList;
|
42 | 42 | import static org.hamcrest.CoreMatchers.equalTo;
|
43 | 43 | import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
|
| 44 | +import static org.junit.Assert.assertEquals; |
44 | 45 | import static org.junit.Assert.assertFalse;
|
45 | 46 | import static org.junit.Assert.assertNotNull;
|
46 | 47 | import static org.junit.Assert.assertNull;
|
|
49 | 50 | import static org.junit.Assert.fail;
|
50 | 51 | import static org.mockito.Mockito.doAnswer;
|
51 | 52 | import static org.mockito.Mockito.mock;
|
| 53 | +import static org.mockito.Mockito.verify; |
52 | 54 | import static org.neo4j.driver.v1.Records.column;
|
53 | 55 | import static org.neo4j.driver.v1.Values.ofString;
|
54 | 56 | import static org.neo4j.driver.v1.Values.value;
|
@@ -384,12 +386,77 @@ public void shouldNotPeekIntoTheFutureWhenResultIsEmpty()
|
384 | 386 | Record future = result.peek();
|
385 | 387 | }
|
386 | 388 |
|
| 389 | + @Test |
| 390 | + public void shouldNotifyResourcesHandlerWhenFetchedViaList() |
| 391 | + { |
| 392 | + SessionResourcesHandler resourcesHandler = mock( SessionResourcesHandler.class ); |
| 393 | + StatementResult result = createResult( 10, resourcesHandler ); |
| 394 | + |
| 395 | + List<Record> records = result.list(); |
| 396 | + assertEquals( 10, records.size() ); |
| 397 | + |
| 398 | + verify( resourcesHandler ).onResultConsumed(); |
| 399 | + } |
| 400 | + |
| 401 | + @Test |
| 402 | + public void shouldNotifyResourcesHandlerWhenFetchedViaSingle() |
| 403 | + { |
| 404 | + SessionResourcesHandler resourcesHandler = mock( SessionResourcesHandler.class ); |
| 405 | + StatementResult result = createResult( 1, resourcesHandler ); |
| 406 | + |
| 407 | + Record record = result.single(); |
| 408 | + assertEquals( "v1-1", record.get( "k1" ).asString() ); |
| 409 | + |
| 410 | + verify( resourcesHandler ).onResultConsumed(); |
| 411 | + } |
| 412 | + |
| 413 | + @Test |
| 414 | + public void shouldNotifyResourcesHandlerWhenFetchedViaIterator() |
| 415 | + { |
| 416 | + SessionResourcesHandler resourcesHandler = mock( SessionResourcesHandler.class ); |
| 417 | + StatementResult result = createResult( 1, resourcesHandler ); |
| 418 | + |
| 419 | + while ( result.hasNext() ) |
| 420 | + { |
| 421 | + assertNotNull( result.next() ); |
| 422 | + } |
| 423 | + |
| 424 | + verify( resourcesHandler ).onResultConsumed(); |
| 425 | + } |
| 426 | + |
| 427 | + @Test |
| 428 | + public void shouldNotifyResourcesHandlerWhenSummary() |
| 429 | + { |
| 430 | + SessionResourcesHandler resourcesHandler = mock( SessionResourcesHandler.class ); |
| 431 | + StatementResult result = createResult( 10, resourcesHandler ); |
| 432 | + |
| 433 | + assertNotNull( result.summary() ); |
| 434 | + |
| 435 | + verify( resourcesHandler ).onResultConsumed(); |
| 436 | + } |
| 437 | + |
| 438 | + @Test |
| 439 | + public void shouldNotifyResourcesHandlerWhenConsumed() |
| 440 | + { |
| 441 | + SessionResourcesHandler resourcesHandler = mock( SessionResourcesHandler.class ); |
| 442 | + StatementResult result = createResult( 5, resourcesHandler ); |
| 443 | + |
| 444 | + result.consume(); |
| 445 | + |
| 446 | + verify( resourcesHandler ).onResultConsumed(); |
| 447 | + } |
| 448 | + |
387 | 449 | private StatementResult createResult( int numberOfRecords )
|
| 450 | + { |
| 451 | + return createResult( numberOfRecords, SessionResourcesHandler.NO_OP ); |
| 452 | + } |
| 453 | + |
| 454 | + private StatementResult createResult( int numberOfRecords, SessionResourcesHandler resourcesHandler ) |
388 | 455 | {
|
389 | 456 | Connection connection = mock( Connection.class );
|
390 | 457 | String statement = "<unknown>";
|
391 | 458 |
|
392 |
| - final InternalStatementResult result = new InternalStatementResult( connection, SessionResourcesHandler.NO_OP, null, |
| 459 | + final InternalStatementResult result = new InternalStatementResult( connection, resourcesHandler, null, |
393 | 460 | new Statement( statement ) );
|
394 | 461 |
|
395 | 462 | // Each time the cursor calls `recieveOne`, we'll run one of these,
|
|
0 commit comments