Spring 전환 최소 실행 골격 구현 #4
1 changed files with 38 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.example.demo.controller;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
@WebMvcTest(HelloController.class)
|
||||||
|
class HelloControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hello_withoutName_returnsDefaultMessage() throws Exception {
|
||||||
|
mockMvc.perform(get("/hello"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string("Hello, World!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hello_withName_returnsPersonalizedMessage() throws Exception {
|
||||||
|
mockMvc.perform(get("/hello").param("name", "Spring"))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string("Hello, Spring!"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void hello_withBlankName_returnsDefaultMessage() throws Exception {
|
||||||
|
mockMvc.perform(get("/hello").param("name", " "))
|
||||||
|
.andExpect(status().isOk())
|
||||||
|
.andExpect(content().string("Hello, World!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue