From 36a408fb5ece70b260b6dcef8ac31d051d5c40d1 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Mon, 12 Aug 2024 09:51:06 -0600 Subject: [PATCH] Update Mocking of TestContext Recent Spring Framework changes to default to Mockito's STRICT stubbing mode requires that TestContext be mocked after the exection context has been fully instantiated Closes gh-15579 --- .../WithSecurityContextTestExecutionListenerTests.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/src/test/java/org/springframework/security/test/context/support/WithSecurityContextTestExecutionListenerTests.java b/test/src/test/java/org/springframework/security/test/context/support/WithSecurityContextTestExecutionListenerTests.java index 8f77d98b9b..7964e5b13a 100644 --- a/test/src/test/java/org/springframework/security/test/context/support/WithSecurityContextTestExecutionListenerTests.java +++ b/test/src/test/java/org/springframework/security/test/context/support/WithSecurityContextTestExecutionListenerTests.java @@ -20,11 +20,11 @@ import java.lang.reflect.Method; import java.util.function.Supplier; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; @@ -42,6 +42,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -56,11 +57,15 @@ public class WithSecurityContextTestExecutionListenerTests { @Autowired private ApplicationContext applicationContext; - @Mock private TestContext testContext; private WithSecurityContextTestExecutionListener listener = new WithSecurityContextTestExecutionListener(); + @BeforeEach + public void setup() { + this.testContext = mock(TestContext.class); + } + @AfterEach public void cleanup() { TestSecurityContextHolder.clearContext();