Make Netty-3 dependency optional
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / persisted / AbstractIdentifiablePayloadTest.java
index 2ff9a915ce6e8ed9480f64b2641b72e44cc6ab67..5b82a478a74973dc1c2786302586af5296f5ae39 100644 (file)
@@ -7,19 +7,27 @@
  */
 package org.opendaylight.controller.cluster.datastore.persisted;
 
+import static java.util.Objects.requireNonNull;
+import static org.junit.Assert.assertEquals;
+
 import org.apache.commons.lang3.SerializationUtils;
-import org.junit.Assert;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.datastore.AbstractTest;
 
-abstract class AbstractIdentifiablePayloadTest<T extends AbstractIdentifiablePayload> extends AbstractTest {
+abstract class AbstractIdentifiablePayloadTest<T extends AbstractIdentifiablePayload<?>> extends AbstractTest {
+    private final T object;
+    private final int expectedSize;
 
-    abstract T object();
+    AbstractIdentifiablePayloadTest(final T object, final int expectedSize) {
+        this.object = requireNonNull(object);
+        this.expectedSize = expectedSize;
+    }
 
     @Test
     public void testSerialization() {
-        final T object = object();
-        final T cloned = SerializationUtils.clone(object);
-        Assert.assertEquals(object.getIdentifier(), cloned.getIdentifier());
+        final byte[] bytes = SerializationUtils.serialize(object);
+        assertEquals(expectedSize, bytes.length);
+        final T cloned = SerializationUtils.deserialize(bytes);
+        assertEquals(object.getIdentifier(), cloned.getIdentifier());
     }
 }