Kotlin refactor
This commit is contained in:
parent
3cf4dc5a78
commit
19d084e728
|
@ -4,7 +4,7 @@ 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 constructor(val helloService: HelloService) {
|
class HelloController(val helloService: HelloService) {
|
||||||
|
|
||||||
@GetMapping("/hello")
|
@GetMapping("/hello")
|
||||||
fun helloKotlin(): String {
|
fun helloKotlin(): String {
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
package com.baeldung.springbootkotlin
|
package com.baeldung.springbootkotlin
|
||||||
|
|
||||||
data class HelloDto constructor(val greeting: String)
|
data class HelloDto(val greeting: String)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class HelloService {
|
class HelloService {
|
||||||
|
|
||||||
fun getHello(): String {
|
fun getHello(): String {
|
||||||
return "hello service"
|
return "hello service"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.example.kotlindemo
|
package springbootkotlin
|
||||||
|
|
||||||
import com.baeldung.springbootkotlin.HelloDto
|
import com.baeldung.springbootkotlin.HelloDto
|
||||||
import com.baeldung.springbootkotlin.KotlinDemoApplication
|
import com.baeldung.springbootkotlin.KotlinDemoApplication
|
||||||
|
@ -24,7 +24,7 @@ class KotlinDemoApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHelloController() {
|
fun testHelloController() {
|
||||||
var result = testRestTemplate?.getForEntity("/hello", String::class.java)
|
val result = testRestTemplate?.getForEntity("/hello", String::class.java)
|
||||||
|
|
||||||
Assert.assertNotNull(result)
|
Assert.assertNotNull(result)
|
||||||
Assert.assertEquals(result?.statusCode, HttpStatus.OK)
|
Assert.assertEquals(result?.statusCode, HttpStatus.OK)
|
||||||
|
@ -33,7 +33,7 @@ class KotlinDemoApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHelloService() {
|
fun testHelloService() {
|
||||||
var result = testRestTemplate?.getForEntity("/hello-service", String::class.java)
|
val result = testRestTemplate?.getForEntity("/hello-service", String::class.java)
|
||||||
|
|
||||||
Assert.assertNotNull(result)
|
Assert.assertNotNull(result)
|
||||||
Assert.assertEquals(result?.statusCode, HttpStatus.OK)
|
Assert.assertEquals(result?.statusCode, HttpStatus.OK)
|
||||||
|
@ -42,7 +42,7 @@ class KotlinDemoApplicationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testHelloDto() {
|
fun testHelloDto() {
|
||||||
var result = testRestTemplate?.getForEntity("/hello-dto", HelloDto::class.java)
|
val 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)
|
||||||
|
|
Loading…
Reference in New Issue