]> WPIA git - gigi.git/blob - tests/club/wpia/gigi/TestUserSerialize.java
fix: ResultSet.getDate is often wrong as it fetches day-precision times
[gigi.git] / tests / club / wpia / gigi / TestUserSerialize.java
1 package club.wpia.gigi;
2
3 import static org.junit.Assert.*;
4
5 import java.io.ByteArrayInputStream;
6 import java.io.ByteArrayOutputStream;
7 import java.io.IOException;
8 import java.io.ObjectInputStream;
9 import java.io.ObjectOutputStream;
10
11 import org.junit.Test;
12
13 import club.wpia.gigi.dbObjects.User;
14 import club.wpia.gigi.testUtils.BusinessTest;
15
16 public class TestUserSerialize extends BusinessTest {
17
18     private byte[] serialize(Object o) throws IOException {
19         try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
20             try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
21                 oos.writeObject(o);
22                 oos.flush();
23             }
24             baos.flush();
25             return baos.toByteArray();
26         }
27     }
28
29     private Object deserialize(byte[] ba) throws IOException, ClassNotFoundException {
30         try (ByteArrayInputStream bais = new ByteArrayInputStream(ba)) {
31             try (ObjectInputStream ois = new ObjectInputStream(bais)) {
32                 Object o = ois.readObject();
33                 return o;
34             }
35         }
36     }
37
38     @Test
39     public void testSerializeUser() throws GigiApiException, IOException, ClassNotFoundException {
40         User u = createVerifiedUser();
41         byte[] ba = serialize(u);
42         Object uo = deserialize(ba);
43         assertSame("Original user and the deserialized object must be the same", u, uo);
44     }
45
46 }