Disable ResetMocksTestExecutionListener on native

Add a guard for `ResetMocksTestExecutionListener` so that it is
not applied when running in a native image.

See gh-32195
This commit is contained in:
Phillip Webb 2022-08-30 13:59:02 -07:00
parent ed42823bd2
commit e599a70425
1 changed files with 3 additions and 2 deletions

View File

@ -27,6 +27,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.NativeDetector;
import org.springframework.core.Ordered;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.TestExecutionListener;
@ -53,14 +54,14 @@ public class ResetMocksTestExecutionListener extends AbstractTestExecutionListen
@Override
public void beforeTestMethod(TestContext testContext) throws Exception {
if (MOCKITO_IS_PRESENT) {
if (MOCKITO_IS_PRESENT && !NativeDetector.inNativeImage()) {
resetMocks(testContext.getApplicationContext(), MockReset.BEFORE);
}
}
@Override
public void afterTestMethod(TestContext testContext) throws Exception {
if (MOCKITO_IS_PRESENT) {
if (MOCKITO_IS_PRESENT && !NativeDetector.inNativeImage()) {
resetMocks(testContext.getApplicationContext(), MockReset.AFTER);
}
}