我有一个调用事件发布者的方法,我想验证对该发布者的调用。public void submitRegistrationForm(String registrationKey, RegistrationFormSubmitDTO registrationFormSubmitDTO) {
applicationEventPublisher.publishEvent(new RegistrationCompletedEvent(this, targetCustomerRegistration));
}所以,我模拟了 applicationEventPublisher 类,并且我已经像这样验证了对它的调用:verify(applicationEventPublisher, times(1)).publishEvent(any(RegistrationCompletedEvent.class));但我被告知不要使用任何(),而是我需要构建具体实例。我如何验证以“this”为参数的方法。
1 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
您可以使用参数捕获器来捕获 RegistrationCompletedEvent 并对其断言...
ArgumentCaptor<RegistrationCompletedEvent > argument = ArgumentCaptor.forClass(RegistrationCompletedEvent .class);
verify(applicationEventPublisher).publishEvent(argument.capture());
assertEquals("whatever", argument.getValue().something());
添加回答
举报
0/150
提交
取消