mirror of https://github.com/tasks/tasks
Add joda time and unit tests
* Add datetime tests * Add repeat tests * Disable instrumentTest on travis build * Update project propertiespull/73/head
parent
26e8dc62c8
commit
49d99258df
@ -0,0 +1,9 @@
|
||||
package org.tasks.date;
|
||||
|
||||
public class DateTimeUtils {
|
||||
|
||||
public static long currentTimeMillis() {
|
||||
return org.joda.time.DateTimeUtils.currentTimeMillis();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.todoroo.astrid.data;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_DAY_AFTER;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_IN_TWO_WEEKS;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_NEXT_MONTH;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_NEXT_WEEK;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_NONE;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_SPECIFIC_DAY;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_SPECIFIC_DAY_TIME;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_TODAY;
|
||||
import static com.todoroo.astrid.data.Task.URGENCY_TOMORROW;
|
||||
import static com.todoroo.astrid.data.Task.createDueDate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.tasks.Freeze.freezeAt;
|
||||
import static org.tasks.Freeze.thaw;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class TaskTest {
|
||||
|
||||
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);
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
freezeAt(now);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
thaw();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateNoUrgency() {
|
||||
assertEquals(0, createDueDate(URGENCY_NONE, 1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateToday() {
|
||||
long expected = new DateTime(2013, 12, 31, 12, 0, 0, 0).getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_TODAY, -1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateTomorrow() {
|
||||
long expected = new DateTime(2014, 1, 1, 12, 0, 0, 0).getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_TOMORROW, -1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateDayAfter() {
|
||||
long expected = new DateTime(2014, 1, 2, 12, 0, 0, 0).getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_DAY_AFTER, -1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateNextWeek() {
|
||||
long expected = new DateTime(2014, 1, 7, 12, 0, 0, 0).getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_NEXT_WEEK, -1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateInTwoWeeks() {
|
||||
long expected = new DateTime(2014, 1, 14, 12, 0, 0, 0).getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_IN_TWO_WEEKS, -1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDueDateNextMonth() {
|
||||
long expected = new DateTime(2014, 1, 31, 12, 0, 0, 0).getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_NEXT_MONTH, -1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeTimeForSpecificDay() {
|
||||
long expected = specificDueDate
|
||||
.withHourOfDay(12)
|
||||
.withMinuteOfHour(0)
|
||||
.withSecondOfMinute(0)
|
||||
.withMillisOfSecond(0)
|
||||
.getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_SPECIFIC_DAY, specificDueDate.getMillis()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeSecondsForSpecificTime() {
|
||||
long expected = specificDueDate
|
||||
.withSecondOfMinute(1)
|
||||
.withMillisOfSecond(0)
|
||||
.getMillis();
|
||||
assertEquals(expected, createDueDate(URGENCY_SPECIFIC_DAY_TIME, specificDueDate.getMillis()));
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.todoroo.astrid.repeats;
|
||||
|
||||
import com.google.ical.values.Frequency;
|
||||
import com.google.ical.values.RRule;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static com.todoroo.astrid.repeats.RepeatTaskCompleteListener.handleSubdayRepeat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class RepeatTaskCompleteListenerTest {
|
||||
private static final Date start = new Date(113, 11, 31, 8, 31, 59);
|
||||
|
||||
@Test
|
||||
public void repeatEveryMinute() {
|
||||
assertEquals(
|
||||
new Date(113, 11, 31, 8, 32, 1).getTime(), // astrid always sets seconds to one
|
||||
handleSubdayRepeat(start, newRule(1, Frequency.MINUTELY)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatEveryOtherMinute() {
|
||||
assertEquals(
|
||||
new Date(113, 11, 31, 8, 33, 1).getTime(),
|
||||
handleSubdayRepeat(start, newRule(2, Frequency.MINUTELY)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatEveryHour() {
|
||||
assertEquals(
|
||||
new Date(113, 11, 31, 9, 31, 1).getTime(),
|
||||
handleSubdayRepeat(start, newRule(1, Frequency.HOURLY)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repeatEveryOtherHour() {
|
||||
assertEquals(
|
||||
new Date(113, 11, 31, 10, 31, 1).getTime(),
|
||||
handleSubdayRepeat(start, newRule(2, Frequency.HOURLY)));
|
||||
}
|
||||
|
||||
private RRule newRule(int interval, Frequency frequency) {
|
||||
RRule rule = new RRule();
|
||||
rule.setInterval(interval);
|
||||
rule.setFreq(frequency);
|
||||
return rule;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.tasks;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeUtils;
|
||||
|
||||
public class Freeze {
|
||||
|
||||
public static Freeze freezeAt(DateTime dateTime) {
|
||||
return freezeAt(dateTime.getMillis());
|
||||
}
|
||||
|
||||
public static Freeze freezeAt(long millis) {
|
||||
DateTimeUtils.setCurrentMillisFixed(millis);
|
||||
return new Freeze();
|
||||
}
|
||||
|
||||
public static void thaw() {
|
||||
DateTimeUtils.setCurrentMillisSystem();
|
||||
}
|
||||
|
||||
public void thawAfter(Snippet snippet) {
|
||||
thaw();
|
||||
}
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
package org.tasks;
|
||||
|
||||
public class Snippet {
|
||||
}
|
Loading…
Reference in New Issue