Merge pull request #1967 from tschiman/master
BAEL-755 Updating code with suggested changes
This commit is contained in:
commit
639bc980a8
|
@ -1,11 +1,10 @@
|
|||
package com.baeldung.springbootkotlin
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class HelloController @Autowired constructor(val helloService: HelloService) {
|
||||
class HelloController constructor(val helloService: HelloService) {
|
||||
|
||||
@GetMapping("/hello")
|
||||
fun helloKotlin(): String {
|
||||
|
@ -17,8 +16,8 @@ class HelloController @Autowired constructor(val helloService: HelloService) {
|
|||
return helloService.getHello()
|
||||
}
|
||||
|
||||
@GetMapping("/hello-poko")
|
||||
fun helloPoko(): HelloPoko {
|
||||
return HelloPoko("Hello from the poko")
|
||||
@GetMapping("/hello-dto")
|
||||
fun helloDto(): HelloDto {
|
||||
return HelloDto("Hello from the dto")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.baeldung.springbootkotlin
|
||||
|
||||
data class HelloDto constructor(val greeting: String)
|
|
@ -1,3 +0,0 @@
|
|||
package com.baeldung.springbootkotlin
|
||||
|
||||
data class HelloPoko constructor(val greeting: String)
|
|
@ -1,6 +1,6 @@
|
|||
package com.example.kotlindemo
|
||||
|
||||
import com.baeldung.springbootkotlin.HelloPoko
|
||||
import com.baeldung.springbootkotlin.HelloDto
|
||||
import com.baeldung.springbootkotlin.KotlinDemoApplication
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
|
@ -41,12 +41,12 @@ class KotlinDemoApplicationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun testHelloPoko() {
|
||||
var result = testRestTemplate?.getForEntity("/hello-poko", HelloPoko::class.java)
|
||||
fun testHelloDto() {
|
||||
var result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
|
||||
|
||||
Assert.assertNotNull(result)
|
||||
Assert.assertEquals(result?.statusCode, HttpStatus.OK)
|
||||
Assert.assertEquals(result?.body, HelloPoko("Hello from the poko"))
|
||||
Assert.assertEquals(result?.body, HelloDto("Hello from the dto"))
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue