3

I have an entity that has an updated_time column. The entity uses @UpdateTimestamp hibernate annotation to handle the update automatically. In my testing, I need to seed some old data with update_time value from 7 days ago.

Is it possible to mock the @UpdateTimestamp to return a specific date, without mocking the System.currentTimeMillis()?

Note: The testing framework I use is JUnit & Mockito for mocking.

Wilianto Indrawan
  • 2,394
  • 3
  • 21
  • 26

1 Answers1

1

I'd be surprised, if there's a mockito annotation, that's not really the scope of it. You could use a Hibernate post load interceptor in the test to update your data.

But if you want to get some more reliability you could use dbunit and create a proper database setup before each test, so there's no manipulation by hibernate necessary.

One could take an in memory db for the purpose, and create test data from scratch for each test, so you're not tied to some existing data setup that you manipulate. H2 is popular, I think.

Curiosa Globunznik
  • 3,129
  • 1
  • 16
  • 24