Fixed up unit tests, got them to pass

pull/14/head
Tim Su 16 years ago
parent d54567c035
commit 362251823b

@ -96,7 +96,7 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
}
// invoke the recurrence iterator
long newDueDate;
long newDueDate = -1;
RRule rrule = new RRule(recurrence);
// handle the iCalendar "byDay" field differently depending on if
@ -122,24 +122,31 @@ public class RepeatTaskCompleteListener extends BroadcastReceiver {
if(!iterator.hasNext())
return -1;
nextDate = iterator.next();
if(nextDate.compareTo(repeatFrom) != 0)
if(nextDate.compareTo(repeatFrom) == 0)
continue;
if(nextDate instanceof DateTimeValueImpl) {
DateTimeValueImpl newDateTime = (DateTimeValueImpl)nextDate;
newDueDate = task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME,
Date.UTC(newDateTime.year() - 1900, newDateTime.month() - 1,
newDateTime.day(), newDateTime.hour(),
newDateTime.minute(), newDateTime.second()));
} else {
newDueDate = task.createDueDate(Task.URGENCY_SPECIFIC_DAY,
new Date(nextDate.year() - 1900, nextDate.month() - 1,
nextDate.day()).getTime());
}
if(newDueDate > DateUtilities.now() && newDueDate != repeatFromDate.getTime())
break;
}
System.err.println("REPEAT started " + repeatFrom + ", ended " + nextDate); //$NON-NLS-1$ //$NON-NLS-2$
if(nextDate instanceof DateTimeValueImpl) {
DateTimeValueImpl newDateTime = (DateTimeValueImpl)nextDate;
newDueDate = task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME,
Date.UTC(newDateTime.year() - 1900, newDateTime.month() - 1,
newDateTime.day(), newDateTime.hour(),
newDateTime.minute(), newDateTime.second()));
} else {
newDueDate = task.createDueDate(Task.URGENCY_SPECIFIC_DAY,
new Date(nextDate.year() - 1900, nextDate.month() - 1,
nextDate.day()).getTime());
}
}
if(newDueDate == -1)
return -1;
// what we do with the by day information is to add days until
// weekday equals one of this list
if(byDay != null && byDay.size() > 0) {

@ -106,8 +106,29 @@ public class AdvancedRepeatTests extends TodorooTestCase {
Date date = new Date(DateUtilities.now() / 1000L * 1000L);
date.setHours(10);
date.setMinutes(4);
long todayWithTime = task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, date.getTime());
date.setSeconds(0);
long todayWithTime = task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, date.getTime()) / 1000L * 1000L;
if(todayWithTime < DateUtilities.now())
todayWithTime += DateUtilities.ONE_DAY;
nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
assertDatesEqual(todayWithTime + DateUtilities.ONE_DAY, nextDueDate);
assertDatesEqual(todayWithTime, nextDueDate);
}
public void testDueDateInPastRepeatMultiple() throws ParseException {
RRule rrule = new RRule();
rrule.setInterval(1);
rrule.setFreq(Frequency.DAILY);
Task task = new Task();
// repeat once => due date should become tomorrow
long past = task.createDueDate(Task.URGENCY_SPECIFIC_DAY_TIME, new Date(110, 7, 1, 0, 0, 0).getTime());
task.setValue(Task.DUE_DATE, past);
long nextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
assertTrue(nextDueDate > DateUtilities.now());
task.setValue(Task.DUE_DATE, nextDueDate);
long evenMoreNextDueDate = RepeatTaskCompleteListener.computeNextDueDate(task, rrule.toIcal());
assertNotSame(nextDueDate, evenMoreNextDueDate);
}
}

@ -176,6 +176,8 @@ public class RepeatTests extends DatabaseTestCase {
/** test after completion flag */
public void testRepeatAfterComplete() throws Exception {
// create a weekly task due a couple days in the past, but with the 'after completion'
// specified. should be due 7 days from now
Task task = new Task();
task.setValue(Task.TITLE, "afterComplete");
RRule rrule = new RRule();

@ -32,7 +32,6 @@ import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.rmilk.data.MilkTask;
import com.todoroo.astrid.service.Astrid2To3UpgradeHelper;
import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagService.Tag;
import com.todoroo.astrid.test.DatabaseTestCase;
@ -90,7 +89,7 @@ public class Astrid2To3UpgradeTests extends DatabaseTestCase {
// --- helper methods
public void upgrade2To3() {
new Astrid2To3UpgradeHelper().upgrade2To3(getContext(), new UpgradeService(), 125);
new Astrid2To3UpgradeHelper().upgrade2To3(getContext(), 125);
}
public static void assertDatesEqual(Date old, long newDate) {

Loading…
Cancel
Save