mirror of https://github.com/tasks/tasks
Reminder service tests
* Port ReminderServiceTests * Add NotifyAtDeadlineTestpull/120/head
parent
7a6feb1b9f
commit
4d585ce3be
@ -0,0 +1,90 @@
|
||||
package com.todoroo.astrid.reminders;
|
||||
|
||||
import com.todoroo.andlib.service.Autowired;
|
||||
import com.todoroo.andlib.test.TodorooRobolectricTestCase;
|
||||
import com.todoroo.andlib.utility.Preferences;
|
||||
import com.todoroo.astrid.dao.TaskDao;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.tasks.R;
|
||||
|
||||
import static com.todoroo.astrid.reminders.ReminderService.NO_ALARM;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.tasks.Freeze.freezeAt;
|
||||
import static org.tasks.Freeze.thaw;
|
||||
import static org.tasks.date.DateTimeUtils.newDate;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
||||
|
||||
@Autowired
|
||||
TaskDao taskDao;
|
||||
|
||||
ReminderService service;
|
||||
|
||||
@Override
|
||||
public void before() {
|
||||
super.before();
|
||||
freezeAt(new DateTime(2014, 1, 24, 17, 23, 37));
|
||||
service = new ReminderService();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
thaw();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scheduleReminderAtDueTime() {
|
||||
final DateTime dueDate = new DateTime(2014, 1, 24, 19, 23, 57);
|
||||
Task task = new Task() {{
|
||||
setValue(Task.DUE_DATE, dueDate.getMillis());
|
||||
setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE);
|
||||
}};
|
||||
assertEquals(dueDate.getMillis(), service.calculateNextDueDateReminder(task));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noReminderWhenNoDueDate() {
|
||||
Task task = new Task() {{
|
||||
setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE);
|
||||
}};
|
||||
assertEquals(NO_ALARM, service.calculateNextDueDateReminder(task));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noReminderWhenNotifyAtDeadlineFlagNotSet() {
|
||||
Task task = new Task() {{
|
||||
setValue(Task.DUE_DATE, new DateTime(2014, 1, 24, 19, 23, 57).getMillis());
|
||||
}};
|
||||
assertEquals(NO_ALARM, service.calculateNextDueDateReminder(task));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dontNotifyMoreThanOncePerDay() {
|
||||
Task task = new Task() {{
|
||||
setValue(Task.DUE_DATE, newDate(2014, 1, 23).getTime());
|
||||
setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE);
|
||||
setValue(Task.REMINDER_LAST, new DateTime(2014, 1, 23, 17, 23, 37).getMillis());
|
||||
}};
|
||||
assertEquals(NO_ALARM, service.calculateNextDueDateReminder(task));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notifyIfLastNotificationWasMoreThanOneDayAgo() {
|
||||
final DateTime dueDate = new DateTime(2014, 1, 23, 0, 0, 0, 0);
|
||||
Task task = new Task() {{
|
||||
setValue(Task.DUE_DATE, dueDate.getMillis());
|
||||
setValue(Task.REMINDER_FLAGS, Task.NOTIFY_AT_DEADLINE);
|
||||
setValue(Task.REMINDER_LAST, new DateTime(2014, 1, 23, 17, 23, 36).getMillis());
|
||||
}};
|
||||
assertEquals(
|
||||
dueDate.withHourOfDay(18).getMillis(),
|
||||
service.calculateNextDueDateReminder(task));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue