### Question:
ReactiveAuditingBeforeBindCallback implements ReactiveBeforeBindCallback<Object>, Ordered { @Override public Publisher<Object> onBeforeBind(Object entity) { return Mono.fromSupplier(() -> auditingHandlerFactory.getObject().markAudited(entity)); } ReactiveAuditingBeforeBindCallback(ObjectFactory<IsNewAwareAuditingHandler> auditingHandlerFactory); @Override Publisher<Object> onBeforeBind(Object entity); @Override int getOrder(); static final int NEO4J_REACTIVE_AUDITING_ORDER; }### Answer:
@Test void triggersModificationMarkForObjectWithSetId() { Sample sample = new Sample(); sample.id = "id"; sample.version = 1L; StepVerifier .create(callback.onBeforeBind(sample)) .expectNextMatches(s -> { Sample auditedObject = (Sample) s; return auditedObject.created == null && auditedObject.modified != null; }) .verifyComplete(); 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)); ReactiveAuditingBeforeBindCallback localCallback = new ReactiveAuditingBeforeBindCallback(() -> handler); StepVerifier.create(localCallback.onBeforeBind(sample)).expectNext(newSample); }
@Test void triggersCreationMarkForObjectWithEmptyId() { Sample sample = new Sample(); StepVerifier .create(callback.onBeforeBind(sample)) .expectNextMatches(s -> { Sample auditedObject = (Sample) s; return auditedObject.created != null && auditedObject.modified != null; }) .verifyComplete(); verify(spyOnHandler, times(1)).markCreated(sample); verify(spyOnHandler, times(0)).markModified(any()); }