Merge branch '6.2.x'

This commit is contained in:
Sam Brannen
2024-11-26 11:58:44 +01:00
7 changed files with 220 additions and 6 deletions

View File

@@ -99,9 +99,10 @@ public enum MockReset {
}
/**
* Get the {@link MockReset} associated with the given mock.
* @param mock the source mock
* @return the reset type (never {@code null})
* Get the {@link MockReset} strategy associated with the given mock.
* @param mock the mock
* @return the reset strategy for the given mock, or {@link MockReset#NONE}
* if no strategy is associated with the given mock
*/
static MockReset get(Object mock) {
MockingDetails mockingDetails = Mockito.mockingDetails(mock);

View File

@@ -37,8 +37,18 @@ class MockitoBeans {
this.beans.add(bean);
}
void resetAll() {
this.beans.forEach(Mockito::reset);
/**
* Reset all Mockito beans configured with the supplied {@link MockReset} strategy.
* <p>No mocks will be reset if the supplied strategy is {@link MockReset#NONE}.
*/
void resetAll(MockReset reset) {
if (reset != MockReset.NONE) {
for (Object bean : this.beans) {
if (reset == MockReset.get(bean)) {
Mockito.reset(bean);
}
}
}
}
}

View File

@@ -116,7 +116,7 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList
}
}
try {
beanFactory.getBean(MockitoBeans.class).resetAll();
beanFactory.getBean(MockitoBeans.class).resetAll(reset);
}
catch (NoSuchBeanDefinitionException ex) {
// Continue