BAEL-755 changing the name of the POKO to a DTO and removing the use of @Autowired in the constructor as it is not needed.

This commit is contained in:
tschiman 2017-05-31 16:31:02 -06:00
parent 7eb0eafe94
commit ea302a5f33
4 changed files with 10 additions and 11 deletions

View File

@ -1,11 +1,10 @@
package com.baeldung.springbootkotlin package com.baeldung.springbootkotlin
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController import org.springframework.web.bind.annotation.RestController
@RestController @RestController
class HelloController @Autowired constructor(val helloService: HelloService) { class HelloController constructor(val helloService: HelloService) {
@GetMapping("/hello") @GetMapping("/hello")
fun helloKotlin(): String { fun helloKotlin(): String {
@ -17,8 +16,8 @@ class HelloController @Autowired constructor(val helloService: HelloService) {
return helloService.getHello() return helloService.getHello()
} }
@GetMapping("/hello-poko") @GetMapping("/hello-dto")
fun helloPoko(): HelloPoko { fun helloDto(): HelloDto {
return HelloPoko("Hello from the poko") return HelloDto("Hello from the dto")
} }
} }

View File

@ -0,0 +1,3 @@
package com.baeldung.springbootkotlin
data class HelloDto constructor(val greeting: String)

View File

@ -1,3 +0,0 @@
package com.baeldung.springbootkotlin
data class HelloPoko constructor(val greeting: String)

View File

@ -1,6 +1,6 @@
package com.example.kotlindemo package com.example.kotlindemo
import com.baeldung.springbootkotlin.HelloPoko import com.baeldung.springbootkotlin.HelloDto
import com.baeldung.springbootkotlin.KotlinDemoApplication import com.baeldung.springbootkotlin.KotlinDemoApplication
import org.junit.Assert import org.junit.Assert
import org.junit.Test import org.junit.Test
@ -42,11 +42,11 @@ class KotlinDemoApplicationTests {
@Test @Test
fun testHelloPoko() { fun testHelloPoko() {
var result = testRestTemplate?.getForEntity("/hello-poko", HelloPoko::class.java) var result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
Assert.assertNotNull(result) Assert.assertNotNull(result)
Assert.assertEquals(result?.statusCode, HttpStatus.OK) Assert.assertEquals(result?.statusCode, HttpStatus.OK)
Assert.assertEquals(result?.body, HelloPoko("Hello from the poko")) Assert.assertEquals(result?.body, HelloDto("Hello from the dto"))
} }
} }