Skip to content

Commit

Permalink
Add HelloWorldService
Browse files Browse the repository at this point in the history
  • Loading branch information
Roger Viñas committed Feb 3, 2022
1 parent 9a9171c commit 40ad4f5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.adevinta.mstestfactoriaf5helloworld.application

class HelloWorldService {

fun hello(): String {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -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()
}
Original file line number Diff line number Diff line change
@@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)))
}
}

0 comments on commit 40ad4f5

Please sign in to comment.