如何模拟JodaTime的实际日期? [英] How can I mock JodaTime actual date?
本文介绍了如何模拟JodaTime的实际日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要测试此方法:
public FirmOrder findActiveByModelColor(ModelColor modelColor) {
Query query = em.createQuery("FROM FirmOrder fo WHERE fo.modelColor = :modelColor AND fo.year = :year AND fo.month = :month");
query.setParameter("modelColor", modelColor);
query.setParameter("year", new DateTime().year().get());
query.setParameter("month", new DateTime().monthOfYear().get());
return (FirmOrder) query.getSingleResult();
}
但是我需要DateTime().year().get()
和DateTime().dayOfMonth().get()
始终返回相同的日期
but I need DateTime().year().get()
and DateTime().dayOfMonth().get()
to always return the same date
tks
推荐答案
If you can't add a factory object as suggested by skaffman, you can use DateTimeUtils.setCurrentMillisFixed()
.
这篇关于如何模拟JodaTime的实际日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文