|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.todoroo.astrid.reminders;
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
|
|
|
|
|
import com.todoroo.andlib.service.Autowired;
|
|
|
|
|
import com.todoroo.andlib.test.TodorooRobolectricTestCase;
|
|
|
|
|
import com.todoroo.andlib.utility.Preferences;
|
|
|
|
@ -14,6 +16,8 @@ import org.robolectric.RobolectricTestRunner;
|
|
|
|
|
import org.tasks.Freeze;
|
|
|
|
|
import org.tasks.R;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import static com.todoroo.astrid.reminders.ReminderService.NO_ALARM;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.tasks.Freeze.freezeAt;
|
|
|
|
@ -23,6 +27,9 @@ import static org.tasks.date.DateTimeUtils.newDate;
|
|
|
|
|
@RunWith(RobolectricTestRunner.class)
|
|
|
|
|
public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
|
|
|
|
|
@SuppressLint("NewApi")
|
|
|
|
|
private static final int MILLIS_PER_HOUR = (int) TimeUnit.HOURS.toMillis(1);
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TaskDao taskDao;
|
|
|
|
|
|
|
|
|
@ -38,6 +45,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
super.before();
|
|
|
|
|
freezeAt(new DateTime(2014, 1, 24, 17, 23, 37));
|
|
|
|
|
service = new ReminderService();
|
|
|
|
|
service.setPreferenceDefaults();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@After
|
|
|
|
@ -83,9 +91,9 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void notifyIfLastNotificationWasMoreThanOneDayAgo() {
|
|
|
|
|
final DateTime dueDate = new DateTime(2014, 1, 23, 0, 0, 0, 0);
|
|
|
|
|
final DateTime dueDate = new DateTime(2014, 1, 24, 0, 0, 0, 0);
|
|
|
|
|
Task task = new Task() {{
|
|
|
|
|
setDueDate(dueDate.getMillis());
|
|
|
|
|
setDueDate(Task.URGENCY_SPECIFIC_DAY, dueDate.getMillis());
|
|
|
|
|
setReminderFlags(Task.NOTIFY_AT_DEADLINE);
|
|
|
|
|
setReminderLast(new DateTime(2014, 1, 23, 17, 23, 36).getMillis());
|
|
|
|
|
}};
|
|
|
|
@ -98,7 +106,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void duringQuietHoursSetNotificationAtEnd() {
|
|
|
|
|
setQuietHours(0, 10);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 9, 13, 37, 501));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 8);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, 8 * MILLIS_PER_HOUR);
|
|
|
|
|
Task task = new Task() {{
|
|
|
|
|
setDueDate(Task.URGENCY_SPECIFIC_DAY, newDate(2014, 1, 27).getTime());
|
|
|
|
|
setReminderFlags(Task.NOTIFY_AT_DEADLINE);
|
|
|
|
@ -112,7 +120,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void afterQuietHoursSetNotificationOnePeriodCloserToDueDate() {
|
|
|
|
|
setQuietHours(0, 10);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 11, 13, 37, 501));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 8);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, 8 * MILLIS_PER_HOUR);
|
|
|
|
|
Task task = new Task() {{
|
|
|
|
|
setDueDate(Task.URGENCY_SPECIFIC_DAY, newDate(2014, 1, 27).getTime());
|
|
|
|
|
setReminderFlags(Task.NOTIFY_AT_DEADLINE);
|
|
|
|
@ -126,13 +134,13 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void beforeQuietStartDueDateMoreThanOnePeriodAfterEnd() {
|
|
|
|
|
setQuietHours(2, 11);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 1, 53, 37, 509));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 1);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, MILLIS_PER_HOUR);
|
|
|
|
|
Task task = new Task() {{
|
|
|
|
|
setDueDate(Task.URGENCY_SPECIFIC_DAY, newDate(2014, 1, 27).getTime());
|
|
|
|
|
setReminderFlags(Task.NOTIFY_AT_DEADLINE);
|
|
|
|
|
}};
|
|
|
|
|
assertEquals(
|
|
|
|
|
new DateTime(2014, 1, 27, 11, 0, 0, 509).getMillis(),
|
|
|
|
|
new DateTime(2014, 1, 27, 11, 0, 0, 0).getMillis(),
|
|
|
|
|
service.calculateNextDueDateReminder(task));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -140,9 +148,9 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void beforeQuietStartDueDateLessThanOnePeriodAfterEnd() {
|
|
|
|
|
setQuietHours(3, 11);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 1, 53, 37, 509));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 1);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, MILLIS_PER_HOUR);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new DateTime(2014, 1, 27, 2, 10, 13, 259).getMillis(),
|
|
|
|
|
new DateTime(2014, 1, 27, 2, 10, 13, 131).getMillis(),
|
|
|
|
|
service.calculateNextDueDateReminder(dueAtNoon));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -150,7 +158,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void noAlarmAfterQuietHoursStartWithWrap() {
|
|
|
|
|
setQuietHours(10, 1);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 10, 0, 0, 0));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 8);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, 8 * MILLIS_PER_HOUR);
|
|
|
|
|
assertEquals(
|
|
|
|
|
NO_ALARM,
|
|
|
|
|
service.calculateNextDueDateReminder(dueAtNoon));
|
|
|
|
@ -160,7 +168,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void setToQuietAlarmEndWithWrap() {
|
|
|
|
|
setQuietHours(22, 11);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 10, 59, 59, 999));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 8);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, 8 * MILLIS_PER_HOUR);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new DateTime(2014, 1, 27, 11, 0, 0, 0).getMillis(),
|
|
|
|
|
service.calculateNextDueDateReminder(dueAtNoon));
|
|
|
|
@ -170,7 +178,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
public void setReminderOnePeriodFromNowBeforeQuietHourStartWithWrap() {
|
|
|
|
|
setQuietHours(22, 11);
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 11, 0, 0, 0));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 8);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, 8 * MILLIS_PER_HOUR);
|
|
|
|
|
assertEquals(
|
|
|
|
|
// wtf? this is after due date
|
|
|
|
|
new DateTime(2014, 1, 27, 13, 45, 0, 0).getMillis(),
|
|
|
|
@ -180,7 +188,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
@Test
|
|
|
|
|
public void setReminderOnePeriodFromNowNoQuietHours() {
|
|
|
|
|
Freeze.freezeAt(new DateTime(2014, 1, 27, 11, 0, 0, 0));
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_time, 8);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_time, 8 * MILLIS_PER_HOUR);
|
|
|
|
|
assertEquals(
|
|
|
|
|
new DateTime(2014, 1, 27, 11, 15, 0, 0).getMillis(),
|
|
|
|
|
service.calculateNextDueDateReminder(dueAtNoon));
|
|
|
|
@ -188,7 +196,7 @@ public class NotifyAtDeadlineTest extends TodorooRobolectricTestCase {
|
|
|
|
|
|
|
|
|
|
private void setQuietHours(int start, int end) {
|
|
|
|
|
Preferences.setBoolean(R.string.p_rmd_enable_quiet, true);
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_quietStart, start);
|
|
|
|
|
Preferences.setStringFromInteger(R.string.p_rmd_quietEnd, end);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_quietStart, start * MILLIS_PER_HOUR);
|
|
|
|
|
Preferences.setInt(R.string.p_rmd_quietEnd, end * MILLIS_PER_HOUR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|