私はGroovy(およびJMockも同様)を初めて使用し、モックされているメソッドのパラメーターでマッチャーを使用する期待を構築するのに苦労しています。私がこのようなことをしようとすると:
Expectations e = new Expectations();
e.allowing(mockObject).doSomething(Expectations.with(aNonNull(ImmutableCollection.class)))
e.will(returnValue(someResponse))
期待値を構築するときに次のエラーが発生します。
groovy.lang.MissingMethodException: No signature of method: static org.jmock.Expectations.with() is applicable for argument types: (org.hamcrest.core.IsNot) values: [not null]
Possible solutions: with(boolean), with(org.hamcrest.Matcher), with(byte), with(org.hamcrest.Matcher), with(char), with(org.hamcrest.Matcher)
aNonNull が返さMatcher<T>
れ (org.hamcrest.core.IsNot implements Matcher<T>
)、Matcher を取る Expectations.with メソッドがあるため、Groovy が指定されたインターフェイスではなく具象クラスを取る with のバージョンを見つけようとしている理由がわかりません非ヌルによって。また、aNonNull の戻り値を両方の Matcher にキャストMatcher<T>
し、エラーを変更することも試みました。Groovy を混乱させるジェネリクスに関する何かがあるかどうか、または他に何を確認する必要があるかはわかりません。