0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

mockitoのverifyでany()と引数指定を混ぜて使いたい

Posted at

詰まった事象

verify(service).hogehoge(any(), any()); // OK
verify(service).hogehoge("fuga" , "piyo"); // OK
verify(service).hogehoge(any(), "piyo"); // NG

解決策

Matcherを使いましょう。

verify(service).hogehoge(any(), eq("piyo"));

実はエラーログに親切に書いてありました。

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"));
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?