diff --git a/core/src/test/java/net/corda/core/flows/SerializationApiInJavaTest.java b/core/src/test/java/net/corda/core/flows/SerializationApiInJavaTest.java new file mode 100644 index 0000000000..07bec4bb79 --- /dev/null +++ b/core/src/test/java/net/corda/core/flows/SerializationApiInJavaTest.java @@ -0,0 +1,37 @@ +package net.corda.core.flows; + +import net.corda.core.serialization.SerializationDefaults; +import net.corda.core.serialization.SerializationFactory; +import net.corda.testing.SerializationEnvironmentRule; +import org.junit.Rule; +import org.junit.Test; + +import static net.corda.core.serialization.SerializationAPIKt.serialize; +import static org.junit.Assert.assertNull; + +/** + * Enforce parts of the serialization API that aren't obvious from looking at the {@link net.corda.core.serialization.SerializationAPIKt} code. + */ +public class SerializationApiInJavaTest { + @Rule + public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); + + @Test + public void enforceSerializationFactoryApi() { + assertNull(SerializationFactory.Companion.getCurrentFactory()); + SerializationFactory factory = SerializationFactory.Companion.getDefaultFactory(); + assertNull(factory.getCurrentContext()); + serialize("hello", factory, factory.getDefaultContext()); + } + + @Test + public void enforceSerializationDefaultsApi() { + SerializationDefaults defaults = SerializationDefaults.INSTANCE; + SerializationFactory factory = defaults.getSERIALIZATION_FACTORY(); + serialize("hello", factory, defaults.getP2P_CONTEXT()); + serialize("hello", factory, defaults.getRPC_SERVER_CONTEXT()); + serialize("hello", factory, defaults.getRPC_CLIENT_CONTEXT()); + serialize("hello", factory, defaults.getSTORAGE_CONTEXT()); + serialize("hello", factory, defaults.getCHECKPOINT_CONTEXT()); + } +} diff --git a/node-api/src/test/java/net/corda/nodeapi/internal/serialization/ForbiddenLambdaSerializationTests.java b/node-api/src/test/java/net/corda/nodeapi/internal/serialization/ForbiddenLambdaSerializationTests.java index ba452d138c..0cb878ff49 100644 --- a/node-api/src/test/java/net/corda/nodeapi/internal/serialization/ForbiddenLambdaSerializationTests.java +++ b/node-api/src/test/java/net/corda/nodeapi/internal/serialization/ForbiddenLambdaSerializationTests.java @@ -20,7 +20,7 @@ import static org.assertj.core.api.ThrowableAssert.catchThrowable; public final class ForbiddenLambdaSerializationTests { @Rule - public SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); + public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); private SerializationFactory factory; @Before diff --git a/node-api/src/test/java/net/corda/nodeapi/internal/serialization/LambdaCheckpointSerializationTest.java b/node-api/src/test/java/net/corda/nodeapi/internal/serialization/LambdaCheckpointSerializationTest.java index 93156d1073..62a71ff630 100644 --- a/node-api/src/test/java/net/corda/nodeapi/internal/serialization/LambdaCheckpointSerializationTest.java +++ b/node-api/src/test/java/net/corda/nodeapi/internal/serialization/LambdaCheckpointSerializationTest.java @@ -19,7 +19,7 @@ import static org.assertj.core.api.ThrowableAssert.catchThrowable; public final class LambdaCheckpointSerializationTest { @Rule - public SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); + public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); private SerializationFactory factory; private SerializationContext context; diff --git a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java index a7ff598d38..8f817167bf 100644 --- a/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java +++ b/node/src/test/java/net/corda/node/services/vault/VaultQueryJavaTests.java @@ -35,7 +35,7 @@ import static org.assertj.core.api.Assertions.*; public class VaultQueryJavaTests { @Rule - public SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); + public final SerializationEnvironmentRule testSerialization = new SerializationEnvironmentRule(); private MockServices services; private MockServices issuerServices; private VaultService vaultService;