package com.kryptnostic.rhizome.hazelcast.serializers;

import com.hazelcast.internal.serialization.InternalSerializationService;
import com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder;
import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Test;

public abstract class AbstractStreamSerializerTest<T extends StreamSerializer<D>, D> {

    private final transient T serializer;
    private final transient T deserializer;

    public AbstractStreamSerializerTest() {
        serializer = createSerializer();
        deserializer = createDeserializer();
    }

    protected abstract T createSerializer();

    /**
     * Override this class when deserializer is expected to deal with encrypted data.
     */
    protected T createDeserializer() {
        return serializer;
    }

    protected abstract D createInput();

    @Test
    public void testSerializeDeserialize() throws SecurityException, IOException {

        D inputObject = createInput();
        InternalSerializationService ss = ( new DefaultSerializationServiceBuilder() ).build();

        ObjectDataOutput dataOut = ss.createObjectDataOutput( 1 );

        serializer.write( dataOut, inputObject );

        byte[] inputData = dataOut.toByteArray();

        ObjectDataInput dataIn = ss.createObjectDataInput( inputData );

        D outputObject = deserializer.read( dataIn );
        if ( inputObject instanceof Object[] || outputObject instanceof Object[] ) {
            Assert.assertArrayEquals( (Object[]) inputObject, (Object[]) outputObject );
        } else {
            Assert.assertEquals( inputObject, outputObject );
        }
    }

}

@@ -378,16 +378,61 @@
 eption;%0A
+import javax.validation.constraints.NotNull;%0A
 import o
@@ -1764,24 +1764,172 @@
  else %7B%0A    
+        testOutput( inputObject, outputObject );%0A        %7D%0A    %7D%0A%0A    public void testOutput( @NotNull  D inputObject, @NotNull  D outputObject ) %7B%0A
         Asse
@@ -1970,31 +1970,21 @@
 utObject );%0A
-        %7D%0A
     %7D%0A%0A%7D%0A

Add custom output testing to stream serializer test.