### Question:
BaseUnvoidHandler implements UnvoidHandler<Voidable> { @Override public void handle(Voidable voidableObject, User voidingUser, Date origParentVoidedDate, String unused) { if (voidableObject.getVoided() && (origParentVoidedDate == null || origParentVoidedDate.equals(voidableObject.getDateVoided()))) { voidableObject.setVoided(false); voidableObject.setVoidedBy(null); voidableObject.setDateVoided(null); voidableObject.setVoidReason(null); } }  @Override void handle(Voidable voidableObject, User voidingUser, Date origParentVoidedDate, String unused);  }### Answer:
@Test public void handle_shouldUnsetTheVoidedBit() { UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); handler.handle(voidable, null, null, null); Assert.assertFalse(voidable.getVoided()); }
@Test public void handle_shouldUnsetTheVoider() { UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); voidable.setVoidedBy(new User(1)); handler.handle(voidable, null, null, null); Assert.assertNull(voidable.getVoidedBy()); }
@Test public void handle_shouldUnsetTheDateVoided() { UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); voidable.setDateVoided(new Date()); handler.handle(voidable, null, null, null); Assert.assertNull(voidable.getDateVoided()); }
@Test public void handle_shouldUnsetTheVoidReason() { UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); voidable.setVoidReason("SOME REASON"); handler.handle(voidable, null, null, null); Assert.assertNull(voidable.getVoidReason()); }
@Test public void handle_shouldOnlyActOnAlreadyVoidedObjects() { UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(false); handler.handle(voidable, null, null, "SOME REASON"); Assert.assertNull(voidable.getVoidReason()); }
@Test public void handle_shouldNotActOnObjectsWithADifferentDateVoided() { Date d = new Date(new Date().getTime() - 1000); UnvoidHandler<Voidable> handler = new BaseUnvoidHandler(); Voidable voidable = new Person(); voidable.setVoided(true); voidable.setDateVoided(d); handler.handle(voidable, null, new Date(), "SOME REASON"); Assert.assertTrue(voidable.getVoided()); }