mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-02 09:09:37 +00:00
Added serialization test for CopyOnWriteHashMap
This commit is contained in:
1 parent
0d971f3681
commit
57134c57f7
1 file changed
+44
+44
@@ -0,0 +1,44 @@
|
||||
package com.sap.sailing.domain.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sse.concurrent.CopyOnWriteHashMap;
|
||||
|
||||
public class CopyOnWriteHashMapSerializationTest {
|
||||
|
||||
private CopyOnWriteHashMap<String, String> expected;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
expected = new CopyOnWriteHashMap<>();
|
||||
expected.put("a", "1");
|
||||
expected.put("b", "2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerializationOfCopyOnWriteHashMap() throws IOException, ClassNotFoundException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream ous = new ObjectOutputStream(baos);
|
||||
ous.writeObject(expected);
|
||||
ous.close();
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
CopyOnWriteHashMap<String, String> deserializedInstance = (CopyOnWriteHashMap<String, String>) ois.readObject();
|
||||
assertEquals(expected, deserializedInstance);
|
||||
|
||||
assertEquals(-1, ois.read(new byte[1]));
|
||||
ois.close();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user