### Question:
RequiresNewTransactionInterceptor extends RequiredTransactionInterceptor { @AroundInvoke public Object applyTransaction(InvocationContext ic) throws Exception { TransactionManager transactionManager = null; Transaction transaction = null; if (isTransactionActive()) { transactionManager = getTransactionManager(); transaction = transactionManager.suspend(); } try { return super.applyTransaction(ic); } finally { if (transactionManager != null && transaction != null) { transactionManager.resume(transaction); } } }  @AroundInvoke Object applyTransaction(InvocationContext ic);  }### Answer:
@Test(expected = ApplicationException.class) public void beginAndCommitTransaction() throws Exception { transactionFactory.expectNoTransaction(); transactionFactory.expectBeginTransaction(); transactionFactory.expectCommitTransaction(); transactionFactory.replay(); try { InvocationContext ic = createNiceMock(InvocationContext.class); expect(ic.proceed()).andThrow(new ApplicationException()); replay(ic); interceptor.applyTransaction(ic); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof Error) { throw (Error) e.getTargetException(); } else { throw (Exception) e.getTargetException(); } } finally { transactionFactory.verify(); } }
@Test(expected = ApplicationRuntimeException.class) public void beginAndRollbackTransaction() throws Exception { transactionFactory.expectNoTransaction(); transactionFactory.expectBeginTransaction(); transactionFactory.expectSetRollbackOnly(); transactionFactory.expectRollbackTransaction(); transactionFactory.replay(); try { InvocationContext ic = createNiceMock(InvocationContext.class); expect(ic.proceed()).andThrow(new ApplicationRuntimeException()); replay(ic); interceptor.applyTransaction(ic); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof Error) { throw (Error) e.getTargetException(); } else { throw (Exception) e.getTargetException(); } } finally { transactionFactory.verify(); } }
@Test(expected = ApplicationException.class) public void beginAndCommitNewTransaction() throws Exception { transactionFactory.expectActiveTransaction(); transactionFactory.expectSuspendTransaction(); transactionFactory.expectBeginTransaction(); transactionFactory.expectCommitTransaction(); transactionFactory.expectResumeTransaction(); transactionFactory.replay(); try { InvocationContext ic = createNiceMock(InvocationContext.class); expect(ic.proceed()).andThrow(new ApplicationException()); replay(ic); interceptor.applyTransaction(ic); } finally { transactionFactory.verify(); } }
@Test(expected = ApplicationRuntimeException.class) public void beginAndRollbackNewTransaction() throws Exception { transactionFactory.expectActiveTransaction(); transactionFactory.expectSuspendTransaction(); transactionFactory.expectBeginTransaction(); transactionFactory.expectSetRollbackOnly(); transactionFactory.expectRollbackTransaction(); transactionFactory.expectResumeTransaction(); transactionFactory.replay(); try { InvocationContext ic = createNiceMock(InvocationContext.class); expect(ic.proceed()).andThrow(new ApplicationRuntimeException()); replay(ic); interceptor.applyTransaction(ic); } finally { transactionFactory.verify(); } }