1 package org.cacert.gigi;
3 import static org.junit.Assert.*;
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;
11 import org.cacert.gigi.dbObjects.User;
12 import org.cacert.gigi.testUtils.BusinessTest;
13 import org.junit.Test;
15 public class TestUserSerialize extends BusinessTest {
17 private byte[] serialize(Object o) throws IOException {
18 try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
19 try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
24 return baos.toByteArray();
28 private Object deserialize(byte[] ba) throws IOException, ClassNotFoundException {
29 try (ByteArrayInputStream bais = new ByteArrayInputStream(ba)) {
30 try (ObjectInputStream ois = new ObjectInputStream(bais)) {
31 Object o = ois.readObject();
38 public void testSerializeUser() throws GigiApiException, IOException, ClassNotFoundException {
39 User u = createVerifiedUser();
40 byte[] ba = serialize(u);
41 Object uo = deserialize(ba);
42 assertSame("Original user and the deserialized object must be the same", u, uo);