加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-14 16:21:10 所属栏目:Java 来源:网络整理
导读:在hamcrest(1.3.RC2,没有JUnit依赖) 我没有使用iterableWithSize(). 我有一个(扩展)Iterator参数化了这样的内容 EndResult内容 contents = contentRepository.findAllByPropertyValue(“title”,“* content *”); EndResult在哪里 包org.springframework.da
在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的组件类型上键入的,而不是迭代本身的具体类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读