mirror of
https://github.com/corda/corda.git
synced 2025-04-12 21:53:17 +00:00
CORDA-540: Tighten-up the unit test to prevent concrete collection classes to be used
This commit is contained in:
parent
cac2465ea5
commit
349692f831
@ -1,11 +1,15 @@
|
||||
package net.corda.nodeapi.internal.serialization
|
||||
|
||||
import net.corda.core.serialization.CordaSerializable
|
||||
import net.corda.core.serialization.SerializedBytes
|
||||
import net.corda.core.serialization.deserialize
|
||||
import net.corda.core.serialization.serialize
|
||||
import net.corda.node.services.statemachine.SessionData
|
||||
import net.corda.testing.TestDependencyInjectionBase
|
||||
import net.corda.testing.amqpSpecific
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.junit.Test
|
||||
import java.io.NotSerializableException
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class ListsSerializationTest : TestDependencyInjectionBase() {
|
||||
@ -30,6 +34,19 @@ class ListsSerializationTest : TestDependencyInjectionBase() {
|
||||
}
|
||||
}
|
||||
|
||||
@CordaSerializable
|
||||
data class WrongPayloadType(val payload: ArrayList<Int>)
|
||||
|
||||
@Test
|
||||
fun `check throws for forbidden declared type`() = amqpSpecific<ListsSerializationTest>("Such exceptions are not expected in Kryo mode.") {
|
||||
val payload = ArrayList<Int>()
|
||||
payload.add(1)
|
||||
payload.add(2)
|
||||
val wrongPayloadType = WrongPayloadType(payload)
|
||||
Assertions.assertThatThrownBy { wrongPayloadType.serialize() }
|
||||
.isInstanceOf(NotSerializableException::class.java).hasMessageContaining("Cannot derive collection type for declaredType")
|
||||
}
|
||||
|
||||
private inline fun<reified T : Any> assertEqualAfterRoundTripSerialization(obj: T) {
|
||||
|
||||
val serializedForm: SerializedBytes<T> = obj.serialize()
|
||||
|
@ -162,4 +162,10 @@ inline fun <reified T : Any> kryoSpecific(reason: String, function: () -> Unit)
|
||||
function()
|
||||
} else {
|
||||
loggerFor<T>().info("Ignoring Kryo specific test, reason: $reason" )
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> amqpSpecific(reason: String, function: () -> Unit) = if(AMQP_ENABLED) {
|
||||
function()
|
||||
} else {
|
||||
loggerFor<T>().info("Ignoring AMQP specific test, reason: $reason" )
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user