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
This commit is contained in:
Josh Cummings 2024-08-12 09:51:06 -06:00
parent 59ec1f6480
commit 36a408fb5e
No known key found for this signature in database
GPG Key ID: A306A51F43B8E5A5
1 changed files with 7 additions and 2 deletions

View File

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