Source:
<code>public void testDuplicateXAREndCalled() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException { javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); tm.begin(); javax.transaction.Transaction theTransaction = tm.getTransaction(); AtomicBoolean endCalled = new AtomicBoolean(false); assertTrue(theTransaction.enlistResource(new SimpleXAResource() { public int id = 1; @Override public boolean isSameRM(XAResource xares) throws XAException { try { Class<? extends XAResource> aClass = xares.getClass(); Field field = aClass.getField("id"); int other = field.getInt(xares); if (other == 1) { return true; } } catch (NoSuchFieldException | IllegalAccessException e) { fail("Unexpected XAR"); } return false; } @Override public void start(Xid xid, int flags) throws XAException { System.out.println(this + "start" + flags); super.start(xid, flags); } @Override public void end(Xid xid, int flags) throws XAException { System.out.println(this + "end" + flags); super.end(xid, flags); } })); assertTrue(theTransaction.enlistResource(new SimpleXAResource() { public int id = 1; @Override public boolean isSameRM(XAResource xares) throws XAException { try { Field field = xares.getClass().getField("id"); int other = field.getInt(xares); if (other == 1) { return true; } } catch (NoSuchFieldException | IllegalAccessException e) { fail("Unexpected XAR"); } return false; } @Override public void start(Xid xid, int flags) throws XAException { System.out.println(this + "start" + flags); super.start(xid, flags); } @Override public void end(Xid xid, int flags) throws XAException { endCalled.set(true); System.out.println(this + "end" + flags); super.end(xid, flags); } })); assertTrue(theTransaction.enlistResource(new SimpleXAResource() { public int id = 2; @Override public boolean isSameRM(XAResource xares) throws XAException { return false; } })); tm.commit(); <START> assertTrue(endCalled.get()); <END> }</code><technical_language>asserting end called resources (ie including duplicate)</technical_language>

Target:
public void testDuplicateXAREndCalled() throws SystemException, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException { javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager(); tm.begin(); javax.transaction.Transaction theTransaction = tm.getTransaction(); AtomicBoolean endCalled = new AtomicBoolean(false); assertTrue(theTransaction.enlistResource(new SimpleXAResource() { public int id = 1; @Override public boolean isSameRM(XAResource xares) throws XAException { try { Class<? extends XAResource> aClass = xares.getClass(); Field field = aClass.getField("id"); int other = field.getInt(xares); if (other == 1) { return true; } } catch (NoSuchFieldException | IllegalAccessException e) { fail("Unexpected XAR"); } return false; } @Override public void start(Xid xid, int flags) throws XAException { super.start(xid, flags); } @Override public void end(Xid xid, int flags) throws XAException { super.end(xid, flags); } })); assertTrue(theTransaction.enlistResource(new SimpleXAResource() { public int id = 1; @Override public boolean isSameRM(XAResource xares) throws XAException { try { Field field = xares.getClass().getField("id"); int other = field.getInt(xares); if (other == 1) { return true; } } catch (NoSuchFieldException | IllegalAccessException e) { fail("Unexpected XAR"); } return false; } @Override public void start(Xid xid, int flags) throws XAException { super.start(xid, flags); } @Override public void end(Xid xid, int flags) throws XAException { endCalled.set(true); super.end(xid, flags); } })); assertTrue(theTransaction.enlistResource(new SimpleXAResource() { public int id = 2; @Override public boolean isSameRM(XAResource xares) throws XAException { return false; } })); tm.commit(); assertTrue(endCalled.get()); }