diff --git a/2022-11/spring-05-springBoot/pom.xml b/2022-11/spring-05-springBoot/pom.xml index 6299aa46..cde7d619 100644 --- a/2022-11/spring-05-springBoot/pom.xml +++ b/2022-11/spring-05-springBoot/pom.xml @@ -10,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 3.0.0 + 2.7.3 UTF-8 diff --git a/2022-11/spring-05-springBoot/src/main/java/ru/otus/service/LocalHello.java b/2022-11/spring-05-springBoot/src/main/java/ru/otus/service/LocalHello.java index 6dddf223..f0b375bf 100644 --- a/2022-11/spring-05-springBoot/src/main/java/ru/otus/service/LocalHello.java +++ b/2022-11/spring-05-springBoot/src/main/java/ru/otus/service/LocalHello.java @@ -1,6 +1,6 @@ package ru.otus.service; -import jakarta.annotation.PostConstruct; +import javax.annotation.PostConstruct; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; diff --git a/2022-11/spring-05-springBoot/src/test/java/ru/otus/controller/GreetingControllerTest.java b/2022-11/spring-05-springBoot/src/test/java/ru/otus/controller/GreetingControllerTest.java deleted file mode 100644 index 904c5386..00000000 --- a/2022-11/spring-05-springBoot/src/test/java/ru/otus/controller/GreetingControllerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package ru.otus.controller; - -import java.util.HashMap; -import java.util.Map; - -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.boot.test.mock.mockito.MockBean; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.test.web.servlet.MockMvc; -import ru.otus.service.GreetingService; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; - - -@WebMvcTest({GreetingController.class, GreetingControllerRstyle.class}) -class GreetingControllerTest { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private GreetingService greetingService; - - @Test - void sayHelloTest() throws Exception { - String name = "Mr.Test"; - Map map = new HashMap<>(); - map.put(name, "Hello, " + name); - String expectedResult = "{\"Mr.Test\":\"Hello, Mr.Test\"}"; - - when(greetingService.sayHello(name)).thenReturn(map); - MockHttpServletResponse result = mockMvc.perform(get(String.format("/hello?name=%s", name))) - .andReturn() - .getResponse(); - - verify(greetingService, times(1)).sayHello(name); - System.out.println(); - assertThat(result.getContentAsString()).isEqualTo(expectedResult); - } - - @Test - void sayHelloTestMock() throws Exception { - String name = "Mr.Test"; - Map map = new HashMap<>(); - map.put(name, "Hello, " + name); - String expectedResult = "{\"Mr.Test\":\"Hello, Mr.Test\"}"; - - when(greetingService.sayHello(name)).thenReturn(map); - MockHttpServletResponse result = mockMvc.perform(get(String.format("/hello/%s", name))) - .andReturn() - .getResponse(); - - verify(greetingService, times(1)).sayHello(name); - System.out.println(); - assertThat(result.getContentAsString()).isEqualTo(expectedResult); - } -} \ No newline at end of file