### Question:
PersonUnvoidHandler implements UnvoidHandler<Person> { @Override public void handle(Person person, User unvoidingUser, Date origParentVoidedDate, String unused) { if (person.getPersonVoided() && (origParentVoidedDate == null || origParentVoidedDate.equals(person.getPersonDateVoided()))) { person.setPersonVoided(false); person.setPersonVoidedBy(null); person.setPersonDateVoided(null); person.setPersonVoidReason(null); } }  @Override void handle(Person person, User unvoidingUser, Date origParentVoidedDate, String unused);  }### Answer:
@Test public void handle_shouldUnsetThePersonVoidedBit() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); handler.handle(person, null, null, null); Assert.assertFalse(person.getPersonVoided()); }
@Test public void handle_shouldUnsetThePersonVoider() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonVoidedBy(new User(1)); handler.handle(person, null, null, null); Assert.assertNull(person.getPersonVoidedBy()); }
@Test public void handle_shouldUnsetThePersonDateVoided() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonDateVoided(new Date()); handler.handle(person, null, null, null); Assert.assertNull(person.getPersonDateVoided()); }
@Test public void handle_shouldUnsetThePersonVoidReason() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonVoidReason("SOME REASON"); handler.handle(person, null, null, null); Assert.assertNull(person.getPersonVoidReason()); }
@Test public void handle_shouldOnlyActOnAlreadyVoidedObjects() { UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(false); handler.handle(person, null, null, "SOME REASON"); Assert.assertNull(person.getPersonVoidReason()); }
@Test public void handle_shouldNotActOnObjectsWithADifferentPersonDateVoided() { Date d = new Date(new Date().getTime() - 1000); UnvoidHandler<Person> handler = new PersonUnvoidHandler(); Person person = new Person(); person.setPersonVoided(true); person.setPersonDateVoided(d); handler.handle(person, null, new Date(), "SOME REASON"); Assert.assertTrue(person.getPersonVoided()); }