I've been reading some answers on here about using PowerMock to mock the System Date function in Java, but it seems that it's necessary to add the annotations to the actual class being tested. Let me set this question up a bit. I'm interning at a large corporation doing unit testing on a system with Spring, JUnit, Mockito, etc. My current task at hand is testing an endpoint that has a dependency on the current time against a DB (kind of like checking for an expiration date).
My question is: is it possible or intuitive to mock the System Date in a test class without touching the main source code? I don't want to modify the source code; even though it's on a testing environment I'd rather just keep it untouched. Or would it make more sense to just modify a DB entry to change the date, perform my test, and then use a transactional test rollback? Thanks a bunch!
The class I'm trying to mock is: java.util.Date cDate = new java.util.Date();