Answer 11: Testing I/O
public void testSerialization() throws IOException, ClassNotFoundException {
Fraction source = new Fraction(1, 2);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(out);
oout.writeObject(source);
oout.close();
byte[] data = out.toByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(data);
ObjectInputStream oin = new ObjectInputStream(in);
Fraction result = (Fraction) oin.readObject();
assertEquals(source, result);
assertNotSame(source, result);
}