Merge branch '2.7.x' into 3.0.x

Closes gh-34044
This commit is contained in:
Andy Wilkinson
2023-02-01 17:32:39 +00:00
2 changed files with 38 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ public class ResetMocksTestExecutionListener extends AbstractTestExecutionListen
for (String name : names) {
BeanDefinition definition = beanFactory.getBeanDefinition(name);
if (definition.isSingleton() && instantiatedSingletons.contains(name)) {
Object bean = beanFactory.getSingleton(name);
Object bean = getBean(beanFactory, name);
if (reset.equals(MockReset.get(bean))) {
Mockito.reset(bean);
}
@@ -101,4 +101,13 @@ public class ResetMocksTestExecutionListener extends AbstractTestExecutionListen
}
}
private Object getBean(ConfigurableListableBeanFactory beanFactory, String name) {
try {
return beanFactory.getBean(name);
}
catch (Exception ex) {
return beanFactory.getSingleton(name);
}
}
}