diff --git a/src/main/java/com/adevinta/mstestfactoriaf5helloworld/application/.gitkeep b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/application/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/com/adevinta/mstestfactoriaf5helloworld/application/HelloWorldService.kt b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/application/HelloWorldService.kt new file mode 100644 index 0000000..12f32bc --- /dev/null +++ b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/application/HelloWorldService.kt @@ -0,0 +1,8 @@ +package com.adevinta.mstestfactoriaf5helloworld.application + +class HelloWorldService { + + fun hello(): String { + TODO("Not yet implemented") + } +} diff --git a/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/configuration/ApplicationConfiguration.kt b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/configuration/ApplicationConfiguration.kt new file mode 100644 index 0000000..ad51f94 --- /dev/null +++ b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/configuration/ApplicationConfiguration.kt @@ -0,0 +1,12 @@ +package com.adevinta.mstestfactoriaf5helloworld.infrastructure.configuration + +import com.adevinta.mstestfactoriaf5helloworld.application.HelloWorldService +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class ApplicationConfiguration { + + @Bean + fun helloWorldService() = HelloWorldService() +} diff --git a/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldController.kt b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldController.kt index 8c47041..d5220ba 100644 --- a/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldController.kt +++ b/src/main/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldController.kt @@ -1,13 +1,18 @@ package com.adevinta.mstestfactoriaf5helloworld.infrastructure.controller +import com.adevinta.mstestfactoriaf5helloworld.application.HelloWorldService import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/hello") -class HelloWorldController { +class HelloWorldController( + private val helloWorldService: HelloWorldService +) { + @GetMapping - @Suppress("FunctionOnlyReturningConstant") - fun sayHello(): String = "Hello Coders!!!" + fun sayHello(): String { + return helloWorldService.hello() + } } diff --git a/src/test/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldControllerTest.kt b/src/test/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldControllerTest.kt index c8df501..943a958 100644 --- a/src/test/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldControllerTest.kt +++ b/src/test/java/com/adevinta/mstestfactoriaf5helloworld/infrastructure/controller/HelloWorldControllerTest.kt @@ -1,10 +1,14 @@ package com.adevinta.mstestfactoriaf5helloworld.infrastructure.controller +import com.adevinta.mstestfactoriaf5helloworld.application.HelloWorldService import com.adevinta.mstestfactoriaf5helloworld.infrastructure.Application +import com.nhaarman.mockito_kotlin.doReturn +import com.nhaarman.mockito_kotlin.whenever import org.hamcrest.Matchers.equalTo 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.test.context.ContextConfiguration import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -15,13 +19,19 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content @ContextConfiguration(classes = [Application::class]) class HelloWorldControllerTest { + @MockBean + private lateinit var helloWorldService: HelloWorldService + @Autowired private lateinit var mvc: MockMvc @Test - fun `should say hello`() { + fun shouldSayHello() { + val helloWorldMessage = "Hello Coders from HelloWorldService!!!" + doReturn(helloWorldMessage).whenever(helloWorldService).hello() + mvc.perform(get("/hello")) .andExpect(status().isOk) - .andExpect(content().string(equalTo("Hello Coders!!!"))) + .andExpect(content().string(equalTo(helloWorldMessage))) } }