Created
August 26, 2016 02:52
-
-
Save ramseyboy/22a7e0d9019baebaf773253b20aee232 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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