【发布时间】:2019-06-13 03:55:43
【问题描述】:
我正在尝试在 RestTemplate 响应中模拟一个字符串,但我在代码中遇到了错误。请提供意见。
错误:
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced argument matcher detected here:
You cannot use argument matchers outside of verification or stubbing.
Examples of correct usage of argument matchers:
when(mock.get(anyInt())).thenReturn(null);
doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject());
verify(mock).someMethod(contains("foo"))
Also, this error might show up because you use argument matchers with methods that cannot be mocked.
Following methods *cannot* be stubbed/verified: final/private/equals()/hashCode().
Mocking methods declared on non-public parent classes is not supported.
上述错误发生在这一行:
以下行代码错误:
when(this.userProfileClientRestTemplateProvider.currentUserProfileWithPermissionsRestTemplate()
.exchange(
any(RequestEntity.class),eq(String.class))) .thenReturn(mockResponseEntityFromFile("com/cnanational/dealerplanadmin/service/applyRuleSetsToDealer/user-permissions.json",
String.class, ResponseEntity.ok()));
【问题讨论】:
-
分享完整的课程和日志。
this.userProfileClientRestTemplateProvider.currentUserProfileWithPermissionsRestTemplate()这是模拟对象吗?
标签: java spring junit mockito resttemplate