MemoPostingRule implements PostingRule<T> { @Override public void reverse(T sourceEntry) { T targetEntry = sourceEntry.newInstance(targetAccount, -sourceEntry.getAmount(), sourceEntry.getWhenCreated(), sourceEntry.getWhenBooked()); SingleEntryTransaction<T> transaction = new SingleEntryTransaction<T>(targetEntry); transaction.commit(); } MemoPostingRule(Account<T> targetAccount); @Override void apply(T sourceEntry); @Override void reverse(T sourceEntry);  }
@Test public void testReverse() { Account<DefaultEntry> sourceAccount = new Account<DefaultEntry>(); Account<DefaultEntry> targetAccount = new Account<DefaultEntry>(); Account<DefaultEntry> memoAccount = new Account<DefaultEntry>(); testObject = new MemoPostingRule<DefaultEntry>(memoAccount); targetAccount.addPostingRule(testObject); DefaultEntry sourceEntry = EntryFactory.INSTANCE.buildDefaultEntry(sourceAccount, -10L); DefaultEntry targetEntry = EntryFactory.INSTANCE.buildDefaultEntry(targetAccount, 10L); Transaction<DefaultEntry> transaction = new Transaction<DefaultEntry>(sourceEntry, targetEntry); transaction.commit(); testObject.reverse(targetEntry); assertThat(memoAccount.getBalance(), equalTo(0L)); }