JAVA-101 Split Core Kotlin

This commit is contained in:
mikr
2020-06-08 00:22:04 +02:00
parent 0130ae560f
commit 73e169d1eb
48 changed files with 136 additions and 27 deletions

View File

@@ -0,0 +1,30 @@
package com.baeldung.gson
import com.google.gson.Gson
import org.junit.Assert
import org.junit.Test
class GsonUnitTest {
var gson = Gson()
@Test
fun givenObject_thenGetJSONString() {
var jsonString = gson.toJson(TestModel(1, "Test"))
Assert.assertEquals(jsonString, "{\"id\":1,\"description\":\"Test\"}")
}
@Test
fun givenJSONString_thenGetObject() {
var jsonString = "{\"id\":1,\"description\":\"Test\"}";
var testModel = gson.fromJson(jsonString, TestModel::class.java)
Assert.assertEquals(testModel.id, 1)
Assert.assertEquals(testModel.description, "Test")
}
data class TestModel(
val id: Int,
val description: String
)
}