GooglePlayReceiver extends Service implements ExecutionDelegator.JobFinishedCallback { @Nullable @VisibleForTesting JobInvocation prepareJob(Intent intent) { Bundle intentExtras = intent.getExtras(); if (intentExtras == null) { Log.e(TAG, ERROR_NO_DATA); return null; } Pair<JobCallback, Bundle> extraction = callbackExtractor.extractCallback(intentExtras); if (extraction == null) { Log.i(TAG, "no callback found"); return null; } return prepareJob(extraction.first, extraction.second); }  @Override final int onStartCommand(Intent intent, int flags, int startId); @Nullable @Override IBinder onBind(Intent intent); @Override void onJobFinished(@NonNull JobInvocation js, @JobResult int result);  }
@Test public void prepareJob() { Intent intent = new Intent(); Bundle encode = encodeContentUriJob(getContentUriTrigger(), TestUtil.JOB_CODER); intent.putExtra(GooglePlayJobWriter.REQUEST_PARAM_EXTRAS, encode); Parcel container = Parcel.obtain(); container.writeStrongBinder(new Binder()); PendingCallback pcb = new PendingCallback(container); intent.putExtra("callback", pcb); ArrayList<Uri> uris = new ArrayList<>(); uris.add(ContactsContract.AUTHORITY_URI); uris.add(Media.EXTERNAL_CONTENT_URI); intent.putParcelableArrayListExtra(BundleProtocol.PACKED_PARAM_TRIGGERED_URIS, uris); JobInvocation jobInvocation = receiver.prepareJob(intent); assertEquals(jobInvocation.getTriggerReason().getTriggeredContentUris(), uris); }
@Test public void prepareJob_messenger() { JobInvocation jobInvocation = receiver.prepareJob(callbackMock, new Bundle()); assertNull(jobInvocation); verify(callbackMock).jobFinished(JobService.RESULT_FAIL_NORETRY); }
@Test public void prepareJob_messenger_noExtras() { Bundle bundle = TestUtil.getBundleForContentJobExecution(); JobInvocation jobInvocation = receiver.prepareJob(callbackMock, bundle); assertEquals(jobInvocation.getTriggerReason().getTriggeredContentUris(), TestUtil.URIS); }