瀏覽代碼

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
Josh Cummings 1 年之前
父節點
當前提交
36a408fb5e

+ 7 - 2
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();