### Question:
PersonVoidHandler implements VoidHandler<Person> { @Override public void handle(Person person, User voidingUser, Date voidedDate, String voidReason) { if (!person.getPersonVoided()) { if (person.getPersonId() != null) { UserService us = Context.getUserService(); for (User user : us.getUsersByPerson(person, false)) { us.retireUser(user, voidReason); } } person.setPersonVoided(true); person.setPersonVoidReason(voidReason); if (person.getPersonVoidedBy() == null) { person.setPersonVoidedBy(voidingUser); } if (person.getPersonDateVoided() == null) { person.setPersonDateVoided(voidedDate); } } }  @Override void handle(Person person, User voidingUser, Date voidedDate, String voidReason);  }### Answer:
@Test public void handle_shouldSetThePersonVoidedBit() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonVoided(false); handler.handle(person, null, null, " "); Assert.assertTrue(person.getPersonVoided()); }
@Test public void handle_shouldSetThePersonVoidReason() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); handler.handle(person, null, null, "THE REASON"); assertEquals("THE REASON", person.getPersonVoidReason()); }
@Test public void handle_shouldSetPersonVoidedBy() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); handler.handle(person, new User(2), null, " "); assertEquals(2, person.getPersonVoidedBy().getId().intValue()); }
@Test public void handle_shouldNotSetPersonVoidedByIfNonNull() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonVoidedBy(new User(3)); handler.handle(person, new User(2), null, " "); assertEquals(3, person.getPersonVoidedBy().getId().intValue()); }
@Test public void handle_shouldSetPersonDateVoided() { Date d = new Date(); VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); handler.handle(person, null, d, " "); assertEquals(d, person.getPersonDateVoided()); }
@Test public void handle_shouldNotSetPersonDateVoidedIfNonNull() { Date d = new Date(new Date().getTime() - 1000); VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonDateVoided(d); handler.handle(person, null, new Date(), " "); assertEquals(d, person.getPersonDateVoided()); }
@Test public void handle_shouldNotSetThePersonVoidReasonIfAlreadyPersonVoided() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = new Person(); person.setPersonVoided(true); handler.handle(person, null, null, "THE REASON"); Assert.assertNull(person.getPersonVoidReason()); }
@Test public void handle_shouldRetireUsers() { VoidHandler<Person> handler = new PersonVoidHandler(); Person person = Context.getPersonService().getPerson(2); User user = new User(person); Context.getUserService().createUser(user, "Admin123"); Assert.assertFalse(Context.getUserService().getUsersByPerson(person, false).isEmpty()); handler.handle(person, null, null, "reason"); Assert.assertTrue(Context.getUserService().getUsersByPerson(person, false).isEmpty()); }