From e599a704251e49fab8d3921fd31ffad73f090de4 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 30 Aug 2022 13:59:02 -0700 Subject: [PATCH] Disable ResetMocksTestExecutionListener on native Add a guard for `ResetMocksTestExecutionListener` so that it is not applied when running in a native image. See gh-32195 --- .../test/mock/mockito/ResetMocksTestExecutionListener.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java index 7a7f94cb7a..7737b33350 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java @@ -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); } }