Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 参数匹配器的使用无效!需要0个匹配器,记录了1个_Java_Unit Testing_Junit_Mockito - Fatal编程技术网

Java 参数匹配器的使用无效!需要0个匹配器,记录了1个

Java 参数匹配器的使用无效!需要0个匹配器,记录了1个,java,unit-testing,junit,mockito,Java,Unit Testing,Junit,Mockito,虽然这个错误很有描述性,但我还是弄不懂。 对于线路: PowerMockito.when( mockStringMessageService.lookupString(Matchers.eq("XYZ"))) .thenReturn(Matchers.eq("XYZ")); 错误是: [junit] Invalid use of argument matchers! [junit] 0 matchers expected, 1 recor

虽然这个错误很有描述性,但我还是弄不懂。 对于线路:

    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个匹配器?

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

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

任何原因,为什么不使用匹配器?