Skip to content

Commit d24dd71

Browse files
committed
Clean up @ExtendWith(SpringExtension.class)
1. Use `@SpringJunitConfig` or `@SpringJUnitWebConfig` instead where feasible 2. Remove it if `@SpringBootTest` present Signed-off-by: Yanming Zhou <[email protected]>
1 parent 34003cc commit d24dd71

File tree

58 files changed

+158
-405
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+158
-405
lines changed

spring-session-core/src/test/java/org/springframework/session/config/annotation/web/http/EnableSpringHttpSessionCustomCookieSerializerTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2019 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@
2525
import jakarta.servlet.http.HttpServletRequest;
2626
import org.junit.jupiter.api.BeforeEach;
2727
import org.junit.jupiter.api.Test;
28-
import org.junit.jupiter.api.extension.ExtendWith;
2928

3029
import org.springframework.beans.factory.annotation.Autowired;
3130
import org.springframework.context.annotation.Bean;
@@ -39,9 +38,7 @@
3938
import org.springframework.session.web.http.CookieSerializer;
4039
import org.springframework.session.web.http.CookieSerializer.CookieValue;
4140
import org.springframework.session.web.http.SessionRepositoryFilter;
42-
import org.springframework.test.context.ContextConfiguration;
43-
import org.springframework.test.context.junit.jupiter.SpringExtension;
44-
import org.springframework.test.context.web.WebAppConfiguration;
41+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
4542

