Skip to content

Commit e599a70

Browse files
committed
Disable ResetMocksTestExecutionListener on native
Add a guard for `ResetMocksTestExecutionListener` so that it is not applied when running in a native image. See gh-32195
1 parent ed42823 commit e599a70

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/mock/mockito/ResetMocksTestExecutionListener.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
2828
import org.springframework.context.ApplicationContext;
2929
import org.springframework.context.ConfigurableApplicationContext;
30+
import org.springframework.core.NativeDetector;
3031
import org.springframework.core.Ordered;
3132
import org.springframework.test.context.TestContext;
3233
import org.springframework.test.context.TestExecutionListener;
@@ -53,14 +54,14 @@ public int getOrder() {
5354

5455
@Override
5556
public void beforeTestMethod(TestContext testContext) throws Exception {
56-
if (MOCKITO_IS_PRESENT) {
57+
if (MOCKITO_IS_PRESENT && !NativeDetector.inNativeImage()) {
5758
resetMocks(testContext.getApplicationContext(), MockReset.BEFORE);
5859
}
5960
}
6061

6162
@Override
6263
public void afterTestMethod(TestContext testContext) throws Exception {
63-
if (MOCKITO_IS_PRESENT) {
64+
if (MOCKITO_IS_PRESENT && !NativeDetector.inNativeImage()) {
6465
resetMocks(testContext.getApplicationContext(), MockReset.AFTER);
6566
}
6667
}

0 commit comments

Comments
 (0)