Add DateTimeUtil tests

pull/73/head
Alex Baker 12 years ago
parent 574f687f46
commit 730d39e541

@ -1,10 +1,8 @@
package com.todoroo.astrid.data; package com.todoroo.astrid.data;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner; import org.robolectric.RobolectricTestRunner;
@ -32,11 +30,6 @@ public class TaskTest {
private static final DateTime now = new DateTime(2013, 12, 31, 16, 10, 53, 452); private static final DateTime now = new DateTime(2013, 12, 31, 16, 10, 53, 452);
private static final DateTime specificDueDate = new DateTime(2014, 3, 17, 9, 54, 27, 959); private static final DateTime specificDueDate = new DateTime(2014, 3, 17, 9, 54, 27, 959);
@BeforeClass
public static void beforeClass() {
DateTimeZone.setDefault(DateTimeZone.forID("America/Chicago"));
}
@Before @Before
public void before() { public void before() {
freezeAt(now); freezeAt(now);

@ -20,7 +20,6 @@ import org.robolectric.RobolectricTestRunner;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.TimeZone;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
@ -103,7 +102,6 @@ public class RepeatAfterCompleteTest extends TodorooRobolectricTestCase {
@Test @Test
public void testTimeZoneLate() throws ParseException { public void testTimeZoneLate() throws ParseException {
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
task.setValue(Task.DUE_DATE, DateUtilities.now() + DateUtilities.ONE_WEEK); task.setValue(Task.DUE_DATE, DateUtilities.now() + DateUtilities.ONE_WEEK);
nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal(), true); nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal(), true);

@ -0,0 +1,54 @@
package org.tasks.date;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.tasks.Snippet;
import java.util.Date;
import static org.junit.Assert.assertEquals;
import static org.tasks.Freeze.freezeAt;
import static org.tasks.date.DateTimeUtils.currentTimeMillis;
import static org.tasks.date.DateTimeUtils.newDate;
import static org.tasks.date.DateTimeUtils.newDateUtc;
@RunWith(RobolectricTestRunner.class)
public class DateTimeUtilsTest {
private final DateTime now = new DateTime(2014, 1, 1, 15, 17, 53, 0);
private final Date nowAsDate = new Date(114, 0, 1, 15, 17, 53);
@Test
public void getCurrentTime() {
freezeAt(now).thawAfter(new Snippet() {{
assertEquals(now.getMillis(), currentTimeMillis());
}});
}
@Test
public void getNowAsDate() {
freezeAt(now).thawAfter(new Snippet() {{
assertEquals(nowAsDate, newDate());
}});
}
@Test
public void createNewDate() {
assertEquals(new Date(114, 0, 1), newDate(2014, 1, 1));
}
@Test
public void createNewDateTime() {
assertEquals(new Date(114, 0, 1, 15, 17, 53), newDate(2014, 1, 1, 15, 17, 53));
}
@Test
public void createNewUtcDate() {
DateTime utc = now.toDateTime(DateTimeZone.UTC);
Date actual = newDateUtc(utc.getYear(), utc.getMonthOfYear(), utc.getDayOfMonth(), utc.getHourOfDay(), utc.getMinuteOfHour(), utc.getSecondOfMinute());
assertEquals(utc.getMillis(), actual.getTime());
}
}
Loading…
Cancel
Save