/**
* The test checks that encoder can handle writeExpression in initialize
*/
public void testEncodeExpressionAsStatement() {
XMLEncoder e = new XMLEncoder(System.out);
e.setExceptionListener(new ExceptionListener() {
public void exceptionThrown(Exception e) {
fail("Exception " + e.getClass() + " is thrown: "
+ e.getMessage());
}
});
try {
final Object object = new Object();
e.setPersistenceDelegate(AType.class,
new DefaultPersistenceDelegate() {
@SuppressWarnings("unchecked")
@Override
protected void initialize(Class type,
Object oldInstance, Object newInstance,
Encoder out) {
out.writeExpression(new Expression(object,
oldInstance, "go", new Object[] {}));
}
});
AType a = new AType();
// e.writeObject(object);
e.writeObject(a);
e.writeObject(object);
} finally {
e.close();
}
}