Skip to content

Commit

Permalink
added test for no such field in nested type
Browse files Browse the repository at this point in the history
  • Loading branch information
albertlatacz committed Jan 3, 2024
1 parent ec9e99b commit b98d5a6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import strikt.assertions.message

class JacksonWrapperTest {

class SubMap(node: JsonNode) : JacksonWrapper(node) {
class SubNodeBacked(node: JsonNode) : JacksonWrapper(node) {
val stringField by Field<String>()
val noSuchField by Field<String>()
}

class NodeBacked(node: JsonNode) : JacksonWrapper(node) {
Expand All @@ -22,9 +23,9 @@ class JacksonWrapperTest {
val decimalField by Field<Double>()
val notAStringField by Field<String>()
val noSuchField by Field<String>()
val listField by ListField(::SubMap)
val listField by ListField(::SubNodeBacked)
val listField2 by ListField(Any::toString)
val objectField by ObjectField(::SubMap)
val objectField by ObjectField(::SubNodeBacked)
}

@Test
Expand Down Expand Up @@ -62,5 +63,6 @@ class JacksonWrapperTest {
expectThat(mapBacked.objectField.stringField).isEqualTo("string")
expectThrows<NoSuchElementException> { mapBacked.notAStringField }.message.isEqualTo("Value for field <notAStringField> is not a class kotlin.String but class kotlin.Int")
expectThrows<NoSuchElementException> { mapBacked.noSuchField }.message.isEqualTo("Field <noSuchField> is missing")
expectThrows<NoSuchElementException> { mapBacked.objectField.noSuchField }.message.isEqualTo("Field <noSuchField> is missing")
}
}
2 changes: 2 additions & 0 deletions lens4k/src/test/kotlin/dev/forkhandles/lens/MapWrapperTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class MapWrapperTest {

class SubMap(propertySet: Map<String, Any?>) : MapWrapper(propertySet) {
val stringField by Field<String>()
val noSuchField by Field<String>()
}

class MapBacked(propertySet: Map<String, Any?>) : MapWrapper(propertySet) {
Expand Down Expand Up @@ -56,5 +57,6 @@ class MapWrapperTest {
expectThat(mapBacked.objectField.stringField).isEqualTo("string")
expectThrows<NoSuchElementException> { mapBacked.notAStringField }.message.isEqualTo("Value for field <notAStringField> is not a class kotlin.String but class kotlin.Int")
expectThrows<NoSuchElementException> { mapBacked.noSuchField }.message.isEqualTo("Field <noSuchField> is missing")
expectThrows<NoSuchElementException> { mapBacked.objectField.noSuchField }.message.isEqualTo("Field <noSuchField> is missing")
}
}

0 comments on commit b98d5a6

Please sign in to comment.