I have several beans in my Spring context that have state, so I\'d like to reset that state before/after unit tests.
My idea was to add a method to a helper class wh
I had to improve it a little
@Resource
AbstractApplicationContext context;
@After
public void cleanup() {
resetAllMocks();
}
private void resetAllMocks() {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
for (String name : context.getBeanDefinitionNames()) {
Object bean = beanFactory.getSingleton(name);
if (Mockito.mockingDetails(bean).isMock()) {
Mockito.reset(bean);
}
}
}