Skip to content

Instantly share code, notes, and snippets.

@ramseyboy
Created August 26, 2016 02:52
Show Gist options
  • Save ramseyboy/22a7e0d9019baebaf773253b20aee232 to your computer and use it in GitHub Desktop.
Save ramseyboy/22a7e0d9019baebaf773253b20aee232 to your computer and use it in GitHub Desktop.
class BooleanSerializerSpecs : Spek() { init {
val gson = GsonBuilder()
.registerTypeAdapter(Boolean::class.java, BooleanSerializer())
.create()
given("a valid json string with a boolean field as Y and one as N") {
val json =
"""
{
"yes": "Y",
"no": "N"
}
"""
on("we deserialize the json") {
val boolClass = gson.fromJson(json, BoolClass::class.java)
it("then Y should equal true") {
shouldBeTrue(boolClass)
it("the N should equal false") {
shouldBeFalse(boolClass)
}
}
}
}
given("a valid json string with a boolean field as Y and one as N") {
val json =
"""
{
"yes": true,
"no": false
}
"""
on("we deserialize the json") {
val boolClass = gson.fromJson(json, BoolClass::class.java)
it("then Y should equal true") {
shouldBeTrue(boolClass)
it("the N should equal false") {
shouldBeFalse(boolClass)
}
}
}
}
given("a valid json string with a boolean field as Y and one as N") {
val json =
"""
{
"yes": "true",
"no": "false"
}
"""
on("we deserialize the json") {
val boolClass = gson.fromJson(json, BoolClass::class.java)
it("then Y should equal true") {
shouldBeTrue(boolClass)
it("the N should equal false") {
shouldBeFalse(boolClass)
}
}
}
}
given("a valid json string with a boolean field as Y and one as N") {
val json =
"""
{
"yes": 1,
"no": 0
}
"""
on("we deserialize the json") {
val boolClass = gson.fromJson(json, BoolClass::class.java)
it("then Y should equal true") {
shouldBeTrue(boolClass)
it("the N should equal false") {
shouldBeFalse(boolClass)
}
}
}
}
}
}
data class BoolClass(val yes: Boolean, val no: Boolean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment