### Question:
AuditableInterceptor extends EmptyInterceptor { @Override public boolean onSave(Object entity, Serializable id, Object[] entityCurrentState, String[] propertyNames, Type[] types) { return setCreatorAndDateCreatedIfNull(entity, entityCurrentState, propertyNames); }  @Override boolean onSave(Object entity, Serializable id, Object[] entityCurrentState, String[] propertyNames, Type[] types); @Override boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
	        String[] propertyNames, Type[] types);  }### Answer:
@Test public void onSave_shouldReturnTrueIfDateCreatedWasNull() { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { 0, null }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertTrue(result); }
@Test public void onSave_shouldReturnTrueIfCreatorWasNull() { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { null, new Date() }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertTrue(result); }
@Test public void onSave_shouldReturnFalseIfDateCreatedAndCreatorWasNotNull() { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { 0, new Date() }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertFalse(result); }
@Test public void onSave_shouldReturnTrueIfDateCreatedWasNull() throws Exception { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { 0, null }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertTrue(result); }
@Test public void onSave_shouldReturnTrueIfCreatorWasNull() throws Exception { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { null, new Date() }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertTrue(result); }
@Test public void onSave_shouldReturnFalseIfDateCreatedAndCreatorWasNotNull() throws Exception { AuditableInterceptor interceptor = new AuditableInterceptor(); User u = new User(); String[] propertyNames = new String[] { "creator", "dateCreated" }; Object[] currentState = new Object[] { 0, new Date() }; boolean result = interceptor.onSave(u, 0, currentState, propertyNames, null); Assert.assertFalse(result); }