mirror of
https://github.com/InsanusMokrassar/SDI.git
synced 2024-11-27 12:38:55 +00:00
fix test
This commit is contained in:
parent
b9e24b0d12
commit
2d158fe166
@ -13,7 +13,7 @@ class Module(base: Map<String, @ContextualSerialization Any>) : Map<String, Any>
|
|||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@ImplicitReflectionSerializer
|
||||||
@Serializer(Module::class)
|
@Serializer(Module::class)
|
||||||
object ModuleSerializer : KSerializer<Module> {
|
internal object ModuleSerializer : KSerializer<Module> {
|
||||||
private val internalSerializer = HashMapSerializer(StringSerializer, ContextSerializer(Any::class))
|
private val internalSerializer = HashMapSerializer(StringSerializer, ContextSerializer(Any::class))
|
||||||
override val descriptor: SerialDescriptor
|
override val descriptor: SerialDescriptor
|
||||||
get() = internalSerializer.descriptor
|
get() = internalSerializer.descriptor
|
||||||
|
@ -2,8 +2,7 @@ package com.insanusmokrassar.sdi
|
|||||||
|
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.test.Test
|
import kotlin.test.*
|
||||||
import kotlin.test.assertTrue
|
|
||||||
|
|
||||||
interface ControllerAPI {
|
interface ControllerAPI {
|
||||||
fun showUp()
|
fun showUp()
|
||||||
@ -13,7 +12,7 @@ interface ServiceAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class Controller(@ContextualSerialization private val service: ServiceAPI) : ControllerAPI {
|
class Controller(@ContextualSerialization val service: ServiceAPI) : ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
@ -25,12 +24,13 @@ class BusinessService(override val names: List<String>) : ServiceAPI
|
|||||||
class DeserializationTest {
|
class DeserializationTest {
|
||||||
@Test
|
@Test
|
||||||
fun test_that_simple_config_correctly_work() {
|
fun test_that_simple_config_correctly_work() {
|
||||||
|
val names = arrayOf("nameOne", "nameTwo")
|
||||||
val input = """
|
val input = """
|
||||||
{
|
{
|
||||||
"service": [
|
"service": [
|
||||||
"com.insanusmokrassar.sdi.BusinessService",
|
"com.insanusmokrassar.sdi.BusinessService",
|
||||||
{
|
{
|
||||||
"names": ["nameOne", "nameTwo"]
|
"names": ${names.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"controller": [
|
"controller": [
|
||||||
@ -41,7 +41,9 @@ class DeserializationTest {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
val module = Json.plain.parse(ModuleSerializer, input)
|
val module = Json.plain.parse(Module.serializer(), input)
|
||||||
(module["controller"] as ControllerAPI).showUp()
|
(module["controller"] as ControllerAPI)
|
||||||
|
val controller = (module["controller"] as Controller)
|
||||||
|
assertEquals(names.toList(), controller.service.names)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user