在hamcrest中(1.3.RC2,没有JUnit依赖项)我使用iterableWithSize().
失败
我有一个用Content
参数化的Iterator
的(扩展),如下所示EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*content*");
其中EndResult
为package org.springframework.data.neo4j.conversion;
public interface EndResult<R> extends Iterable<R> {...}
CCD_ 8是我的Pojo。
现在,我认为这会奏效assertThat(contents, iterableWithSize(1));
但它给了我一个错误:方法assertThat(T,Matcher)在类型中,Assert不适用对于论点(EndResult<Content>,Matcher<Iterable<Object>>)
我也尝试过这些失败:
assertThat(contents, iterableWithSize(equalTo(1));
assertThat(contents, IsIterableWithSize.<EndResult<Content>>.iterableWithSize(1));
这些是我的进口商品:
导入静态org.hamcrest.CoreMatchers.equalTo;导入静态org.hamcrest.collection.IsCollectionWithSize.hasSize;导入静态org.hamcrest.collection.IsIterableWithSize.iterableWithSize;导入静态org.unit.Assert.assertEquals;导入静态org.unit.Assert.assertThat;import org.hamcrest.coollection.IsInterableWithSize;
集合的hasSize按预期工作,但对于迭代器,我甚至找不到一个工作示例。。。
它应该只是
assertThat(contents, IsIterableWithSize.<Content>iterableWithSize(1));
iterableWithSize
是在Iterable
的组件类型上键入的,而不是迭代本身的具体类型。