我面临一个非常奇怪的问题.
- URL = "/my/specific/url/";
- when(this.restHelperMock.post(
- eq(myEnum),eq(this.config.apiEndpoint() + URL),any(JSONObject.class))).thenReturn(new JSONObject(myDesiredJsonContent));
甚至包含
- URL = "/my/specific/url/";
- when(this.restHelperMock.post(
- eq(myEnum),contains(this.config.apiEndpoint() + URL),any(JSONObject.class))).thenReturn(new JSONObject(myDesiredJsonContent));
给我
- 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.
即使我不使用RAW表达式.
奇怪的是,如果我将contains方法更改为:
- URL = "/my/specific/url/";
- when(this.restHelperMock.post(
- eq(myEnum),contains(URL),any(JSONObject.class))).thenReturn(new JSONObject(myDesiredJsonContent));
省略端点,它的工作原理.
Config和RestHelper都被嘲笑:
- this.restHelperMock = mock(RESTHelper.class);
- this.config = mock(MyBMWConfiguration.class);
- when(this.config.apiEndpoint()).thenReturn("http://host:port/api");
ApiEndpoint的URL等于我想要模拟的,
即使它不会,我应该得到一个NullpointerException,因为虚假的嘲弄.
但在这里,我没有任何想法.
谢谢您的回答.