我当前正在尝试模拟DateTime对象,以便可以拦截它并使其每次在测试中创建一个新的DateTime对象时创建一个常量(预定的)DateTime对象。眼下如何使用Mockito模拟Jodatime DateTime
DateTime start = new LocalDateTime().toDateTime().minusHours(1)
DateTime end = new LocalDateTime().toDateTime()
,我嘲讽LocalDateTime对象和DateTime对象,但我不知道如何:
在我实际的方法,我创建DateTime对象这样继续:
@Mock
DateTime dt;
@Mock
LocalDateTime ldt;
@Test
public void test() {
when(new DateTime()).thenReturn(????); // Stuck here.
when(new LocalDateTime().toDateTime()).thenReturn(dt);
}
任何帮助,将不胜感激。谢谢!