{
Author author = new Author();
author.setName(AUTHOR_1_NAME);
author.setAuthorId(AUTHOR_1_ID);
AuthorBean authorBean = author.getBean();
// serialize the AuthorBean
byte[] serializedAuthorBean;
{
ObjectOutputStream objectOutputStream = null;
ByteArrayOutputStream byteArrayOutputStream;
try
{
byteArrayOutputStream
= new ByteArrayOutputStream();
objectOutputStream
= new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(authorBean);
serializedAuthorBean
= byteArrayOutputStream.toByteArray();
}
finally
{
if (objectOutputStream != null)
{
objectOutputStream.close();
}
}
}
// deserialize the AuthorBean again
AuthorBean deserializedAuthorBean;
{
ObjectInputStream objectInputStream = null;
ByteArrayInputStream byteArrayInputStream = null;
try
{
byteArrayInputStream
= new ByteArrayInputStream(serializedAuthorBean);
objectInputStream
= new ObjectInputStream(byteArrayInputStream);
deserializedAuthorBean
= (AuthorBean) objectInputStream.readObject();
}
finally
{
if (byteArrayInputStream != null)
{
byteArrayInputStream.close();
}
}
}
assertEquals("The Name of the deserialized AuthorBean, "
+ " should equal the Name of AuthorBean",
deserializedAuthorBean.getName(), authorBean.getName());
assertEquals("The Id of the deserialized AuthorBean, "
+ " should equal the Id of AuthorBean",
deserializedAuthorBean.getAuthorId(), authorBean.getAuthorId());
}