### Question:
BaseRetireHandler implements RetireHandler<Retireable> { @Override public void handle(Retireable retireableObject, User retiringUser, Date retireDate, String retireReason) { if (!retireableObject.getRetired() || retireableObject.getRetiredBy() == null) { retireableObject.setRetired(true); retireableObject.setRetireReason(retireReason); if (retireableObject.getRetiredBy() == null) { retireableObject.setRetiredBy(retiringUser); } if (retireableObject.getDateRetired() == null) { retireableObject.setDateRetired(retireDate); } } }  @Override void handle(Retireable retireableObject, User retiringUser, Date retireDate, String retireReason);  }### Answer:
@Test public void handle_shouldSetTheRetiredBit() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetired(false); handler.handle(retireable, null, null, " "); Assert.assertTrue(retireable.getRetired()); }
@Test public void handle_shouldSetTheRetireReason() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); handler.handle(retireable, null, null, "THE REASON"); Assert.assertEquals("THE REASON", retireable.getRetireReason()); }
@Test public void handle_shouldSetRetiredBy() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); handler.handle(retireable, new User(2), null, " "); Assert.assertEquals(2, retireable.getRetiredBy().getId().intValue()); }
@Test public void handle_shouldNotSetRetiredByIfNonNull() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetiredBy(new User(3)); handler.handle(retireable, new User(2), null, " "); Assert.assertEquals(3, retireable.getRetiredBy().getId().intValue()); }
@Test public void handle_shouldSetDateRetired() { Date d = new Date(); RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); handler.handle(retireable, null, d, " "); Assert.assertEquals(d, retireable.getDateRetired()); }
@Test public void handle_shouldNotSetDateRetiredIfNonNull() { Date d = new Date(new Date().getTime() - 1000); RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setDateRetired(d); handler.handle(retireable, null, new Date(), " "); Assert.assertEquals(d, retireable.getDateRetired()); }
@Test public void handle_shouldNotSetTheRetireReasonIfAlreadyVoided() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); retireable.setRetiredBy(new User()); handler.handle(retireable, null, null, "THE REASON"); Assert.assertNull(retireable.getRetireReason()); }
@Test public void handle_shouldSetRetiredByEvenIfRetiredBitIsSetButRetiredByIsNull() { RetireHandler<Retireable> handler = new BaseRetireHandler(); Retireable retireable = new Location(); retireable.setRetired(true); handler.handle(retireable, null, null, "THE REASON"); Assert.assertEquals("THE REASON", retireable.getRetireReason()); }