AlarmOperationScheduler implements OperationScheduler { @Override public void schedule(long delay, @NonNull final Runnable operation) { long time = clock.elapsedRealtime() + delay; PendingOperation pendingOperation = new PendingOperation(time, operation); Logger.verbose("AlarmOperationScheduler - Operation scheduled with %d delay", delay); synchronized (pendingOperations) { pendingOperations.add(pendingOperation); Collections.sort(pendingOperations, OPERATION_COMPARATOR); scheduleAlarm(); } } AlarmOperationScheduler(@NonNull final Context context); @VisibleForTesting  AlarmOperationScheduler(@NonNull Context context, @NonNull Clock clock, @NonNull AlarmManagerDelegate delegate); @NonNull static AlarmOperationScheduler shared(@NonNull Context context); @Override void schedule(long delay, @NonNull final Runnable operation);  }
@Test public void testSchedule() { testClock.elapsedRealtime = 1; scheduler.schedule(1000, mock(Runnable.class)); verify(mockDelegate).onSchedule(eq(1001l), any(PendingIntent.class)); scheduler.schedule(100000, mock(Runnable.class)); verify(mockDelegate, times(2)).onSchedule(eq(1001l), any(PendingIntent.class)); scheduler.schedule(20, mock(Runnable.class)); verify(mockDelegate).onSchedule(eq(21l), any(PendingIntent.class)); }