### Question:
PrincipalProvider extends AuditProvider { @Override public void prePersist(Object entity) { updatePrincipal(entity, true); }  @Override void prePersist(Object entity); @Override void preUpdate(Object entity);  }### Answer:
@Test public void should_set_users_for_creation() { String creator = "creator"; MockPrincipalProvider provider = new MockPrincipalProvider(creator); AuditedEntity entity = new AuditedEntity(); provider.prePersist(entity); assertNotNull(entity.getCreator()); assertNotNull(entity.getCreatorPrincipal()); assertNotNull(entity.getChanger()); assertEquals(entity.getCreator(), creator); assertEquals(entity.getCreatorPrincipal().getName(), creator); assertEquals(entity.getChanger(), creator); assertNull(entity.getChangerOnly()); assertNull(entity.getChangerOnlyPrincipal()); }
@Test(expected = AuditPropertyException.class) public void should_fail_on_invalid_entity() { PrincipalProviderTest.InvalidEntity entity = new PrincipalProviderTest.InvalidEntity(); new MockPrincipalProvider("").prePersist(entity); fail(); }