public void testSerialization() {
final TextBlock b1 = new TextBlock();
b1.addLine(new TextLine("Test"));
TextBlock b2 = null;
try {
final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
final ObjectOutput out = new ObjectOutputStream(buffer);
out.writeObject(b1);
out.close();
final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
b2 = (TextBlock) in.readObject();
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertEquals(b1, b2);
}
Serialize an instance, restore it, and check for equality. |