2012-03-14 13 views
6

"引数には適用されません" AN EndResultpackage org.springframework.data.neo4j.conversion; public interface EndResult<R> extends Iterable<R> {...}Contentあるこの EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*content*");Hamcrestジェネリック地獄#2:iterableWithSizeはerrrorを与える(なしのJUnitの依存関係と、1.3.RC2)私は</p> <p><code>iterableWithSize().</code>は私が(の延長)を持って使用して失敗しています hamcrestで

のようなContentでパラメータ化Iteratorは私のPOJOです。タイプでアサートは、引数には適用 ない メソッドassertThat(T、マッチャー) :

今、私はこれは assertThat(contents, iterableWithSize(1));

を働くだろうと思うだろうが、それは私にエラーを与えます(EndResult <コンテンツ>、マッチャー<反復処理可能<オブジェクト>>)

私はまた、これらの障害を試してみました:

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は動作しますが、イテレータのために、私も作業例を見つける傾ける...

答えて

13

これはちょうどよいはずです

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

iterableWithSizeは、Iterableののコンポーネントタイプであり、具体的なiterableタイプではありません。

+0

おかげマーク - 確かに時間の[OK]をコンパイルしますが、テストが実行されたとき、私はにjava.lang.AssertionError取得: 予想:サイズ<2> で反復可能だ:

+0

@Agelos:あなたのコードとテストのどちらかを修正する方がいいでしょう。私はHamcrestの質問に答えていました。間違った前提があるか、コードが壊れています。申し訳ありませんが、私は新しい質問に答えるために春について十分に知りません。 –

+0

しかし、EndResult がIterable を拡張しているので、trivial {next(); i ++}コードで何が間違っている可能性がありますか? –

関連する問題

 関連する問題