From e8dba2ffd659508c88a014f7645f7bb188e0d3d4 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Mon, 27 Jan 2020 20:04:21 +0100 Subject: [PATCH] BAEL-21543: Fix integration tests in spring-boot --- .../UserControllerIntegrationTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java index 07d9b0807e..21395c779b 100644 --- a/spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/beanvalidation/application/UserControllerIntegrationTest.java @@ -2,9 +2,6 @@ package com.baeldung.beanvalidation.application; import com.baeldung.beanvalidation.application.controllers.UserController; import com.baeldung.beanvalidation.application.repositories.UserRepository; - -import java.nio.charset.Charset; -import static org.assertj.core.api.Assertions.assertThat; import org.hamcrest.core.Is; import org.junit.Test; import org.junit.runner.RunWith; @@ -18,6 +15,10 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import java.nio.charset.Charset; + +import static org.assertj.core.api.Assertions.assertThat; + @RunWith(SpringRunner.class) @WebMvcTest @AutoConfigureMockMvc @@ -40,9 +41,9 @@ public class UserControllerIntegrationTest { @Test public void whenGetRequestToUsers_thenCorrectResponse() throws Exception { mockMvc.perform(MockMvcRequestBuilders.get("/users") - .contentType(MediaType.APPLICATION_JSON_UTF8)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8)); + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)); } @@ -52,7 +53,7 @@ public class UserControllerIntegrationTest { String user = "{\"name\": \"bob\", \"email\" : \"bob@domain.com\"}"; mockMvc.perform(MockMvcRequestBuilders.post("/users") .content(user) - .contentType(MediaType.APPLICATION_JSON_UTF8)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().contentType(textPlainUtf8)); } @@ -62,9 +63,9 @@ public class UserControllerIntegrationTest { String user = "{\"name\": \"\", \"email\" : \"bob@domain.com\"}"; mockMvc.perform(MockMvcRequestBuilders.post("/users") .content(user) - .contentType(MediaType.APPLICATION_JSON_UTF8)) + .contentType(MediaType.APPLICATION_JSON)) .andExpect(MockMvcResultMatchers.status().isBadRequest()) .andExpect(MockMvcResultMatchers.jsonPath("$.name", Is.is("Name is mandatory"))) - .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8)); + .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)); } }