Under the following setting
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
public class myTest {
I have this on my src
DateFormat dataformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String currentdate = dataformat.format(new Date());
And I know Date.getTime() method will be called.
I tried this on my test code.
final Date date = Mockito.mock(Date.class);
Mockito.when(date.getTime()).thenReturn(dateLongValue);
But nothing happened. I also tried with mock up like this
Mockito.when(date.format(new Date())).thenReturn(dateStringValue);
But got
java.lang.NullPointerException
at java.text.DateFormat.format(DateFormat.java:346)
This could be easy but I had no luck. Any suggestion would be appreciated.