|
|
@ -5,7 +5,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package com.todoroo.astrid.reminders;
|
|
|
|
package com.todoroo.astrid.reminders;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.app.Notification;
|
|
|
|
|
|
|
|
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
import com.todoroo.andlib.utility.DateUtilities;
|
|
|
|
import com.todoroo.astrid.dao.TaskDao;
|
|
|
|
import com.todoroo.astrid.dao.TaskDao;
|
|
|
@ -23,6 +23,8 @@ import javax.inject.Singleton;
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Module;
|
|
|
|
import dagger.Provides;
|
|
|
|
import dagger.Provides;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.Matchers.any;
|
|
|
|
|
|
|
|
import static org.mockito.Matchers.eq;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
|
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|
|
@ -42,17 +44,9 @@ public class NotificationTests extends DatabaseTestCase {
|
|
|
|
public Broadcaster getBroadcaster() {
|
|
|
|
public Broadcaster getBroadcaster() {
|
|
|
|
return mock(Broadcaster.class);
|
|
|
|
return mock(Broadcaster.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
|
|
|
|
@Provides
|
|
|
|
|
|
|
|
public Notifier getNotifier() {
|
|
|
|
|
|
|
|
return mock(Notifier.class);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Inject TaskDao taskDao;
|
|
|
|
@Inject TaskDao taskDao;
|
|
|
|
@Inject
|
|
|
|
|
|
|
|
NotificationReceiver notificationReceiver;
|
|
|
|
|
|
|
|
@Inject NotificationManager notificationManager;
|
|
|
|
@Inject NotificationManager notificationManager;
|
|
|
|
@Inject Broadcaster broadcaster;
|
|
|
|
@Inject Broadcaster broadcaster;
|
|
|
|
@Inject Notifier notifier;
|
|
|
|
@Inject Notifier notifier;
|
|
|
@ -63,7 +57,6 @@ public class NotificationTests extends DatabaseTestCase {
|
|
|
|
|
|
|
|
|
|
|
|
verifyNoMoreInteractions(notificationManager);
|
|
|
|
verifyNoMoreInteractions(notificationManager);
|
|
|
|
verifyNoMoreInteractions(broadcaster);
|
|
|
|
verifyNoMoreInteractions(broadcaster);
|
|
|
|
verifyNoMoreInteractions(notifier);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testAlarmToNotification() {
|
|
|
|
public void testAlarmToNotification() {
|
|
|
@ -71,14 +64,10 @@ public class NotificationTests extends DatabaseTestCase {
|
|
|
|
setTitle("rubberduck");
|
|
|
|
setTitle("rubberduck");
|
|
|
|
setDueDate(DateUtilities.now() - DateUtilities.ONE_DAY);
|
|
|
|
setDueDate(DateUtilities.now() - DateUtilities.ONE_DAY);
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|
taskDao.persist(task);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notificationReceiver.handle(new Intent() {{
|
|
|
|
taskDao.persist(task);
|
|
|
|
putExtra(NotificationReceiver.ID_KEY, task.getId());
|
|
|
|
|
|
|
|
putExtra(NotificationReceiver.EXTRAS_TYPE, ReminderService.TYPE_DUE);
|
|
|
|
|
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(notifier).triggerTaskNotification(task.getId(), ReminderService.TYPE_DUE);
|
|
|
|
notifier.triggerTaskNotification(task.getId(), ReminderService.TYPE_DUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void testDeletedTaskDoesntTriggerNotification() {
|
|
|
|
public void testDeletedTaskDoesntTriggerNotification() {
|
|
|
@ -88,10 +77,7 @@ public class NotificationTests extends DatabaseTestCase {
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|
taskDao.persist(task);
|
|
|
|
taskDao.persist(task);
|
|
|
|
|
|
|
|
|
|
|
|
notificationReceiver.handle(new Intent() {{
|
|
|
|
notifier.triggerTaskNotification(task.getId(),ReminderService.TYPE_DUE);
|
|
|
|
putExtra(NotificationReceiver.ID_KEY, task.getId());
|
|
|
|
|
|
|
|
putExtra(NotificationReceiver.EXTRAS_TYPE, ReminderService.TYPE_DUE);
|
|
|
|
|
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(notificationManager).cancel((int) task.getId());
|
|
|
|
verify(notificationManager).cancel((int) task.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,10 +89,7 @@ public class NotificationTests extends DatabaseTestCase {
|
|
|
|
}};
|
|
|
|
}};
|
|
|
|
taskDao.persist(task);
|
|
|
|
taskDao.persist(task);
|
|
|
|
|
|
|
|
|
|
|
|
notificationReceiver.handle(new Intent() {{
|
|
|
|
notifier.triggerTaskNotification(task.getId(), ReminderService.TYPE_DUE);
|
|
|
|
putExtra(NotificationReceiver.ID_KEY, task.getId());
|
|
|
|
|
|
|
|
putExtra(NotificationReceiver.EXTRAS_TYPE, ReminderService.TYPE_DUE);
|
|
|
|
|
|
|
|
}});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(notificationManager).cancel((int) task.getId());
|
|
|
|
verify(notificationManager).cancel((int) task.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|