org.robolectric.shadows.ShadowAlarmManager Java Examples

The following examples show how to use org.robolectric.shadows.ShadowAlarmManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegisteringTimeoutControllerTest.java    From OPFPush with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Test
public void testSetTimeout() {
    final Context ctx = RuntimeEnvironment.application.getApplicationContext();
    final AlarmManager alarmManager = (AlarmManager) RuntimeEnvironment.application.getSystemService(Context.ALARM_SERVICE);
    final ShadowAlarmManager shadowAlarmManager = shadowOf(alarmManager);

    final long whenExpected = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(TIMEOUT_MINUTES);
    RegisteringTimeoutController.setTimeout(ctx, TEST_PROVIDER);

    final List<ShadowAlarmManager.ScheduledAlarm> alarms = shadowAlarmManager.getScheduledAlarms();
    for (ShadowAlarmManager.ScheduledAlarm alarm : alarms) {
        final PendingIntent operation = alarm.operation;
        final int creatorUid = operation.getCreatorUid();
        if (creatorUid == ctx.getApplicationInfo().uid) {
            Assert.assertTrue(Math.abs(whenExpected - alarm.triggerAtTime) < TIME_DELTA_MILLISECONDS);
            return;
        }
    }
    Assert.fail();
}
 
Example #2
Source File: BaseActivityTest.java    From open with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void onCreate_shouldSetDataUploadServiceAlarm() throws Exception {
    Token token = new Token("yo", "yo");
    activity.setAccessToken(token);
    activity = initBaseActivityWithMenu(menu);
    AlarmManager alarmManager =
            (AlarmManager) Robolectric.application.getSystemService(Context.ALARM_SERVICE);
    ShadowAlarmManager shadowAlarmManager = Robolectric.shadowOf(alarmManager);
    assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNotNull();
}
 
Example #3
Source File: JobProxyTest.java    From android-job with Apache License 2.0 4 votes vote down vote up
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);
}