在 hamcrest(1.3.RC2,没有 JUnit 依赖项)中,我使用失败iterableWithSize().
我有一个像这样
Iterator
参数化的(扩展)Content
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。
现在,我认为这会起作用
assertThat(contents, iterableWithSize(1));
但它给了我错误: Assert 类型中的方法 assertThat(T, Matcher) 不适用于参数 (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.junit.Assert.assertEquals; 导入静态 org.junit.Assert.assertThat; 导入 org.hamcrest.collection.IsIterableWithSize;
集合的 hasSize 按预期工作,但对于迭代器,我什至找不到工作示例......