Skip to content

Commit e8dba2f

Browse files
committed
BAEL-21543: Fix integration tests in spring-boot
1 parent 78df7c0 commit e8dba2f

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import com.baeldung.beanvalidation.application.controllers.UserController;
44
import com.baeldung.beanvalidation.application.repositories.UserRepository;
5-
6-
import java.nio.charset.Charset;
7-
import static org.assertj.core.api.Assertions.assertThat;
85
import org.hamcrest.core.Is;
96
import org.junit.Test;
107
import org.junit.runner.RunWith;
@@ -18,6 +15,10 @@
1815
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
1916
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
2017

18+
import java.nio.charset.Charset;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
2122
@RunWith(SpringRunner.class)
2223
@WebMvcTest
2324
@AutoConfigureMockMvc
@@ -40,9 +41,9 @@ public void whenUserControllerInjected_thenNotNull() throws Exception {
4041
@Test
4142
public void whenGetRequestToUsers_thenCorrectResponse() throws Exception {
4243
mockMvc.perform(MockMvcRequestBuilders.get("/users")
43-
.contentType(MediaType.APPLICATION_JSON_UTF8))
44+
.contentType(MediaType.APPLICATION_JSON))
4445
.andExpect(MockMvcResultMatchers.status().isOk())
45-
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8));
46+
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON));
4647

4748
}
4849

@@ -52,7 +53,7 @@ public void whenPostRequestToUsersAndValidUser_thenCorrectResponse() throws Exce
5253
String user = "{\"name\": \"bob\", \"email\" : \"bob@domain.com\"}";
5354
mockMvc.perform(MockMvcRequestBuilders.post("/users")
5455
.content(user)
55-
.contentType(MediaType.APPLICATION_JSON_UTF8))
56+
.contentType(MediaType.APPLICATION_JSON))
5657
.andExpect(MockMvcResultMatchers.status().isOk())
5758
.andExpect(MockMvcResultMatchers.content().contentType(textPlainUtf8));
5859
}
@@ -62,9 +63,9 @@ public void whenPostRequestToUsersAndInValidUser_thenCorrectReponse() throws Exc
6263
String user = "{\"name\": \"\", \"email\" : \"bob@domain.com\"}";
6364
mockMvc.perform(MockMvcRequestBuilders.post("/users")
6465
.content(user)
65-
.contentType(MediaType.APPLICATION_JSON_UTF8))
66+
.contentType(MediaType.APPLICATION_JSON))
6667
.andExpect(MockMvcResultMatchers.status().isBadRequest())
6768
.andExpect(MockMvcResultMatchers.jsonPath("$.name", Is.is("Name is mandatory")))
68-
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8));
69+
.andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON));
6970
}
7071
}

0 commit comments

Comments
 (0)