DOCS: Serialization roundtrip removes mutability explanation (#2883)

* DOCS: Serialization roundtrip removes mutability explanation

* review comments

* review comments

* Review comments

* Review comments

* Review comments
This commit is contained in:
Katelyn Baker
2018-03-27 20:21:40 +01:00
committed by GitHub
parent de40d1dae5
commit 8431616b87
2 changed files with 139 additions and 0 deletions

View File

@ -0,0 +1,60 @@
package net.corda.nodeapi.internal.serialization.amqp
import net.corda.core.serialization.ConstructorForDeserialization
import org.assertj.core.api.Assertions
import org.junit.Test
class RoundTripTests {
@Test
fun mutableBecomesImmutable() {
data class C(val l : MutableList<String>)
val factory = testDefaultFactoryNoEvolution()
val bytes = SerializationOutput(factory).serialize(C(mutableListOf ("a", "b", "c")))
val newC = DeserializationInput(factory).deserialize(bytes)
Assertions.assertThatThrownBy {
newC.l.add("d")
}.isInstanceOf(UnsupportedOperationException::class.java)
}
@Test
fun mutableStillMutable() {
class C {
val l : MutableList<String>
@Suppress("Unused")
constructor (l : MutableList<String>) {
this.l = l.toMutableList()
}
}
val factory = testDefaultFactoryNoEvolution()
val bytes = SerializationOutput(factory).serialize(C(mutableListOf ("a", "b", "c")))
val newC = DeserializationInput(factory).deserialize(bytes)
newC.l.add("d")
}
@Test
fun mutableStillMutable2() {
data class C (val l : MutableList<String>){
@ConstructorForDeserialization
@Suppress("Unused")
constructor (l : Collection<String>) : this (l.toMutableList())
}
val factory = testDefaultFactoryNoEvolution()
val bytes = SerializationOutput(factory).serialize(C(mutableListOf ("a", "b", "c")))
val newC = DeserializationInput(factory).deserialize(bytes)
newC.l.add("d")
}
@Test
fun mutableBecomesImmutable4() {
data class C(val l : List<String>)
val factory = testDefaultFactoryNoEvolution()
val bytes = SerializationOutput(factory).serialize(C(listOf ("a", "b", "c")))
val newC = DeserializationInput(factory).deserialize(bytes)
val newC2 = newC.copy (l = (newC.l + "d"))
}
}