I am currently have a requirement where in, need to mock new Date() to a specific date for all the test cases.
@Before
public void setUp() throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date NOW = sdf.parse("2015-09-26 00:00:00");
whenNew(Date.class).withAnyArguments().thenReturn(NOW);
}
So i used the above code to mock it , but still when i see the output of the test results, i could still see the actual "new Date()" is executed.
So i added this in @before block in all the test files. So can you please help to know if I am missing anything?