Skip to content

Commit cd84fc8

Browse files
devondragonclaude
andcommitted
Update test imports for Spring Boot 4 modular packages
Spring Boot 4 moved test annotations to separate modules with new package locations. Updated all test files to use: - @AutoConfigureMockMvc -> boot.webmvc.test.autoconfigure - @WebMvcTest -> boot.webmvc.test.autoconfigure - @DataJpaTest -> boot.data.jpa.test.autoconfigure - @MockitoBean -> test.context.bean.override.mockito Also updated ObjectMapper instantiation to manual creation since Jackson 3 (used in Spring Boot 4) changed auto-configuration behavior. Files updated across: - demo/event tests - user/api tests - user/concurrent tests - user/integration tests - user/oauth2 tests - user/security tests - test annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 96478ce commit cd84fc8

28 files changed

Lines changed: 49 additions & 61 deletions

src/test/java/com/digitalsanctuary/spring/demo/DemoTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.digitalsanctuary.spring.demo;
22

33
import org.junit.jupiter.api.Test;
4-
import org.springframework.boot.autoconfigure.domain.EntityScan;
4+
import org.springframework.boot.persistence.autoconfigure.EntityScan;
55
import org.springframework.boot.test.context.SpringBootTest;
66
import org.springframework.context.annotation.Import;
77
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

