Last active
August 29, 2015 14:09
-
-
Save TomoyaShibata/b980ba99c0a6ef819abb to your computer and use it in GitHub Desktop.
Joda-Timeを使っているコードで現在日時を任意の値に設定してテストする ref: http://qiita.com/bps/items/bc061ab4802769668c6a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void somethingTest() { | |
DateTime mockDateTime= new DateTime(2014, 1, 1, 0, 0, 0); | |
DateTimeUtils.setCurrentMillisFixed(mockDateTime.getMills()); | |
// 現在日時を取得してみると、設定した日時が現在日時として取得される | |
System.out.println(new DateTime()); // 2014-01-01T00:00:00.000+09:00 | |
// something test code... | |
} | |
@After | |
public void tearDown() { | |
// 対象のテスト後にはシステム時刻を元に戻して安全性を保つ | |
DateTimeUtils.setCurrentMillisSystem(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment