diff --git a/2.x/chapter1-1/pom.xml b/2.x/chapter1-1/pom.xml index d4e872a6..e261d981 100644 --- a/2.x/chapter1-1/pom.xml +++ b/2.x/chapter1-1/pom.xml @@ -29,6 +29,21 @@ spring-boot-starter-test test + + + + org.junit.jupiter + junit-jupiter-api + 5.6.0 + test + + + + org.mockito + mockito-core + 3.3.3 + test + diff --git a/2.x/chapter1-1/src/test/java/com/didispace/chapter11/HelloController_index_b1e8101632_Test.java b/2.x/chapter1-1/src/test/java/com/didispace/chapter11/HelloController_index_b1e8101632_Test.java new file mode 100644 index 00000000..4640090b --- /dev/null +++ b/2.x/chapter1-1/src/test/java/com/didispace/chapter11/HelloController_index_b1e8101632_Test.java @@ -0,0 +1,47 @@ +package com.didispace.chapter11; + +import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +@SpringBootTest +@AutoConfigureMockMvc +public class HelloController_index_b1e8101632_Test { + + @Autowired + private MockMvc mockMvc; + + @Autowired + private HelloController helloController; + + @Before + public void setUp() { + mockMvc = MockMvcBuilders.standaloneSetup(helloController).build(); + } + + @Test + public void testIndexSuccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/hello")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Hello World")) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + } + + @Test + public void testIndexFailure() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/hello")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Hello Mars")) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); + } +}