4643
import static org.assertj.core.api.Assertions.assertThat;
4744
import static org.mockito.ArgumentMatchers.any;
@@ -57,9 +54,7 @@
5754
*
5855
* @author Rob Winch
5956
*/
60-
@ExtendWith(SpringExtension.class)
61-
@ContextConfiguration
62-
@WebAppConfiguration
57+
@SpringJUnitWebConfig
6358
class EnableSpringHttpSessionCustomCookieSerializerTests {
6459

6560
@Autowired

spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/AbstractITest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,22 +19,19 @@
1919
import java.util.UUID;
2020

2121
import org.junit.jupiter.api.BeforeEach;
22-
import org.junit.jupiter.api.extension.ExtendWith;
2322

2423
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
2524
import org.springframework.security.core.authority.AuthorityUtils;
2625
import org.springframework.security.core.context.SecurityContext;
2726
import org.springframework.security.core.context.SecurityContextHolder;
28-
import org.springframework.test.context.junit.jupiter.SpringExtension;
29-
import org.springframework.test.context.web.WebAppConfiguration;
27+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
3028

3129
/**
3230
* Base class for repositories integration tests
3331
*
3432
* @author Jakub Kubrynski
3533
*/
36-
@ExtendWith(SpringExtension.class)
37-
@WebAppConfiguration
34+
@SpringJUnitWebConfig
3835
public abstract class AbstractITest {
3936

4037
protected SecurityContext context;

spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbDeleteJacksonSessionVerificationTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import org.assertj.core.api.AssertionsForClassTypes;
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.extension.ExtendWith;
2726
import org.testcontainers.containers.MongoDBContainer;
2827
import reactor.test.StepVerifier;
2928

@@ -43,8 +42,7 @@
4342
import org.springframework.security.core.userdetails.User;
4443
import org.springframework.security.web.server.SecurityWebFilterChain;
4544
import org.springframework.session.data.mongo.config.annotation.web.reactive.EnableMongoWebSession;
46-
import org.springframework.test.context.ContextConfiguration;
47-
import org.springframework.test.context.junit.jupiter.SpringExtension;
45+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4846
import org.springframework.test.web.reactive.server.FluxExchangeResult;
4947
import org.springframework.test.web.reactive.server.WebTestClient;
5048
import org.springframework.web.bind.annotation.GetMapping;
@@ -55,8 +53,7 @@
5553
/**
5654
* @author Boris Finkelshteyn
5755
*/
58-
@ExtendWith(SpringExtension.class)
59-
@ContextConfiguration
56+
@SpringJUnitConfig
6057
class MongoDbDeleteJacksonSessionVerificationTest {
6158

6259
@Autowired

spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/MongoDbLogoutVerificationTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import org.assertj.core.api.AssertionsForClassTypes;
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.extension.ExtendWith;
2726
import org.testcontainers.containers.MongoDBContainer;
2827
import reactor.test.StepVerifier;
2928

@@ -43,8 +42,7 @@
4342
import org.springframework.security.core.userdetails.User;
4443
import org.springframework.security.web.server.SecurityWebFilterChain;
4544
import org.springframework.session.data.mongo.config.annotation.web.reactive.EnableMongoWebSession;
46-
import org.springframework.test.context.ContextConfiguration;
47-
import org.springframework.test.context.junit.jupiter.SpringExtension;
45+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4846
import org.springframework.test.web.reactive.server.FluxExchangeResult;
4947
import org.springframework.test.web.reactive.server.WebTestClient;
5048
import org.springframework.web.bind.annotation.GetMapping;
@@ -55,8 +53,7 @@
5553
/**
5654
* @author Greg Turnquist
5755
*/
58-
@ExtendWith(SpringExtension.class)
59-
@ContextConfiguration
56+
@SpringJUnitConfig
6057
class MongoDbLogoutVerificationTest {
6158

6259
@Autowired

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepositoryConfigurationITests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@
2424

2525
import org.junit.jupiter.api.BeforeEach;
2626
import org.junit.jupiter.api.Test;
27-
import org.junit.jupiter.api.extension.ExtendWith;
2827

2928
import org.springframework.context.annotation.Bean;
3029
import org.springframework.context.annotation.Configuration;
@@ -43,13 +42,13 @@
4342
import org.springframework.session.data.redis.config.ConfigureReactiveRedisAction;
4443
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisIndexedWebSession;
4544
import org.springframework.session.events.SessionCreatedEvent;
46-
import org.springframework.test.context.junit.jupiter.SpringExtension;
45+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
4746
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4847

4948
import static org.assertj.core.api.Assertions.assertThat;
5049
import static org.awaitility.Awaitility.await;
5150

52-
@ExtendWith(SpringExtension.class)
51+
@SpringJUnitConfig
5352
class ReactiveRedisIndexedSessionRepositoryConfigurationITests {
5453

5554
ReactiveRedisIndexedSessionRepository repository;

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisIndexedSessionRepositoryITests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323

2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.extension.ExtendWith;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.context.annotation.Bean;
@@ -43,17 +42,13 @@
4342
import org.springframework.session.events.SessionCreatedEvent;
4443
import org.springframework.session.events.SessionDeletedEvent;
4544
import org.springframework.session.events.SessionExpiredEvent;
46-
import org.springframework.test.context.ContextConfiguration;
47-
import org.springframework.test.context.junit.jupiter.SpringExtension;
48-
import org.springframework.test.context.web.WebAppConfiguration;
45+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
4946

5047
import static org.assertj.core.api.Assertions.assertThat;
5148
import static org.assertj.core.api.Assertions.assertThatNoException;
5249
import static org.awaitility.Awaitility.await;
5350

54-
@ExtendWith(SpringExtension.class)
55-
@ContextConfiguration
56-
@WebAppConfiguration
51+
@SpringJUnitWebConfig
5752
@SuppressWarnings({ "ConstantConditions" })
5853
class ReactiveRedisIndexedSessionRepositoryITests {
5954

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryITests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121

2222
import org.junit.jupiter.api.BeforeEach;
2323
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.extension.ExtendWith;
2524
import reactor.core.publisher.Mono;
2625

2726
import org.springframework.beans.factory.annotation.Autowired;
@@ -31,9 +30,7 @@
3130
import org.springframework.session.Session;
3231
import org.springframework.session.data.redis.ReactiveRedisSessionRepository.RedisSession;
3332
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;
34-
import org.springframework.test.context.ContextConfiguration;
35-
import org.springframework.test.context.junit.jupiter.SpringExtension;
36-
import org.springframework.test.context.web.WebAppConfiguration;
33+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
3734
import org.springframework.test.util.ReflectionTestUtils;
3835

3936
import static org.assertj.core.api.Assertions.assertThat;
@@ -51,9 +48,7 @@
5148
*
5249
* @author Vedran Pavic
5350
*/
54-
@ExtendWith(SpringExtension.class)
55-
@ContextConfiguration
56-
@WebAppConfiguration
51+
@SpringJUnitWebConfig
5752
class ReactiveRedisSessionRepositoryITests extends AbstractRedisITests {
5853

5954
@Autowired

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/ReactiveRedisSessionRepositoryKeyMissITests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.util.function.BiFunction;
2222

2323
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.extension.ExtendWith;
2524
import reactor.core.publisher.Mono;
2625

2726
import org.springframework.context.annotation.Bean;
@@ -32,7 +31,7 @@
3231
import org.springframework.session.config.ReactiveSessionRepositoryCustomizer;
3332
import org.springframework.session.data.redis.ReactiveRedisSessionRepository.RedisSession;
3433
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;
35-
import org.springframework.test.context.junit.jupiter.SpringExtension;
34+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3635
import org.springframework.test.util.ReflectionTestUtils;
3736
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3837

@@ -50,7 +49,7 @@
5049
* @see <a href="https://github.com/spring-projects/spring-session/issues/2021">Related
5150
* GitHub Issue</a>
5251
*/
53-
@ExtendWith(SpringExtension.class)
52+
@SpringJUnitConfig
5453
class ReactiveRedisSessionRepositoryKeyMissITests extends AbstractRedisITests {
5554

5655
private ReactiveRedisSessionRepository sessionRepository;

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryDynamicITests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@
2121
import java.util.function.BiFunction;
2222

2323
import org.junit.jupiter.api.Test;
24-
import org.junit.jupiter.api.extension.ExtendWith;
2524

2625
import org.springframework.context.annotation.Bean;
2726
import org.springframework.context.annotation.Configuration;
@@ -31,7 +30,7 @@
3130
import org.springframework.session.config.SessionRepositoryCustomizer;
3231
import org.springframework.session.data.redis.RedisIndexedSessionRepository.RedisSession;
3332
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisIndexedHttpSession;
34-
import org.springframework.test.context.junit.jupiter.SpringExtension;
33+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3534
import org.springframework.test.util.ReflectionTestUtils;
3635
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3736

@@ -48,7 +47,7 @@
4847
* @see <a href="https://github.com/spring-projects/spring-session/issues/2021">Related
4948
* GitHub Issue</a>
5049
*/
51-
@ExtendWith(SpringExtension.class)
50+
@SpringJUnitConfig
5251
class RedisIndexedSessionRepositoryDynamicITests extends AbstractRedisITests {
5352

5453
private RedisIndexedSessionRepository sessionRepository;

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisIndexedSessionRepositoryITests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323

2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.extension.ExtendWith;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.context.annotation.Bean;
@@ -43,9 +42,7 @@
4342
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisIndexedHttpSession;
4443
import org.springframework.session.events.SessionCreatedEvent;
4544
import org.springframework.session.events.SessionDestroyedEvent;
46-
import org.springframework.test.context.ContextConfiguration;
47-
import org.springframework.test.context.junit.jupiter.SpringExtension;
48-
import org.springframework.test.context.web.WebAppConfiguration;
45+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
4946

5047
import static org.assertj.core.api.Assertions.assertThat;
5148
import static org.assertj.core.api.Assertions.assertThatNoException;
@@ -56,9 +53,7 @@
5653
* @author Rob Winch
5754
* @author Vedran Pavic
5855
*/
59-
@ExtendWith(SpringExtension.class)
60-
@ContextConfiguration
61-
@WebAppConfiguration
56+
@SpringJUnitWebConfig
6257
class RedisIndexedSessionRepositoryITests extends AbstractRedisITests {
6358

6459
private static final String SPRING_SECURITY_CONTEXT = "SPRING_SECURITY_CONTEXT";

spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/RedisSessionRepositoryITests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,16 +23,13 @@
2323
import java.util.UUID;
2424

2525
import org.junit.jupiter.api.Test;
26-
import org.junit.jupiter.api.extension.ExtendWith;
2726

2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.context.annotation.Configuration;
3029
import org.springframework.session.MapSession;
3130
import org.springframework.session.data.redis.RedisSessionRepository.RedisSession;
3231
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
33-
import org.springframework.test.context.ContextConfiguration;
34-
import org.springframework.test.context.junit.jupiter.SpringExtension;
35-
import org.springframework.test.context.web.WebAppConfiguration;
32+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
3633

3734
import static org.assertj.core.api.Assertions.assertThat;
3835
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
@@ -42,9 +39,7 @@
4239
*
4340
* @author Vedran Pavic
4441
*/
45-
@ExtendWith(SpringExtension.class)
46-
@ContextConfiguration
47-
@WebAppConfiguration
42+
@SpringJUnitWebConfig
4843
class RedisSessionRepositoryITests extends AbstractRedisITests {
4944

5045
@Autowired

0 commit comments

Comments
 (0)