6

hamcrest (1.3.RC2、JUnit 依存関係なし) で使用に失敗していますiterableWithSize().

私はこのよう にIteratorパラメータ化された(の拡張)を持っていますContentEndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*content*");

私のPojoはどこにEndResultあり package org.springframework.data.neo4j.conversion; public interface EndResult<R> extends Iterable<R> {...} ますか。Content

今、私はこれがうまくいくと思うでしょう 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));

これらは私の輸入品です:

    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 は期待どおりに機能しますが、イテレータの場合は実際の例を見つけることさえできません...

4

1 に答える 1

13

それはちょうどあるはずです

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

iterableWithSizeiterable自体の具象型ではなく、あなたのコンポーネント型に型付けされます。Iterable

于 2012-03-14T18:27:54.920 に答える