Remove implements CombinationResult { @Override public void applyTo(Collection<Debt> existingDebts) { for (Debt debtToBeRemoved : debtsToBeRemoved) { existingDebts.remove(debtToBeRemoved); } } Remove(Debt... debtsToBeRemoved); @Override boolean hasChanges(); @Override void applyTo(Collection<Debt> existingDebts); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void shouldRemoveDebts() throws Exception { final Debt debt = debt(thomas, amount(10), matthias); final Remove combinationResult = new Remove(debt); final List<Debt> list = new ArrayList<>(Arrays.asList(debt)); combinationResult.applyTo(list); assertThat(list, allOf( iterableWithSize(0), not(hasItem(debt)) )); }
@Test public void shouldRemoveInstancesOnlyOnce() throws Exception { final Remove sut = new Remove( debt(thomas, amount(2.5), simon) ); final ArrayList<Debt> existingTransactions = new ArrayList<>( Arrays.asList( debt(thomas, amount(2.5), simon), debt(thomas, amount(2.5), simon) ) ); sut.applyTo(existingTransactions); assertThat(existingTransactions, allOf( iterableWithSize(1), hasItem( debt(thomas, amount(2.5), simon) ) )); }