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
Using the previous answers, I've updated this to use Java 8 Streams API:
@Inject
private ApplicationContext applicationContext;
@Before
public void resetMocks() {
ConfigurableListableBeanFactory beanFactory = ((AbstractApplicationContext) applicationContext).getBeanFactory();
Stream.of(applicationContext.getBeanDefinitionNames())
.map(n -> beanFactory.getSingleton(n))
// My ConfigurableListableBeanFactory isn't compiled for 1.8 so can't use method reference. If yours is, you can say
// .map(ConfigurableListableBeanFactory::getSingleton)
.filter(b -> Mockito.mockingDetails(b).isMock())
.forEach(Mockito::reset);
}