CORDA-939 Make SerializationEnvironmentRule.env private so as not to expose internals. (#2404)

* Make SerializationEnvironment private so as not to expose internals.

* Only expose used parts of api

* Make properties lateinit

* Removing java calls to getEnv

* Initialise properties at declaration

* Tidy up imports
This commit is contained in:
Anthony Keenan 2018-01-23 14:42:30 +00:00 committed by GitHub
parent 443afb3515
commit 70f1fdeb2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 9 deletions

View File

@ -25,7 +25,7 @@ public final class ForbiddenLambdaSerializationTests {
@Before @Before
public void setup() { public void setup() {
factory = testSerialization.getEnv().getSerializationFactory(); factory = testSerialization.getSerializationFactory();
} }
@Test @Test

View File

@ -25,7 +25,7 @@ public final class LambdaCheckpointSerializationTest {
@Before @Before
public void setup() { public void setup() {
factory = testSerialization.getEnv().getSerializationFactory(); factory = testSerialization.getSerializationFactory();
context = new SerializationContextImpl(KryoSerializationSchemeKt.getKryoHeaderV0_1(), this.getClass().getClassLoader(), AllWhitelist.INSTANCE, Maps.newHashMap(), true, SerializationContext.UseCase.Checkpoint); context = new SerializationContextImpl(KryoSerializationSchemeKt.getKryoHeaderV0_1(), this.getClass().getClassLoader(), AllWhitelist.INSTANCE, Maps.newHashMap(), true, SerializationContext.UseCase.Checkpoint);
} }

View File

@ -25,10 +25,11 @@ class ContractAttachmentSerializerTest {
private lateinit var context: SerializationContext private lateinit var context: SerializationContext
private lateinit var contextWithToken: SerializationContext private lateinit var contextWithToken: SerializationContext
private val mockServices = MockServices(emptyList(), rigorousMock(), CordaX500Name("MegaCorp", "London", "GB")) private val mockServices = MockServices(emptyList(), rigorousMock(), CordaX500Name("MegaCorp", "London", "GB"))
@Before @Before
fun setup() { fun setup() {
factory = testSerialization.env.serializationFactory factory = testSerialization.serializationFactory
context = testSerialization.env.checkpointContext context = testSerialization.checkpointContext
contextWithToken = context.withTokenContext(SerializeAsTokenContextImpl(Any(), factory, context, mockServices)) contextWithToken = context.withTokenContext(SerializeAsTokenContextImpl(Any(), factory, context, mockServices))
} }

View File

@ -25,8 +25,8 @@ class SerializationTokenTest {
@Before @Before
fun setup() { fun setup() {
factory = testSerialization.env.serializationFactory factory = testSerialization.serializationFactory
context = testSerialization.env.checkpointContext.withWhitelisted(SingletonSerializationToken::class.java) context = testSerialization.checkpointContext.withWhitelisted(SingletonSerializationToken::class.java)
} }
// Large tokenizable object so we can tell from the smaller number of serialized bytes it was actually tokenized // Large tokenizable object so we can tell from the smaller number of serialized bytes it was actually tokenized

View File

@ -1,10 +1,16 @@
package net.corda.testing.core package net.corda.testing.core
import com.nhaarman.mockito_kotlin.* import com.nhaarman.mockito_kotlin.any
import com.nhaarman.mockito_kotlin.doAnswer
import com.nhaarman.mockito_kotlin.doNothing
import com.nhaarman.mockito_kotlin.whenever
import net.corda.client.rpc.internal.KryoClientSerializationScheme import net.corda.client.rpc.internal.KryoClientSerializationScheme
import net.corda.core.DoNotImplement import net.corda.core.DoNotImplement
import net.corda.core.internal.staticField import net.corda.core.internal.staticField
import net.corda.core.serialization.internal.* import net.corda.core.serialization.internal.SerializationEnvironment
import net.corda.core.serialization.internal.SerializationEnvironmentImpl
import net.corda.core.serialization.internal._globalSerializationEnv
import net.corda.core.serialization.internal.effectiveSerializationEnv
import net.corda.node.serialization.KryoServerSerializationScheme import net.corda.node.serialization.KryoServerSerializationScheme
import net.corda.nodeapi.internal.serialization.* import net.corda.nodeapi.internal.serialization.*
import net.corda.nodeapi.internal.serialization.amqp.AMQPClientSerializationScheme import net.corda.nodeapi.internal.serialization.amqp.AMQPClientSerializationScheme
@ -42,7 +48,10 @@ class SerializationEnvironmentRule(private val inheritable: Boolean = false) : T
} }
} }
lateinit var env: SerializationEnvironment private lateinit var env: SerializationEnvironment
val serializationFactory get() = env.serializationFactory
val checkpointContext get() = env.checkpointContext
override fun apply(base: Statement, description: Description): Statement { override fun apply(base: Statement, description: Description): Statement {
init(description.toString()) init(description.toString())
return object : Statement() { return object : Statement() {