Skip to content

MockReset strategy is no longer honored for @MockitoBean and @MockitoSpyBean #33941

@quaff

Description

@quaff
@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 moduletype: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions