While testing the updating of an entity, I want to also make sure that the dates are working correctly. In my entity I have:
@PreUpdate
private void onUpdate() {
this.lastUpdated = new LocalDateTime();
}
When I test a brand getting updated, I'm created the brand, modifying it, then calling update, after-which I refetch the brand to assert I could find it by the changed value.
The time between saving and updating is often so small, the dates end up being the same:
assertThat(first.getLastUpdated().isBefore(brand.get().getLastUpdated())).isEqualTo(true);
I've solved this currently by adding in a Thread.sleep(100)
call between the save and update, but my gut says this is a really bad idea. Thoughts?