-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: testIssues in the test moduleIssues in the test moduletype: regressionA bug that is also a regressionA bug that is also a regression
Milestone
Description
@SpringJUnitConfig
class MockBeanTests {
@MockitoBean
// @MockBean works
ContextRefreshedEventProcessor contextRefreshedEventProcessor;
@Test
void test() {
then(contextRefreshedEventProcessor).should().process(any(ContextRefreshedEvent.class));
}
@Configuration
static class Config {
@Bean
ContextRefreshedEventListener contextRefreshedEventListener(
ContextRefreshedEventProcessor contextRefreshedEventProcessor) {
return new ContextRefreshedEventListener(contextRefreshedEventProcessor);
}
}
static class ContextRefreshedEventListener {
private final ContextRefreshedEventProcessor contextRefreshedEventProcessor;
public ContextRefreshedEventListener(ContextRefreshedEventProcessor contextRefreshedEventProcessor) {
this.contextRefreshedEventProcessor = contextRefreshedEventProcessor;
}
@EventListener
public void onApplicationEvent(ContextRefreshedEvent event) {
contextRefreshedEventProcessor.process(event);
}
}
interface ContextRefreshedEventProcessor {
void process(ContextRefreshedEvent event);
}
}
The test fails with @MockitoBean
but works fine with Spring Boot's @MockBean
.
I think it's caused by @MockitoBean
resetting the mock before tests automatically.
Metadata
Metadata
Assignees
Labels
in: testIssues in the test moduleIssues in the test moduletype: regressionA bug that is also a regressionA bug that is also a regression