When i insert my business object in the database (with spring/hibernate), there are some date fields that are updated with the current date.
This is an important feature so i want to validate it in my testable specification.
The problem is that i want to see the field with the correct date, but as it's the current date, it changes every time.
I have a solution that could work but it's so hacky that i can't do it in good conscience.
It would be like this :
@Service
public class DateService {
private Date fixedDate;
public Date getCurrentDate() {
if (fixedDate != null)
return fixedDate;
return new Date();
}
// setter / reset
}
And I @autowired it every time i need a new Date(). Then, when it's testing time, i fix the date so i know every "new" date would be this date.
How do you create good repeatable date based tests in your projects ?
Thanks