### Question:
BaseVoidHandler implements VoidHandler<Voidable> { @Override public void handle(Voidable voidableObject, User voidingUser, Date voidedDate, String voidReason) { if (!voidableObject.getVoided() || voidableObject.getVoidedBy() == null) { voidableObject.setVoided(true); voidableObject.setVoidReason(voidReason); if (voidableObject.getVoidedBy() == null) { voidableObject.setVoidedBy(voidingUser); } if (voidableObject.getDateVoided() == null) { voidableObject.setDateVoided(voidedDate); } } }  @Override void handle(Voidable voidableObject, User voidingUser, Date voidedDate, String voidReason);  }### Answer:
@Test public void handle_shouldSetTheVoidedBit() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setVoided(false); handler.handle(voidable, null, null, " "); Assert.assertTrue(voidable.getVoided()); }
@Test public void handle_shouldSetTheVoidReason() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); handler.handle(voidable, null, null, "THE REASON"); Assert.assertEquals("THE REASON", voidable.getVoidReason()); }
@Test public void handle_shouldSetVoidedBy() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); handler.handle(voidable, new User(2), null, " "); Assert.assertEquals(2, voidable.getVoidedBy().getId().intValue()); }
@Test public void handle_shouldNotSetVoidedByIfNonNull() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setVoidedBy(new User(3)); handler.handle(voidable, new User(2), null, " "); Assert.assertEquals(3, voidable.getVoidedBy().getId().intValue()); }
@Test public void handle_shouldSetDateVoided() { Date d = new Date(); VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); handler.handle(voidable, null, d, " "); Assert.assertEquals(d, voidable.getDateVoided()); }
@Test public void handle_shouldNotSetDateVoidedIfNonNull() { Date d = new Date(new Date().getTime() - 1000); VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setDateVoided(d); handler.handle(voidable, null, new Date(), " "); Assert.assertEquals(d, voidable.getDateVoided()); }
@Test public void handle_shouldNotSetTheVoidReasonIfAlreadyVoided() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); voidable.setVoidedBy(new User(1)); handler.handle(voidable, null, null, "THE REASON"); Assert.assertNull(voidable.getVoidReason()); }
@Test public void handle_shouldSetVoidedByEvenIfVoidedBitIsSetButVoidedByIsNull() { VoidHandler<Voidable> handler = new BaseVoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); handler.handle(voidable, null, null, "THE REASON"); Assert.assertEquals("THE REASON", voidable.getVoidReason()); }