BankingService { @Compensatable public void transferMoney(String fromAccount, String toAccount, Double amount) { accountManager.debitAccount(fromAccount, amount); accountManager.creditAccount(toAccount, amount); }  @Compensatable void transferMoney(String fromAccount, String toAccount, Double amount);  }
@Test public void testSuccess() throws Exception { bankingService.transferMoney("A", "B", 100.0); assertBalance("A", 900.0); assertBalance("B", 1100.0); }
@Test public void testFailure() throws Exception { try { bankingService.transferMoney("A", "B", 600.0); Assert.fail("Expected a TransactionCompensatedException to be thrown"); } catch (TransactionCompensatedException e) { } assertBalance("A", 1000.0); assertBalance("B", 1000.0); }