### Question:
AuditingBeforeBindCallback implements BeforeBindCallback<Object>, Ordered { @Override public Object onBeforeBind(Object entity) { return auditingHandlerFactory.getObject().markAudited(entity); } AuditingBeforeBindCallback(ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory); @Override Object onBeforeBind(Object entity); @Override int getOrder(); static final int NEO4J_AUDITING_ORDER; }### Answer:
@Test void triggersCreationMarkForObjectWithEmptyId() { Sample sample = new Sample(); sample = (Sample) callback.onBeforeBind(sample); assertThat(sample.created).isNotNull(); assertThat(sample.modified).isNotNull(); verify(spyOnHandler, times(1)).markCreated(sample); verify(spyOnHandler, times(0)).markModified(any()); }
@Test void triggersModificationMarkForObjectWithSetId() { Sample sample = new Sample(); sample.id = "id"; sample.version = 1L; sample = (Sample) callback.onBeforeBind(sample); assertThat(sample.created).isNull(); assertThat(sample.modified).isNotNull(); verify(spyOnHandler, times(0)).markCreated(any()); verify(spyOnHandler, times(1)).markModified(sample); }
@Test void propagatesChangedInstanceToEvent() { ImmutableSample sample = new ImmutableSample(); ImmutableSample newSample = new ImmutableSample(); IsNewAwareAuditingHandler handler = mock(IsNewAwareAuditingHandler.class); doReturn(newSample).when(handler).markAudited(eq(sample)); Object result = new AuditingBeforeBindCallback(() -> handler).onBeforeBind(sample); assertThat(result).isSameAs(newSample); }