In hamcrest (1.3.RC2, with no JUnit dependencies)
I am failing using iterableWithSize().
I have an (extension of) an Iterator parametrized with Content like this
EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*content*");
where EndResult is
package org.springframework.data.neo4j.conversion;
public interface EndResult<R> extends Iterable<R> {...}
and Content is a my Pojo.
Now, I would think that this would work
assertThat(contents, iterableWithSize(1));
but it gives me the error : The method assertThat(T, Matcher) in the type Assert is not applicable for the arguments (EndResult< Content>, Matcher< Iterable< Object>>)
I also tried these failures :
assertThat(contents, iterableWithSize(equalTo(1));
assertThat(contents, IsIterableWithSize.<EndResult<Content>>.iterableWithSize(1));
These are my imports :
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsIterableWithSize.iterableWithSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.hamcrest.collection.IsIterableWithSize;
The hasSize for collections works as expected, but for iterators I cant even find a working example...
It should just be
assertThat(contents, IsIterableWithSize.<Content>iterableWithSize(1));
iterableWithSize is typed on the component type of your Iterable, not the concrete type of iterable itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With