Skip to content

Commit

Permalink
Adding test for required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Jul 18, 2022
1 parent c3e44bb commit 8caedaa
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.akuleshov7.ktoml.decoders

import com.akuleshov7.ktoml.Toml
import com.akuleshov7.ktoml.exceptions.MissingRequiredPropertyException
import kotlinx.serialization.Required
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlin.test.Test
import kotlin.test.assertFailsWith

@Serializable
data class RequiredStr(
val a: String = "a",
@Required
val b: String = "b",
val c: String,
)

class RequiredAnnotation {
@Test
fun testMissingRequiredPropertyException() {
assertFailsWith<MissingRequiredPropertyException> { Toml.decodeFromString<RequiredStr>("c = \"100\"") }
}
}

0 comments on commit 8caedaa

Please sign in to comment.