src/test/java/com/digitalsanctuary/spring/demo/event/EventAPIControllerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.junit.jupiter.api.BeforeEach;
2525
import org.junit.jupiter.api.Test;
2626
import org.springframework.beans.factory.annotation.Autowired;
27-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
27+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
2828
import org.springframework.test.context.bean.override.mockito.MockitoBean;
2929
import org.springframework.http.MediaType;
3030
import com.digitalsanctuary.spring.demo.SecurityTestUtils;
@@ -53,8 +53,8 @@ public class EventAPIControllerTest {
5353
@MockitoBean
5454
private DemoSessionProfile demoSessionProfile;
5555

56-
@Autowired
57-
private ObjectMapper objectMapper;
56+
private ObjectMapper objectMapper = new ObjectMapper()
57+
.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
5858

5959
private Event testEvent;
6060
private List<Event> testEvents;

src/test/java/com/digitalsanctuary/spring/demo/event/EventControllerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import org.junit.jupiter.api.BeforeEach;
1515
import org.junit.jupiter.api.Test;
1616
import org.springframework.beans.factory.annotation.Autowired;
17-
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
17+
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
1818
import org.springframework.http.MediaType;
1919
import org.springframework.test.context.ActiveProfiles;
2020
import org.springframework.test.context.bean.override.mockito.MockitoBean;
@@ -40,8 +40,8 @@ public class EventControllerTest {
4040
@MockitoBean
4141
private DemoUserProfileService demoUserProfileService; // Add this mock bean
4242

43-
@Autowired
44-
private ObjectMapper objectMapper;
43+
private ObjectMapper objectMapper = new ObjectMapper()
44+
.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
4545

4646
private Event event;
4747

src/test/java/com/digitalsanctuary/spring/demo/event/EventRepositoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import java.util.Optional;
88
import org.junit.jupiter.api.Test;
99
import org.springframework.beans.factory.annotation.Autowired;
10-
import org.springframework.boot.autoconfigure.domain.EntityScan;
11-
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
10+
import org.springframework.boot.persistence.autoconfigure.EntityScan;
11+
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
1212
import org.springframework.test.context.ActiveProfiles;
1313

1414
@ActiveProfiles("test")

src/test/java/com/digitalsanctuary/spring/user/UserApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.digitalsanctuary.spring.user;
22

3-
import org.springframework.boot.autoconfigure.domain.EntityScan;
3+
import org.springframework.boot.persistence.autoconfigure.EntityScan;
44
import org.springframework.boot.test.context.SpringBootTest;
55
import org.springframework.context.annotation.Import;
66
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

src/test/java/com/digitalsanctuary/spring/user/api/ApiSecurityTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.junit.jupiter.api.Nested;
1414
import org.junit.jupiter.api.Test;
1515
import org.springframework.beans.factory.annotation.Autowired;
16-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
16+
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
1717
import org.springframework.boot.test.context.SpringBootTest;
1818
import org.springframework.http.MediaType;
1919
import org.springframework.security.test.context.support.WithAnonymousUser;
@@ -52,8 +52,7 @@ class ApiSecurityTest {
5252
@Autowired
5353
private MockMvc mockMvc;
5454

55-
@Autowired
56-
private ObjectMapper objectMapper;
55+
private ObjectMapper objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
5756

5857
@Autowired
5958
private UserRepository userRepository;

src/test/java/com/digitalsanctuary/spring/user/api/AuthenticatedUserApiTestSimplified.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.junit.jupiter.api.Disabled;
1616
import org.springframework.beans.factory.annotation.Autowired;
1717
import org.springframework.beans.factory.annotation.Value;
18-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
18+
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
1919
import org.springframework.boot.test.context.SpringBootTest;
2020
import org.springframework.http.MediaType;
2121
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -57,8 +57,7 @@ class AuthenticatedUserApiTestSimplified {
5757
@Autowired
5858
private MockMvc mockMvc;
5959

60-
@Autowired
61-
private ObjectMapper objectMapper;
60+
private ObjectMapper objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
6261

6362
@Autowired
6463
private UserRepository userRepository;

src/test/java/com/digitalsanctuary/spring/user/api/PasswordResetApiTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.junit.jupiter.api.DisplayName;
2626
import org.junit.jupiter.api.Test;
2727
import org.springframework.beans.factory.annotation.Autowired;
28-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
28+
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
2929
import org.springframework.boot.test.context.SpringBootTest;
3030
import org.springframework.http.MediaType;
3131
import org.springframework.test.context.ActiveProfiles;
@@ -67,8 +67,7 @@ class PasswordResetApiTest {
6767
@Autowired
6868
private MockMvc mockMvc;
6969

70-
@Autowired
71-
private ObjectMapper objectMapper;
70+
private ObjectMapper objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
7271

7372
@Autowired
7473
private UserRepository userRepository;

src/test/java/com/digitalsanctuary/spring/user/api/PasswordResetApiTestSimplified.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.junit.jupiter.api.DisplayName;
1616
import org.junit.jupiter.api.Test;
1717
import org.springframework.beans.factory.annotation.Autowired;
18-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
18+
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
1919
import org.springframework.boot.test.context.SpringBootTest;
2020
import org.springframework.http.MediaType;
2121
import org.springframework.test.context.ActiveProfiles;
@@ -50,8 +50,7 @@ class PasswordResetApiTestSimplified {
5050
@Autowired
5151
private MockMvc mockMvc;
5252

53-
@Autowired
54-
private ObjectMapper objectMapper;
53+
private ObjectMapper objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
5554

5655
@Autowired
5756
private UserRepository userRepository;

src/test/java/com/digitalsanctuary/spring/user/api/PasswordResetCompletionTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.junit.jupiter.api.DisplayName;
1212
import org.junit.jupiter.api.Test;
1313
import org.springframework.beans.factory.annotation.Autowired;
14-
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
14+
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
1515
import org.springframework.boot.test.context.SpringBootTest;
1616
import org.springframework.security.crypto.password.PasswordEncoder;
1717
import org.springframework.test.context.ActiveProfiles;
@@ -49,8 +49,7 @@ class PasswordResetCompletionTest {
4949
@Autowired
5050
private MockMvc mockMvc;
5151

52-
@Autowired
53-
private ObjectMapper objectMapper;
52+
private ObjectMapper objectMapper = new ObjectMapper().registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
5453

5554
@Autowired
5655
private UserRepository userRepository;

0 commit comments

Comments
 (0)