use of org.robolectric.shadows.ShadowAlarmManager in project OneSignal-Android-SDK by OneSignal.
the class MainOneSignalClassRunner method shouldSyncPendingChangesFromSyncService.
@Test
@Config(sdk = 19)
public void shouldSyncPendingChangesFromSyncService() throws Exception {
OneSignalInit();
threadAndTaskWait();
OneSignal.sendTag("key", "value");
// App is swiped away
blankActivityController.pause();
assertEquals(2, ShadowOneSignalRestClient.networkCallCount);
fastColdRestartApp();
threadAndTaskWait();
// Tags did not get synced so SyncService should be scheduled
AlarmManager alarmManager = (AlarmManager) ApplicationProvider.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
ShadowAlarmManager shadowAlarmManager = shadowOf(alarmManager);
assertEquals(1, shadowAlarmManager.getScheduledAlarms().size());
assertEquals(SyncService.class, shadowOf(shadowOf(shadowAlarmManager.getNextScheduledAlarm().operation).getSavedIntent()).getIntentClass());
shadowAlarmManager.getScheduledAlarms().clear();
// Test running the service
Robolectric.buildService(SyncService.class).startCommand(0, 0);
threadAndTaskWait();
assertEquals("value", ShadowOneSignalRestClient.lastPost.getJSONObject("tags").getString("key"));
// Remote params are called before players call due to initWithContext call inside SyncService
assertEquals(4, ShadowOneSignalRestClient.networkCallCount);
// Test starting app
OneSignalInit();
threadAndTaskWait();
// No new changes, don't schedule another restart.
// App is swiped away
blankActivityController.pause();
threadAndTaskWait();
// No Focus service should be scheduled
assertEquals(0, shadowOf(alarmManager).getScheduledAlarms().size());
assertEquals(4, ShadowOneSignalRestClient.networkCallCount);
}
use of org.robolectric.shadows.ShadowAlarmManager in project OneSignal-Android-SDK by OneSignal.
the class TestHelpers method resetAlarmManager.
private static void resetAlarmManager() {
AlarmManager alarmManager = (AlarmManager) ApplicationProvider.getApplicationContext().getSystemService(Context.ALARM_SERVICE);
ShadowAlarmManager shadowAlarmManager = shadowOf(alarmManager);
shadowAlarmManager.getScheduledAlarms().clear();
}
use of org.robolectric.shadows.ShadowAlarmManager in project sms-backup-plus by jberkel.
the class AlarmManagerDriverTest method assertAlarmScheduled.
private Intent assertAlarmScheduled(String ofExpectedType) {
AlarmManager alarmManager = (AlarmManager) RuntimeEnvironment.application.getSystemService(Context.ALARM_SERVICE);
ShadowAlarmManager shadow = shadowOf(alarmManager);
ShadowAlarmManager.ScheduledAlarm nextScheduledAlarm = shadow.getNextScheduledAlarm();
assertThat(nextScheduledAlarm.type).isEqualTo(AlarmManager.RTC_WAKEUP);
assertThat(nextScheduledAlarm.triggerAtTime).isGreaterThan(0L);
PendingIntent pendingIntent = nextScheduledAlarm.operation;
ShadowPendingIntent shadowPendingIntent = shadowOf(pendingIntent);
ComponentName component = shadowPendingIntent.getSavedIntent().getComponent();
assertThat(component.getPackageName()).isEqualTo("com.zegoggles.smssync");
assertThat(component.getClassName()).isEqualTo("com.zegoggles.smssync.service.SmsBackupService");
assertThat(shadowPendingIntent.getFlags()).isEqualTo(FLAG_UPDATE_CURRENT);
assertThat(shadowPendingIntent.getSavedIntent().getAction()).isNotEmpty();
assertThat(shadowPendingIntent.getSavedIntent().getAction()).isEqualTo(ofExpectedType);
return shadowPendingIntent.getSavedIntent();
}
use of org.robolectric.shadows.ShadowAlarmManager in project android-job by evernote.
the class JobProxyTest method verifyAlarmCount.
private void verifyAlarmCount(AlarmManager alarmManager, int count) throws NoSuchFieldException, IllegalAccessException {
Field declaredField = alarmManager.getClass().getDeclaredField("__robo_data__");
declaredField.setAccessible(true);
ShadowAlarmManager shadowAlarmManager = (ShadowAlarmManager) declaredField.get(alarmManager);
assertThat(shadowAlarmManager.getScheduledAlarms()).hasSize(count);
}
Aggregations