Disable ResetMocksTestExecutionListener on native

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

See gh-32195
pull/32196/head
Phillip Webb 2 years ago
parent ed42823bd2
commit e599a70425

@ -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);
}
}

Loading…
Cancel
Save