ReminderHelper { public void generateAlarms() { generateAlarms(-1, null); } ReminderHelper(OpacClient app);   ReminderHelper(OpacClient app, SharedPreferences sp, AccountDataSource data); void generateAlarms(); void updateAlarms(int newWarning); void updateAlarms(boolean enabled); void scheduleAlarms(); void resetNotified();  }
@Test public void shouldOnlyResetNotifiedOnReminderOff() throws Exception { setNotificationsEnabled(false); rh.generateAlarms(); verify(data, times(1)).resetNotifiedOnAllAlarams(); verifyNoMoreInteractions(data); }
@Test public void shouldNotCreateAlarmsWithoutLentItems() throws Exception { setNotificationsEnabled(true); when(data.getAllLentItems()).thenReturn(new ArrayList<LentItem>()); rh.generateAlarms(); verify(data, never()) .addAlarm(any(LocalDate.class), any(long[].class), any(DateTime.class)); }
@Test public void shouldCreateAlarmForLentItem() throws Exception { setNotificationsEnabled(true); LocalDate date = LocalDate.now(); long dbId = 1L; stubLentItem(date, dbId); rh.generateAlarms(); verify(data, times(1)).addAlarm(date, new long[]{dbId}, date.toDateTimeAtStartOfDay().minus(Days.days(3))); }
@Test public void shouldRemoveAlarmForRemovedItem() throws Exception { setNotificationsEnabled(true); when(data.getAllLentItems()).thenReturn(new ArrayList<LentItem>()); Alarm alarm = stubAlarm(); rh.generateAlarms(); verify(data, times(1)).removeAlarm(alarm); }
@Test public void shouldUpdateAlarmForChangedItemIds() throws Exception { setNotificationsEnabled(true); stubLentItem(LocalDate.now(), 2L); stubAlarm(); rh.generateAlarms(); verify(data, times(1)).updateAlarm(argThat( alarm -> alarm.media.length == 1 && alarm.media[0] == 2L)); }
@SuppressLint("CommitPrefEdits") @Test public void shouldUpdateWarningPeriodFromMillisToDays() { SharedPreferences.Editor editor = mock(SharedPreferences.Editor.class); when(sp.getString(eq("notification_warning"), anyString())).thenReturn("259200000"); when(data.getAllLentItems()).thenReturn(new ArrayList<LentItem>()); when(editor.putString(anyString(), anyString())).thenReturn(editor); when(sp.edit()).thenReturn(editor); rh.generateAlarms(); verify(editor).putString("notification_warning", "3"); verify(editor).apply(); verifyNoMoreInteractions(editor); }