Skip to content

Commit 3b7ff7f

Browse files
committed
test: add SerializationTest
1 parent e291ee9 commit 3b7ff7f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
<version>1.3</version>
111111
<scope>test</scope>
112112
</dependency>
113+
<dependency>
114+
<groupId>javax.servlet</groupId>
115+
<artifactId>javax.servlet-api</artifactId>
116+
<version>3.1.0</version>
117+
<scope>provided</scope>
118+
</dependency>
113119
</dependencies>
114120

115121
<build>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.flowingcode.addons.applayout.test;
2+
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.IOException;
6+
import java.io.ObjectInputStream;
7+
import java.io.ObjectOutputStream;
8+
9+
import org.junit.Test;
10+
11+
import com.flowingcode.addons.applayout.AppLayout;
12+
import com.flowingcode.addons.applayout.MenuItem;
13+
14+
public class SerializationTest {
15+
16+
private void testSerializationOf(Object obj) throws IOException, ClassNotFoundException {
17+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
18+
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
19+
oos.writeObject(obj);
20+
}
21+
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
22+
obj.getClass().cast(in.readObject());
23+
}
24+
}
25+
26+
@Test
27+
public void testSerialization() throws ClassNotFoundException, IOException {
28+
AppLayout appLayout = new AppLayout("");
29+
appLayout.setMenuItems(new MenuItem("Item", () -> {}));
30+
testSerializationOf(appLayout);
31+
}
32+
33+
}

0 commit comments

Comments
 (0)