Transaction { public void commit() { if (!isCommitted()) { Account<T> withdrawalAccount = withdrawalEntry.getAccount(); Account<T> depositAccount = depositEntry.getAccount(); withdrawalAccount.addEntry(withdrawalEntry); depositAccount.addEntry(depositEntry); } else { throw new IllegalStateException("Should not commit more than once."); } } Transaction(T withdrawalEntry, T depositEntry); void commit(); boolean isCommitted(); @Override String toString();  }
@Test public void testBalanceAfterAdd() { Account<DefaultEntry> account1 = new Account<DefaultEntry>(); Account<DefaultEntry> account2 = new Account<DefaultEntry>(); DateTime then = new DateTime(2000, 1, 2, 12, 34, 56, 0); DefaultEntry w1 = new DefaultEntry(account1, -10, then, then); DefaultEntry d1 = new DefaultEntry(account2, 10, then, then); Transaction<DefaultEntry> tx = new Transaction<DefaultEntry>(w1, d1); tx.commit(); assertThat(account1.getBalance(), equalTo(-10L)); assertThat(account2.getBalance(), equalTo(10L)); }