Dear neo4j community and developers

For the second time we stumbled about Iterables that are no Iterables
in Neo4j. IndexHits e.g. extends Iterator and Iterable and states in
its documentation that is not really an iterable but always returns
"this" in calls to iterator(). So far so good.

Now when using Spring Data Neo4j, the IndexHits is wrapped and hidden
behind ClosableIterable and IterableAdapter etc. The user has no idea
anymore that those IterableWrapper and ClosableIterable things he gets
back are no iterables at all - well the names tell him of course that
those things *are* Iterables. This leads to very, very strange
behaviour like this:

@Test
public void ouch() {
        Device d1 = new Device("d1").persist();
        Device d2 = new Device("d2").persist();

        ClosableIterable<Device> devices = deviceRepository().findAll();
        assertThat(devices, hasItems(d1));
        assertEquals(1, IteratorUtil.count(devices));
}

We add two devices to our DB, but the test clearly states that
findAll() only returns one (assertEquals(1,
IteratorUtil.count(devices))).
As an exercise for the reader: explain why this test misleads you....

Iterable should always return a valid iterator for every call to
iterator(). Implementing Iterable just to be able to use an iterator
in a for loop is evil..... >:-)


Best regards,
James
_______________________________________________
NOTICE: THIS MAILING LIST IS BEING SWITCHED TO GOOGLE GROUPS, please register 
and consider posting at https://groups.google.com/forum/#!forum/neo4j

Neo4j mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to