public void testExceptionDelegation(){
Persistable persist = new Persistable.Transaction() {
public TransactionResult runQuery(EntityManager em) {
Prefname name = new Prefname("name1");
em.persist(name);
id = name.getId();
String str = null;
str.charAt(0); // NPE
return TransactionResult.COMMIT;
}
};
try{
Utils.processPersistable(persist);
fail("PersistanceException should be thrown");
}catch(PersistenceException exc){
// OK
assertTrue(exc.getCause() instanceof NullPointerException);
}
Persistable query = new Persistable.Query() {
public TransactionResult runQuery(EntityManager em) {
Prefname name = em.find(Prefname.class, id);
assertNull(name);
dataFoundInDb = false;
return null;
}
};