### Question:
GreedyScheduler implements Scheduler, WorkConstraintsCallback, ExecutionListener { @Override public synchronized void schedule(WorkSpec... workSpecs) { int originalSize = mConstrainedWorkSpecs.size(); for (WorkSpec workSpec : workSpecs) { if (workSpec.state == State.ENQUEUED && !workSpec.isPeriodic() && workSpec.initialDelay == 0L) { if (workSpec.hasConstraints()) { if (Build.VERSION.SDK_INT < 24 || !workSpec.constraints.hasContentUriTriggers()) { Log.d(TAG, String.format("Starting tracking for %s", workSpec.id)); mConstrainedWorkSpecs.add(workSpec); } } else { mWorkManagerImpl.startWork(workSpec.id); } } } if (originalSize != mConstrainedWorkSpecs.size()) { mWorkConstraintsTracker.replace(mConstrainedWorkSpecs); } } GreedyScheduler(Context context, WorkManagerImpl workManagerImpl); @VisibleForTesting  GreedyScheduler(WorkManagerImpl workManagerImpl,
            WorkConstraintsTracker workConstraintsTracker); @Override synchronized void schedule(WorkSpec... workSpecs); @Override synchronized void cancel(@NonNull String workSpecId); @Override synchronized void onAllConstraintsMet(@NonNull List<String> workSpecIds); @Override synchronized void onAllConstraintsNotMet(@NonNull List<String> workSpecIds); @Override synchronized void onExecuted(@NonNull String workSpecId,
            boolean isSuccessful,
            boolean needsReschedule);  }### Answer:
@Test @SmallTest public void testGreedyScheduler_startsUnconstrainedWork() { OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class).build(); WorkSpec workSpec = getWorkSpec(work); mGreedyScheduler.schedule(workSpec); verify(mWorkManagerImpl).startWork(workSpec.id); }
@Test @SmallTest public void testGreedyScheduler_ignoresPeriodicWork() { PeriodicWorkRequest periodicWork = new PeriodicWorkRequest.Builder(TestWorker.class, 0L, TimeUnit.MILLISECONDS) .build(); mGreedyScheduler.schedule(getWorkSpec(periodicWork)); verify(mMockWorkConstraintsTracker, never()).replace(ArgumentMatchers.<WorkSpec>anyList()); }
@Test @SmallTest public void testGreedyScheduler_ignoresInitialDelayWork() { OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class) .setInitialDelay(1000L, TimeUnit.MILLISECONDS) .build(); mGreedyScheduler.schedule(getWorkSpec(work)); verify(mMockWorkConstraintsTracker, never()).replace(ArgumentMatchers.<WorkSpec>anyList()); }