微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – Hamcrest泛型地狱#2:iterableWithSize给出错误“不适用于参数”

在hamcrest(1.3.RC2,没有JUnit依赖)
我没有使用iterableWithSize().

我有一个(扩展)Iterator参数化了这样的内容
EndResult<内容> contents = contentRepository.findAllByPropertyValue(“title”,“* content *”); EndResult在哪里
包org.springframework.data.neo4j.conversion;
公共接口EndResult< R>扩展Iterable< R> {…}
内容是我的Pojo.

现在,我认为这会奏效
assertthat(contents,iterableWithSize(1));

但它给了我错误

方法断言(T,Matcher)
在Assert类型中不适用
对于论点
(EndResult< Content>,Matcher< Iterable< Object>>)

我也试过这些失败:

assertthat(contents,iterableWithSize(equalTo(1));

assertthat(contents,IsIterableWithSize.< EndResult< Content>> .iterableWithSize(1));

这些是我的进口:


    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;

集合的hasSize按预期工作,但对于迭代器我甚至找不到一个有效的例子……

解决方法

它应该是
assertthat(contents,IsIterableWithSize.<Content>iterableWithSize(1));

iterableWithSize是在Iterable的组件类型上键入的,而不是迭代本身的具体类型.

原文地址:https://www.jb51.cc/java/125661.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