gpt4 book ai didi

java - Hamcrest 泛型 hell #2 : iterableWithSize gives errror "is not applicable for the arguments"

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:51:24 24 4
gpt4 key购买 nike

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

我有一个(扩展)一个IteratorContent 参数化像这样 EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*content*");

哪里EndResultpackage org.springframework.data.neo4j.conversion; public interface EndResult<R> extends Iterable<R> {...}Content是我的 Pojo。

现在,我认为这会起作用 assertThat(contents, iterableWithSize(1));

但它给了我错误:方法 assertThat(T, Matcher)在类型 Assert 中不适用对于论点(EndResult , Matcher >)

我也尝试过这些失败:

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组件类型上键入的,而不是可迭代对象本身的具体类型。

关于java - Hamcrest 泛型 hell #2 : iterableWithSize gives errror "is not applicable for the arguments",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9707531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com