In hamcrest (1.3.RC2, without JUnit dependencies) I cannot use iterableWithSize () with the SpringDataNeo4j library.
I have a (extension) a Iterator
with a Content
parameter like this
EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*");
where EndResult
is
package org.springframework.data.neo4j.conversion; EndResult's open interface extends Iterable {...}
and Content
is a @NodeEntity
Pojo.
With the help of Mark Peters , I found out that I should call it that.
assertThat(contents, IsIterableWithSize.<Content>iterableWithSize(2));
, since iterableWithSize
is typed into the component type of your Iterable
, and not the specific type of the iterative itself.
But when the test runs, I get
java.lang.AssertionError: Expected: an iterable with size <2> got: org.springframework.data.neo4j.conversion.QueryResultBuilder$1@1 970ae0
Trying to figure out 1) I'm doing something wrong, or 2) hamcrest or 3) Spring Data Neo4j has an error, I checked my object at hand, and it seems OK as Iterable
public static int iterSize(Iterator iter){ int i=0; while (iter.hasNext()){ i++;iter.next();} return i; } public static int iterSize(Iterable iter) {return iterSize(iter.iterator());} assertEquals("contents contain 2 items", 2, iterSize(contents));
Therefore, I suppose that perhaps he concludes that he has a problem that has a problem. Has anyone tried something similar with IsIterableWithSize?
Verification Code https://github.com/anodynos/SpringDataNeo4jTrials/blob/master/src/test/java/sdnTests/test/HamcrestIteratorSizeTest.java