Search in sources :

Example 1 with PrimitiveLongBaseIterator

use of org.neo4j.collection.primitive.PrimitiveLongCollections.PrimitiveLongBaseIterator in project neo4j by neo4j.

the class PrimitiveLongCollectionsTest method shouldNotContinueToCallNextOnHasNextFalse.

@Test
public void shouldNotContinueToCallNextOnHasNextFalse() throws Exception {
    // GIVEN
    AtomicLong count = new AtomicLong(2);
    PrimitiveLongIterator iterator = new PrimitiveLongBaseIterator() {

        @Override
        protected boolean fetchNext() {
            return count.decrementAndGet() >= 0 ? next(count.get()) : false;
        }
    };
    // WHEN/THEN
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(1L, iterator.next());
    assertTrue(iterator.hasNext());
    assertTrue(iterator.hasNext());
    assertEquals(0L, iterator.next());
    assertFalse(iterator.hasNext());
    assertFalse(iterator.hasNext());
    assertEquals(-1L, count.get());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) PrimitiveLongBaseIterator(org.neo4j.collection.primitive.PrimitiveLongCollections.PrimitiveLongBaseIterator) Test(org.junit.Test)

Aggregations

AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Test (org.junit.Test)1 PrimitiveLongBaseIterator (org.neo4j.collection.primitive.PrimitiveLongCollections.PrimitiveLongBaseIterator)1