Add tests for deserialization of collections persisted with kotlin 1.0

This commit is contained in:
Ilya Gorbunov
2016-05-12 20:27:53 +03:00
parent 6a07d5f89c
commit 15dcd3d9f9
@@ -207,6 +207,31 @@ class CollectionJVMTest {
val inputObjectStream = ObjectInputStream(inputStream)
return inputObjectStream.readObject() as T
}
@test fun deserializeEmptyList() = testPersistedDeserialization(
"ac ed 00 05 73 72 00 1c 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 4c 69 73 74 99 6f c7 d0 a7 e0 60 32 02 00 00 78 70",
emptyList<Any>())
@test fun deserializeEmptySet() = testPersistedDeserialization(
"ac ed 00 05 73 72 00 1b 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 53 65 74 2f 46 b0 15 76 d7 e2 f4 02 00 00 78 70",
emptySet<Any>())
@test fun deserializeEmptyMap() = testPersistedDeserialization(
"ac ed 00 05 73 72 00 1b 6b 6f 74 6c 69 6e 2e 63 6f 6c 6c 65 63 74 69 6f 6e 73 2e 45 6d 70 74 79 4d 61 70 72 72 37 71 cb 04 4c d2 02 00 00 78 70",
emptyMap<Any, Any>())
private fun testPersistedDeserialization(hexValue: String, expected: Any) {
val actual = deserializeFromHex<Any>(hexValue)
assertEquals(expected, actual)
}
private fun hexToBytes(value: String): ByteArray = value.split(" ").map { Integer.parseInt(it, 16).toByte() }.toByteArray()
private fun <T> deserializeFromHex(value: String) = hexToBytes(value).let {
val inputStream = ByteArrayInputStream(it)
val inputObjectStream = ObjectInputStream(inputStream)
inputObjectStream.readObject() as T
}
}