Remove notification tests

pull/574/head
Alex Baker 7 years ago
parent 5f7e6c109c
commit 135e2dc446

@ -1,193 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.reminders;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.app.NotificationCompat;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.test.DatabaseTestCase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.LocalBroadcastManager;
import org.tasks.Notifier;
import org.tasks.injection.TestComponent;
import org.tasks.notifications.NotificationManager;
import org.tasks.themes.ThemeCache;
import javax.inject.Inject;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;
import static android.support.test.InstrumentationRegistry.getTargetContext;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@RunWith(AndroidJUnit4.class)
public class NotificationTests extends DatabaseTestCase {
@Module
public static class NotificationTestsModule {
private final NotificationManager notificationManager = mock(NotificationManager.class);
private final LocalBroadcastManager localBroadcastManager = mock(LocalBroadcastManager.class);
private final Context context;
public NotificationTestsModule(Context context) {
this.context = context;
}
@Provides
public NotificationManager getNotificationManager() {
return notificationManager;
}
@Provides
public LocalBroadcastManager getBroadcaster() {
return localBroadcastManager;
}
@Provides
public ThemeCache getThemeCache() {
return new ThemeCache(context);
}
}
@Subcomponent(modules = NotificationTestsModule.class)
public interface NotificationTestsComponent {
void inject(NotificationTests notificationTests);
}
@Inject TaskDao taskDao;
@Inject NotificationManager notificationManager;
@Inject LocalBroadcastManager localBroadcastManager;
@Inject Notifier notifier;
@Override
public void tearDown() {
super.tearDown();
verifyNoMoreInteractions(notificationManager);
verifyNoMoreInteractions(localBroadcastManager);
}
@Test
public void testAlarmToNotification() {
final Task task = new Task() {{
setTitle("rubberduck");
setDueDate(DateUtilities.now() - DateUtilities.ONE_DAY);
}};
taskDao.persist(task);
notifier.triggerTaskNotification(task.getId(), ReminderService.TYPE_DUE);
verify(notificationManager).notify(eq((int) task.getId()), any(NotificationCompat.Builder.class), true, false, false);
}
@Test
public void testDeletedTaskDoesntTriggerNotification() {
final Task task = new Task() {{
setTitle("gooeyduck");
setDeletionDate(DateUtilities.now());
}};
taskDao.persist(task);
notifier.triggerTaskNotification(task.getId(),ReminderService.TYPE_DUE);
verify(notificationManager).cancel((int) task.getId());
}
@Test
public void testCompletedTaskDoesntTriggerNotification() {
final Task task = new Task() {{
setTitle("rubberduck");
setCompletionDate(DateUtilities.now());
}};
taskDao.persist(task);
notifier.triggerTaskNotification(task.getId(), ReminderService.TYPE_DUE);
verify(notificationManager).cancel((int) task.getId());
}
// public void testQuietHours() {
// final Task task = new Task();
// task.setTitle("rubberduck");
// taskDao.persist(task);
// Intent intent = new Intent();
// intent.putExtra(TaskNotificationReceiver.ID_KEY, task.getId());
//
// int hour = newDate().getHours();
// Preferences.setStringFromInteger(R.string.p_rmd_quietStart, hour - 1);
// Preferences.setStringFromInteger(R.string.p_rmd_quietEnd, hour + 1);
//
// // due date notification has vibrate
// TaskNotificationReceiver.setNotificationManager(new TestNotificationManager() {
// public void notify(int id, Notification notification) {
// assertNull(notification.sound);
// assertTrue((notification.defaults & Notification.DEFAULT_SOUND) == 0);
// assertNotNull(notification.vibrate);
// assertTrue(notification.vibrate.length > 0);
// }
// });
// intent.putExtra(TaskNotificationReceiver.EXTRAS_TYPE, ReminderService.TYPE_DUE);
// notificationReceiver.onReceive(getContext(), intent);
//
// // random notification does not
// TaskNotificationReceiver.setNotificationManager(new TestNotificationManager() {
// public void notify(int id, Notification notification) {
// assertNull(notification.sound);
// assertTrue((notification.defaults & Notification.DEFAULT_SOUND) == 0);
// assertTrue(notification.vibrate == null ||
// notification.vibrate.length == 0);
// }
// });
// intent.removeExtra(TaskNotificationReceiver.EXTRAS_TYPE);
// intent.putExtra(TaskNotificationReceiver.EXTRAS_TYPE, ReminderService.TYPE_RANDOM);
// notificationReceiver.onReceive(getContext(), intent);
//
// // wrapping works
// Preferences.setStringFromInteger(R.string.p_rmd_quietStart, hour + 2);
// Preferences.setStringFromInteger(R.string.p_rmd_quietEnd, hour + 1);
//
// TaskNotificationReceiver.setNotificationManager(new TestNotificationManager() {
// public void notify(int id, Notification notification) {
// assertNull(notification.sound);
// assertTrue((notification.defaults & Notification.DEFAULT_SOUND) == 0);
// }
// });
// intent.removeExtra(TaskNotificationReceiver.EXTRAS_TYPE);
// intent.putExtra(TaskNotificationReceiver.EXTRAS_TYPE, ReminderService.TYPE_DUE);
// notificationReceiver.onReceive(getContext(), intent);
//
// // nonstop notification still sounds
// task.setReminderFlags(Task.NOTIFY_MODE_NONSTOP);
// taskDao.persist(task);
// TaskNotificationReceiver.setNotificationManager(new TestNotificationManager() {
// public void notify(int id, Notification notification) {
// assertTrue(notification.sound != null ||
// (notification.defaults & Notification.DEFAULT_SOUND) > 0);
// }
// });
// notificationReceiver.onReceive(getContext(), intent);
// }
@Override
protected void inject(TestComponent component) {
component
.plus(new NotificationTestsModule(getTargetContext()))
.inject(this);
}
}

@ -63,8 +63,8 @@ public class JobQueueTest {
Freeze.freezeAt(now).thawAfter(new Snippet() {{
assertEquals(
asList(new Reminder(1, now, TYPE_DUE),
new Alarm(1, 1, now)),
asList(new Alarm(1, 1, now),
new Reminder(1, now, TYPE_DUE)),
queue.getOverdueJobs());
}});
}

@ -11,7 +11,6 @@ import com.todoroo.astrid.gtasks.GtasksTaskListUpdaterTest;
import com.todoroo.astrid.gtasks.GtasksTaskMovingTest;
import com.todoroo.astrid.model.TaskTest;
import com.todoroo.astrid.provider.Astrid3ProviderTests;
import com.todoroo.astrid.reminders.NotificationTests;
import com.todoroo.astrid.reminders.ReminderServiceTest;
import com.todoroo.astrid.repeats.NewRepeatTests;
import com.todoroo.astrid.repeats.RepeatTaskHelperTest;
@ -65,8 +64,6 @@ public interface TestComponent {
void inject(BackupServiceTests backupServiceTests);
NotificationTests.NotificationTestsComponent plus(NotificationTests.NotificationTestsModule notificationTestsModule);
void inject(AlarmServiceTest alarmServiceTest);
void inject(RepeatTaskHelperTest repeatTaskHelperTest);

Loading…
Cancel
Save