Ведь такой тест можно создать. Мне не хватало DefaultSerializationServiceBuilder
, которое может создать SerializationService
Весь тест, написанный на Groovy, выглядит так:
import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals
import java.time.LocalDateTime
import com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder
import com.hazelcast.internal.serialization.impl.ObjectDataInputStream
import com.hazelcast.internal.serialization.impl.ObjectDataOutputStream
import com.hazelcast.spi.serialization.SerializationService
import org.junit.Test
class AuditTest {
@Test
void "serialize and deserialize Audit"() {
def toSerialize = new Audit(createdBy: "me",
createdTimestamp: LocalDateTime.now(),
modifiedBy: "you",
modifiedTimestamp: LocalDateTime.now(),
)
SerializationService serializationService = new DefaultSerializationServiceBuilder().build()
def outputStream = new ByteArrayOutputStream()
def dataOutput = new ObjectDataOutputStream(outputStream, serializationService)
toSerialize.writeData(dataOutput)
def inputStream = new ByteArrayInputStream(outputStream.toByteArray())
def dataInput = new ObjectDataInputStream(inputStream, serializationService)
def toDeserialize = new Audited()
toDeserialize.readData(dataInput)
assert reflectionEquals(toDeserialize, toSerialize)
}
}