Skip to content

Commit 40a5289

Browse files
ngonzalezpazFCjavier-godoy
authored andcommitted
test: add serialization test
Add javax.servlet-api dependency to pom
1 parent 2c5afa7 commit 40a5289

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@
131131
<version>3.0.0</version>
132132
<scope>test</scope>
133133
</dependency>
134+
<dependency>
135+
<groupId>javax.servlet</groupId>
136+
<artifactId>javax.servlet-api</artifactId>
137+
<version>3.1.0</version>
138+
<type>jar</type>
139+
<scope>test</scope>
140+
</dependency>
134141
</dependencies>
135142

136143
<build>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*-
2+
* #%L
3+
* ChipField Addon
4+
* %%
5+
* Copyright (C) 2018 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.chipfield.test;
21+
22+
import com.flowingcode.vaadin.addons.chipfield.ChipField;
23+
import java.io.ByteArrayInputStream;
24+
import java.io.ByteArrayOutputStream;
25+
import java.io.IOException;
26+
import java.io.ObjectInputStream;
27+
import java.io.ObjectOutputStream;
28+
import org.junit.Test;
29+
30+
public class SerializationTest {
31+
32+
private void testSerializationOf(Object obj) throws IOException, ClassNotFoundException {
33+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
34+
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
35+
oos.writeObject(obj);
36+
}
37+
try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
38+
obj.getClass().cast(in.readObject());
39+
}
40+
}
41+
42+
@Test
43+
public void testSerialization() throws ClassNotFoundException, IOException {
44+
testSerializationOf(new ChipField<>("Label", "Item1", "Item2", "Item3"));
45+
}
46+
47+
}

0 commit comments

Comments
 (0)