mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Fix ReminderSchedulerTest
This commit is contained in:
@@ -21,6 +21,7 @@ package org.isoron.uhabits.core.reminders;
|
|||||||
|
|
||||||
import org.isoron.uhabits.core.*;
|
import org.isoron.uhabits.core.*;
|
||||||
import org.isoron.uhabits.core.models.*;
|
import org.isoron.uhabits.core.models.*;
|
||||||
|
import org.isoron.uhabits.core.preferences.*;
|
||||||
import org.isoron.uhabits.core.utils.*;
|
import org.isoron.uhabits.core.utils.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import org.junit.runner.*;
|
import org.junit.runner.*;
|
||||||
@@ -29,11 +30,16 @@ import org.mockito.junit.*;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static org.isoron.uhabits.core.utils.DateUtils.applyTimezone;
|
||||||
|
import static org.isoron.uhabits.core.utils.DateUtils.removeTimezone;
|
||||||
|
import static org.isoron.uhabits.core.utils.DateUtils.setFixedLocalTime;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class ReminderSchedulerTest extends BaseUnitTest
|
public class ReminderSchedulerTest extends BaseUnitTest
|
||||||
{
|
{
|
||||||
|
private final long habitId = 10L;
|
||||||
|
|
||||||
private Habit habit;
|
private Habit habit;
|
||||||
|
|
||||||
private ReminderScheduler reminderScheduler;
|
private ReminderScheduler reminderScheduler;
|
||||||
@@ -41,15 +47,19 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
|||||||
@Mock
|
@Mock
|
||||||
private ReminderScheduler.SystemScheduler sys;
|
private ReminderScheduler.SystemScheduler sys;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private WidgetPreferences widgetPreferences;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception
|
public void setUp() throws Exception
|
||||||
{
|
{
|
||||||
super.setUp();
|
super.setUp();
|
||||||
habit = fixtures.createEmptyHabit();
|
habit = fixtures.createEmptyHabit();
|
||||||
|
habit.id = habitId;
|
||||||
|
|
||||||
reminderScheduler =
|
reminderScheduler =
|
||||||
new ReminderScheduler(commandRunner, habitList, sys);
|
new ReminderScheduler(commandRunner, habitList, sys, widgetPreferences);
|
||||||
|
|
||||||
DateUtils.setFixedTimeZone(TimeZone.getTimeZone("GMT-4"));
|
DateUtils.setFixedTimeZone(TimeZone.getTimeZone("GMT-4"));
|
||||||
}
|
}
|
||||||
@@ -58,7 +68,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
|||||||
public void testScheduleAll()
|
public void testScheduleAll()
|
||||||
{
|
{
|
||||||
long now = unixTime(2015, 1, 26, 13, 0);
|
long now = unixTime(2015, 1, 26, 13, 0);
|
||||||
DateUtils.setFixedLocalTime(now);
|
setFixedLocalTime(now);
|
||||||
|
|
||||||
Habit h1 = fixtures.createEmptyHabit();
|
Habit h1 = fixtures.createEmptyHabit();
|
||||||
Habit h2 = fixtures.createEmptyHabit();
|
Habit h2 = fixtures.createEmptyHabit();
|
||||||
@@ -88,11 +98,33 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
|||||||
scheduleAndVerify(atTime, expectedCheckmarkTime, atTime);
|
scheduleAndVerify(atTime, expectedCheckmarkTime, atTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSchedule_withSnooze()
|
||||||
|
{
|
||||||
|
long now = removeTimezone(unixTime(2015, 1, 1, 15, 0));
|
||||||
|
setFixedLocalTime(now);
|
||||||
|
|
||||||
|
long snoozeTimeInFuture = unixTime(2015, 1, 1, 21, 0);
|
||||||
|
long snoozeTimeInPast = unixTime(2015, 1, 1, 7, 0);
|
||||||
|
long regularReminderTime = applyTimezone(unixTime(2015, 1, 2, 8, 30));
|
||||||
|
long todayCheckmarkTime = unixTime(2015, 1, 1, 0, 0);
|
||||||
|
long tomorrowCheckmarkTime = unixTime(2015, 1, 2, 0, 0);
|
||||||
|
habit.setReminder(new Reminder(8, 30, WeekdayList.EVERY_DAY));
|
||||||
|
|
||||||
|
when(widgetPreferences.getSnoozeTime(habitId)).thenReturn(snoozeTimeInFuture);
|
||||||
|
reminderScheduler.schedule(habit);
|
||||||
|
verify(sys).scheduleShowReminder(snoozeTimeInFuture, habit, todayCheckmarkTime);
|
||||||
|
|
||||||
|
when(widgetPreferences.getSnoozeTime(habitId)).thenReturn(snoozeTimeInPast);
|
||||||
|
reminderScheduler.schedule(habit);
|
||||||
|
verify(sys).scheduleShowReminder(regularReminderTime, habit, tomorrowCheckmarkTime);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSchedule_laterToday()
|
public void testSchedule_laterToday()
|
||||||
{
|
{
|
||||||
long now = unixTime(2015, 1, 26, 6, 30);
|
long now = unixTime(2015, 1, 26, 6, 30);
|
||||||
DateUtils.setFixedLocalTime(now);
|
setFixedLocalTime(now);
|
||||||
|
|
||||||
long expectedCheckmarkTime = unixTime(2015, 1, 26, 0, 0);
|
long expectedCheckmarkTime = unixTime(2015, 1, 26, 0, 0);
|
||||||
long expectedReminderTime = unixTime(2015, 1, 26, 12, 30);
|
long expectedReminderTime = unixTime(2015, 1, 26, 12, 30);
|
||||||
@@ -105,7 +137,7 @@ public class ReminderSchedulerTest extends BaseUnitTest
|
|||||||
public void testSchedule_tomorrow()
|
public void testSchedule_tomorrow()
|
||||||
{
|
{
|
||||||
long now = unixTime(2015, 1, 26, 13, 0);
|
long now = unixTime(2015, 1, 26, 13, 0);
|
||||||
DateUtils.setFixedLocalTime(now);
|
setFixedLocalTime(now);
|
||||||
|
|
||||||
long expectedCheckmarkTime = unixTime(2015, 1, 27, 0, 0);
|
long expectedCheckmarkTime = unixTime(2015, 1, 27, 0, 0);
|
||||||
long expectedReminderTime = unixTime(2015, 1, 27, 12, 30);
|
long expectedReminderTime = unixTime(2015, 1, 27, 12, 30);
|
||||||
|
|||||||
Reference in New Issue
Block a user