Skip to content

Commit

Permalink
Disable ResetMocksTestExecutionListener on native
Browse files Browse the repository at this point in the history
Add a guard for `ResetMocksTestExecutionListener` so that it is
not applied when running in a native image.

See gh-32195
  • Loading branch information
philwebb committed Aug 31, 2022
1 parent ed42823 commit e599a70
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -53,14 +54,14 @@ public int getOrder() {

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

0 comments on commit e599a70

Please sign in to comment.