私はこれをしたい:
when(myObject.getEntity(1l,usr.getUserName()).thenReturn(null);
when(myObject.getEntity(1l,Constants.ADMIN)).thenReturn(null);
マッチャーと一列に並んでいます。だから、私はこのコードを持っています:
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.AdditionalMatchers.*;
[...]
User usr = mock(usr);
[...]
when(myObject.getEntity(
eq(1l),
or(eq(usr.getUserName()),eq(Constants.ADMIN))
)
).thenReturn(null);
しかし、Or マッチャーを使用すると、JUnit が失敗します。
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
0 matchers expected, 1 recorded.
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
For more info see javadoc for Matchers class.
at blah.blah.MyTestClass.setup(MyTestClass:The line where I use the when & or matcher)
... more stacktrace ...
私が間違っていることは何ですか?
ありがとう!