From 34a5bd13a52ce3b5f0e951905f8c1e37df87b16a Mon Sep 17 00:00:00 2001 From: harishagrawal Date: Tue, 12 Sep 2023 09:52:39 +0000 Subject: [PATCH 1/3] Test generated by RoostGPT for test learn-springboot using AI Type Open AI and AI Model gpt-4 --- 2.x/chapter1-1/pom.xml | 15 ++++++++++ ...HelloController_index_b1e8101632_Test.java | 29 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 2.x/chapter1-1/src/test/java/com/didispace/chapter11/HelloController_index_b1e8101632_Test.java 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..3bc041ce --- /dev/null +++ b/2.x/chapter1-1/src/test/java/com/didispace/chapter11/HelloController_index_b1e8101632_Test.java @@ -0,0 +1,29 @@ +// Test generated by RoostGPT for test learn-springboot using AI Type Open AI and AI Model gpt-4 + +package com.didispace.chapter11; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; + +@SpringBootTest +public class HelloController_index_b1e8101632_Test { + + @MockBean + private HelloController helloController; + + @Test + public void testIndexSuccess() { + Mockito.when(helloController.index()).thenReturn("Hello World"); + String result = helloController.index(); + Assertions.assertEquals("Hello World", result, "Expected and actual results do not match"); + } + + @Test + public void testIndexFailure() { + Mockito.when(helloController.index()).thenReturn("Hello World"); + String result = helloController.index(); + Assertions.assertNotEquals("Hello Mars", result, "Expected and actual results should not match"); + } +} From 2de19062b694d05d5b1476a63d05caa9d1586501 Mon Sep 17 00:00:00 2001 From: harishagrawal Date: Tue, 12 Sep 2023 09:59:47 +0000 Subject: [PATCH 2/3] Test generated by RoostGPT for test learn-springboot using AI Type Open AI and AI Model gpt-4 --- ...HelloController_index_b1e8101632_Test.java | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) 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 index 3bc041ce..66f18e4f 100644 --- 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 @@ -1,29 +1,37 @@ -// Test generated by RoostGPT for test learn-springboot using AI Type Open AI and AI Model gpt-4 - package com.didispace.chapter11; 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.boot.test.mock.mockito.MockBean; +import org.springframework.test.web.servlet.MockMvc; +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 { - @MockBean - private HelloController helloController; + @Autowired + private MockMvc mockMvc; @Test - public void testIndexSuccess() { - Mockito.when(helloController.index()).thenReturn("Hello World"); - String result = helloController.index(); - Assertions.assertEquals("Hello World", result, "Expected and actual results do not match"); + public void testIndexSuccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Hello World")) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); } @Test - public void testIndexFailure() { - Mockito.when(helloController.index()).thenReturn("Hello World"); - String result = helloController.index(); - Assertions.assertNotEquals("Hello Mars", result, "Expected and actual results should not match"); + public void testIndexFailure() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Hello Mars")) + .andDo(MockMvcResultHandlers.print()) + .andReturn(); } } From d8901b80eba86548177beb70f585513ac1f573a6 Mon Sep 17 00:00:00 2001 From: harishagrawal Date: Tue, 12 Sep 2023 10:09:38 +0000 Subject: [PATCH 3/3] Test generated by RoostGPT for test learn-springboot using AI Type Open AI and AI Model gpt-4 --- .../HelloController_index_b1e8101632_Test.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 index 66f18e4f..4640090b 100644 --- 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 @@ -1,11 +1,13 @@ 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; @@ -17,9 +19,17 @@ 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("/")) + mockMvc.perform(MockMvcRequestBuilders.get("/hello")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Hello World")) .andDo(MockMvcResultHandlers.print()) @@ -28,7 +38,7 @@ public void testIndexSuccess() throws Exception { @Test public void testIndexFailure() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/")) + mockMvc.perform(MockMvcRequestBuilders.get("/hello")) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.content().string("Hello Mars")) .andDo(MockMvcResultHandlers.print())