我正在尝试调用一个返回类型为void的真实的方法。我已经在我的bean上尝试了@mock和@spy,但是它仍然没有进入实际的类。
@Autowired private HelperV2 authValidationHelper;
@Override
public void postProcess(Event event) {
List<Error> errorList = new ArrayList<>();
authValidationHelper.validateOrderTotalAmount(event, errorList);
handleError(event, errorList);
}
}
测试用例
@Spy private HelperV2 authValidationHelper;
@Test
public void test_postProcess() {
BaseOrderEvent event =
ParserUtil.getObjectFromFile(
"events/createPaymentRequestWithShoppingCardOnly2.json", Event.class);
Mockito.doCallRealMethod()
.when(authValidationHelper)
.validateOrderTotalAmount(Mockito.any(), Mockito.any());
createOrderEventProcessor.postProcess(event);
}
1条答案
按热度按时间6g8kf2rb1#
如果要替换Spring上下文中的Bean,则需要
@MockBean
或@SpyBean