Created
February 19, 2016 10:58
-
-
Save Sch3lp/cb82ae6aa6c49fa426cc to your computer and use it in GitHub Desktop.
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
package be.schelp.example; | |
import org.junit.Rule; | |
import org.junit.Test; | |
import org.joda.time.DateMidnight; | |
import static org.assertj.core.api.Assertions.assertThat; | |
import be.schelp.test.FreezeDateRule; | |
public class FileFormatterTest { | |
@Rule | |
public FreezeDateRule freezeDateRule = FreezeDateRule.create(); | |
@Test | |
public void composeFilename_ConcatsCurrentDateInYMDFormat() throws Exception { | |
freezeDateRule.freezeTime(new DateMidnight(2016,2,19).toDate()); | |
String filename = new FileFormatter().composeFilename("filename"); | |
assertThat(filename).isEqualTo("filename_20160219"); | |
} | |
} |
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
package be.schelp.test; | |
import org.joda.time.DateTimeUtils; | |
import org.junit.rules.TestWatcher; | |
import org.junit.runner.Description; | |
import java.util.Date; | |
public class FreezeDateRule extends TestWatcher { | |
public static FreezeDateRule create() { | |
return new FreezeDateRule(); | |
} | |
private FreezeDateRule(){} | |
@Override | |
protected void finished(Description description) { | |
super.finished(description); | |
DateTimeUtils.setCurrentMillisSystem(); | |
} | |
public void freezeTime(Date date) { | |
DateTimeUtils.setCurrentMillisFixed(date.getTime()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment