Skip to content

Commit b01d1f7

Browse files
committed
BAEL-21543: Fix integration tests in spring-mvc-basics
1 parent 32e9a49 commit b01d1f7

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

spring-mvc-basics/src/test/java/com/baeldung/web/controller/EmployeeControllerContentNegotiationIntegrationTest.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.baeldung.web.controller;
22

3-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
5-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
6-
73
import org.junit.jupiter.api.Test;
84
import org.springframework.beans.factory.annotation.Autowired;
95
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -12,6 +8,10 @@
128
import org.springframework.http.MediaType;
139
import org.springframework.test.web.servlet.MockMvc;
1410

11+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
12+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
13+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
14+
1515
@SpringBootTest
1616
@AutoConfigureMockMvc
1717
public class EmployeeControllerContentNegotiationIntegrationTest {
@@ -23,7 +23,7 @@ public class EmployeeControllerContentNegotiationIntegrationTest {
2323
public void whenEndpointUsingJsonSuffixCalled_thenJsonResponseObtained() throws Exception {
2424
this.mockMvc.perform(get("/employee/1.json"))
2525
.andExpect(status().isOk())
26-
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE));
26+
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE));
2727
}
2828

2929
@Test
@@ -37,7 +37,7 @@ public void whenEndpointUsingXmlSuffixCalled_thenXmlResponseObtained() throws Ex
3737
public void whenEndpointUsingJsonParameterCalled_thenJsonResponseObtained() throws Exception {
3838
this.mockMvc.perform(get("/employee/1?mediaType=json"))
3939
.andExpect(status().isOk())
40-
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE));
40+
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE));
4141
}
4242

4343
@Test
@@ -51,7 +51,7 @@ public void whenEndpointUsingXmlParameterCalled_thenXmlResponseObtained() throws
5151
public void whenEndpointUsingJsonAcceptHeaderCalled_thenJsonResponseObtained() throws Exception {
5252
this.mockMvc.perform(get("/employee/1").header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE))
5353
.andExpect(status().isOk())
54-
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_UTF8_VALUE));
54+
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE));
5555
}
5656

5757
@Test

spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookControllerIntegrationTest.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package com.baeldung.web.controller;
22

3-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
5-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
6-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
7-
83
import org.junit.jupiter.api.BeforeEach;
94
import org.junit.jupiter.api.Test;
5+
import org.springframework.http.MediaType;
106
import org.springframework.test.web.servlet.MockMvc;
117
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
128

9+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
10+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
11+
1312
public class SimpleBookControllerIntegrationTest {
1413

1514
private MockMvc mockMvc;
16-
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
1715

1816
@BeforeEach
1917
public void setup() {
@@ -25,7 +23,7 @@ public void givenBookId_whenMockMVC_thenVerifyResponse() throws Exception {
2523
this.mockMvc
2624
.perform(get("/books/42"))
2725
.andExpect(status().isOk())
28-
.andExpect(content().contentType(CONTENT_TYPE))
26+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
2927
.andExpect(jsonPath("$.id").value(42));
3028
}
3129

spring-mvc-basics/src/test/java/com/baeldung/web/controller/SimpleBookRestControllerIntegrationTest.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package com.baeldung.web.controller;
22

3-
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
5-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
6-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
7-
83
import org.junit.jupiter.api.BeforeEach;
94
import org.junit.jupiter.api.Test;
5+
import org.springframework.http.MediaType;
106
import org.springframework.test.web.servlet.MockMvc;
117
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
128

9+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
10+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
11+
1312
public class SimpleBookRestControllerIntegrationTest {
1413

1514
private MockMvc mockMvc;
16-
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
1715

1816
@BeforeEach
1917
public void setup() {
@@ -25,7 +23,7 @@ public void givenBookId_whenMockMVC_thenVerifyResponse() throws Exception {
2523
this.mockMvc
2624
.perform(get("/books-rest/42"))
2725
.andExpect(status().isOk())
28-
.andExpect(content().contentType(CONTENT_TYPE))
26+
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
2927
.andExpect(jsonPath("$.id").value(42));
3028
}
3129

0 commit comments

Comments
 (0)