Skip to content

Commit

Permalink
add test case for Github #56
Browse files Browse the repository at this point in the history
  • Loading branch information
apatrida committed Feb 9, 2017
1 parent afbc64f commit 1cac718
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.fasterxml.jackson.module.kotlin.test

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonUnwrapped
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException
import com.fasterxml.jackson.module.kotlin.*
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals

private data class TestGalleryWidget_BAD(
val widgetReferenceId: String,
@JsonUnwrapped var gallery: TestGallery
)

private data class TestGalleryWidget_GOOD(val widgetReferenceId: String) {
@JsonUnwrapped lateinit var gallery: TestGallery
}


@JsonInclude(JsonInclude.Include.NON_EMPTY)
private data class TestGallery(
val id: String? = null,
val headline: String? = null,
val intro: String? = null,
val role: String? = null,
val images: List<TestImage>? = null
)

@JsonInclude(JsonInclude.Include.NON_EMPTY)
private data class TestImage(
val id: String? = null,
val escenicId: String? = null,
val caption: String? = null,
val copyright: String? = null,
val crops: Map<String, String>? = null
)

class Github56 {
lateinit var mapper: ObjectMapper

private val gallery = TestGallery(
id = "id",
headline = "headline",
intro = "intro",
role = "role",
images = listOf(
TestImage(id = "testImage1"),
TestImage(id = "testImage2")
)
)
val validJson = """
{"widgetReferenceId":"widgetReferenceId","id":"id","headline":"headline","intro":"intro","role":"role","images":[{"id":"testImage1"},{"id":"testImage2"}]}
""".trim()

@Before
fun setUp() {
mapper = jacksonObjectMapper()
}

@Test
fun serializes() {
val result = mapper.writeValueAsString(TestGalleryWidget_BAD("widgetReferenceId", gallery))
assertEquals(validJson, result)
}

@Test(expected = InvalidDefinitionException::class)
fun deserializesWithError() {
mapper.readValue<TestGalleryWidget_BAD>(validJson)
}

@Test
fun deserializesCorrectly() {
mapper.readValue<TestGalleryWidget_GOOD>(validJson)
}
}

0 comments on commit 1cac718

Please sign in to comment.