Skip to content

Commit e08ad23

Browse files
ngonzalezpazFCjavier-godoy
authored andcommitted
test: add serialization test
Add javax.servlet-api dependency to pom
1 parent 878b00d commit e08ad23

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@
120120
<version>2.1.0-SNAPSHOT</version>
121121
<scope>test</scope>
122122
</dependency>
123+
<dependency>
124+
<groupId>javax.servlet</groupId>
125+
<artifactId>javax.servlet-api</artifactId>
126+
<version>3.1.0</version>
127+
<type>jar</type>
128+
<scope>test</scope>
129+
</dependency>
123130
</dependencies>
124131

125132
<build>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* #%L
3+
* Simple Timer Addon
4+
* %%
5+
* Copyright (C) 2019 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.addons.simpletimer.test;
21+
22+
import java.io.ByteArrayInputStream;
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.IOException;
25+
import java.io.ObjectInputStream;
26+
import java.io.ObjectOutputStream;
27+
28+
import org.junit.Test;
29+
30+
import com.flowingcode.vaadin.addons.simpletimer.SimpleTimer;
31+
32+
public class SerializationTest {
33+
34+
private void testSerializationOf(Object obj) throws IOException, ClassNotFoundException {
35+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
36+
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
37+
oos.writeObject(obj);
38+
}
39+
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
40+
obj.getClass().cast(in.readObject());
41+
}
42+
}
43+
44+
@Test
45+
public void testSerialization() throws ClassNotFoundException, IOException {
46+
testSerializationOf(new SimpleTimer());
47+
}
48+
49+
}

0 commit comments

Comments
 (0)