### Question:
JobIntentService extends Service { public static void enqueueWork(@NonNull Context context, @NonNull Class cls, int jobId, @NonNull Intent work) { enqueueWork(context, new ComponentName(context, cls), jobId, work); } JobIntentService(); @Override void onCreate(); @Override int onStartCommand(@Nullable Intent intent, int flags, int startId); @Override IBinder onBind(@NonNull Intent intent); @Override void onDestroy(); static void enqueueWork(@NonNull Context context, @NonNull Class cls, int jobId,
            @NonNull Intent work); static void enqueueWork(@NonNull Context context, @NonNull ComponentName component,
            int jobId, @NonNull Intent work); void setInterruptIfStopped(boolean interruptIfStopped); boolean isStopped(); boolean onStopCurrentWork();  }### Answer:
@MediumTest @Test public void testEnqueueOne() throws Throwable { initStatics(); TestIntentItem[] items = new TestIntentItem[] { new TestIntentItem(new Intent("FIRST")), }; for (TestIntentItem item : items) { JobIntentService.enqueueWork(mContext, TargetService.class, JOB_ID, item.intent); } allowServiceToRun(); waitServiceFinish(); compareIntents(items, sFinishedWork); }
@MediumTest @Test public void testEnqueueMultiple() throws Throwable { initStatics(); TestIntentItem[] items = new TestIntentItem[] { new TestIntentItem(new Intent("FIRST")), new TestIntentItem(new Intent("SECOND")), new TestIntentItem(new Intent("THIRD")), new TestIntentItem(new Intent("FOURTH")), }; for (TestIntentItem item : items) { JobIntentService.enqueueWork(mContext, TargetService.class, JOB_ID, item.intent); } allowServiceToRun(); waitServiceFinish(); compareIntents(items, sFinishedWork); }
@MediumTest @Test public void testEnqueueSubWork() throws Throwable { initStatics(); TestIntentItem[] items = new TestIntentItem[] { new TestIntentItem(new Intent("FIRST")), new TestIntentItem(new Intent("SECOND")), new TestIntentItem(new Intent("THIRD"), new TestIntentItem[] { new TestIntentItem(new Intent("FIFTH")), new TestIntentItem(new Intent("SIXTH")), new TestIntentItem(new Intent("SEVENTH")), new TestIntentItem(new Intent("EIGTH")), }), new TestIntentItem(new Intent("FOURTH")), }; for (TestIntentItem item : items) { JobIntentService.enqueueWork(mContext, TargetService.class, JOB_ID, item.intent); } allowServiceToRun(); waitServiceFinish(); compareIntents(items, sFinishedWork); }
@MediumTest @Test @RequiresApi(26) public void testStopWhileWorking() throws Throwable { if (Build.VERSION.SDK_INT < 26) { return; } initStatics(); TestIntentItem[] items = new TestIntentItem[] { new TestIntentItem(new Intent("FIRST"), TestIntentItem.FLAG_WAIT | TestIntentItem.FLAG_STOPPED_AFTER_WAIT), }; for (TestIntentItem item : items) { JobIntentService.enqueueWork(mContext, TargetService.class, JOB_ID, item.intent); } allowServiceToRun(); ensureServiceWaiting(); ((JobScheduler) mContext.getApplicationContext().getSystemService( Context.JOB_SCHEDULER_SERVICE)).cancel(JOB_ID); ensureServiceStopped(); allowServiceToResumeFromWait(); waitServiceFinish(); compareIntents(items, sFinishedWork); }