@Test
public void testJavaSerialiazation() throws Exception {

    Block block = new Block(params, blockBytes);
    Transaction tx = block.transactions.get(1);
    // Serialize using Java.
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(tx);
    oos.close();
    byte[] javaBits = bos.toByteArray();
    // Deserialize again.
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(javaBits));
    Transaction tx2 = (Transaction) ois.readObject();
    ois.close();
    // Note that this will actually check the transactions are equal by doing bitcoin serialization and checking
    // the bytestreams are the same! A true "deep equals" is not implemented for Transaction. The primary purpose
    // of this test is to ensure no errors occur during the Java serialization/deserialization process.
    assertEquals(tx, tx2);
}