参数匹配器的使用无效! 0匹配预期,1记录 [英] Invalid use of argument matchers! 0 matchers expected, 1 recorded

查看:253
本文介绍了参数匹配器的使用无效! 0匹配预期,1记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然错误是非常具有描述性的,但我无法理解它。
对于行:

Although the error is quite descriptive I could not get a hang of it. For lines:

    PowerMockito.when(
            mockStringMessageService.lookupString(Matchers.eq("XYZ")))
            .thenReturn(Matchers.eq("XYZ"));

错误是:

[junit] Invalid use of argument matchers!
[junit] 0 matchers expected, 1 recorded:
[junit] -> at com.amazon.kilvish.types.StatusTableTest.setUp(StatusTableTest.java:61)
[junit] 
[junit] This exception may occur if matchers are combined with raw values:
[junit]     //incorrect:
[junit]     someMethod(anyObject(), "raw String");
[junit] When using matchers, all arguments have to be provided by matchers.
[junit] For example:
[junit]     //correct:
[junit]     someMethod(anyObject(), eq("String by matcher"));
[junit] 
[junit] For more info see javadoc for Matchers class.

为什么预期有0个匹配器?

Why are 0 matchers expected?

推荐答案

您不能在 thenReturn 子句中使用匹配器。只需使用字符串文字:

You cannot use matchers in the thenReturn clause. Just use the string literal instead:

PowerMockito.when(
        mockStringMessageService.lookupString(Matchers.eq("XYZ")))
        .thenReturn("XYZ");

这篇关于参数匹配器的使用无效! 0匹配预期,1记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