init commit (#11767)
This commit is contained in:
+25
-5
@@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -25,16 +26,16 @@ public class NoConverterFoundIntegrationTest {
|
||||
/* Remove Getters from Student class to successfully run this test case
|
||||
* @Test
|
||||
public void whenGettersNotDefined_thenThrowException() throws Exception {
|
||||
|
||||
|
||||
String url = "/api/student/1";
|
||||
|
||||
|
||||
this.mockMvc.perform(get(url))
|
||||
.andExpect(status().isInternalServerError())
|
||||
.andExpect(result -> assertThat(result.getResolvedException())
|
||||
.isInstanceOf(HttpMessageNotWritableException.class))
|
||||
.andExpect(result -> assertThat(result.getResolvedException().getMessage())
|
||||
.contains("No converter found for return value of type"));
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -44,9 +45,28 @@ public class NoConverterFoundIntegrationTest {
|
||||
String url = "/api/student/2";
|
||||
|
||||
this.mockMvc.perform(get(url))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.firstName").value("John"));
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.firstName").value("John"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenJsonConverterIsFound_thenReturnResponse() throws Exception {
|
||||
String url = "/api/student/v2/1";
|
||||
|
||||
this.mockMvc.perform(get(url))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().json("{'id':1,'firstName':'Kevin','lastName':'Cruyff', 'grade':'AA'}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenConverterNotFound_thenThrowException() throws Exception {
|
||||
String url = "/api/student/v3/1";
|
||||
|
||||
this.mockMvc.perform(get(url))
|
||||
.andExpect(status().isInternalServerError())
|
||||
.andExpect(result -> assertThat(result.getResolvedException()).isInstanceOf(HttpMessageNotWritableException.class))
|
||||
.andExpect(result -> assertThat(result.getResolvedException()
|
||||
.getMessage()).contains("No converter for [class com.baeldung.boot.noconverterfound.model.Student] with preset Content-Type"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user