@Test public void onJobFinished_unknownJobCallbackIsNotPresent_ignoreNoException() { receiver.onJobFinished(jobInvocationBuilder.build(), JobService.RESULT_SUCCESS); verifyZeroInteractions(driverMock); }
@Test public void onJobFinished_successRecurringContentJob_reschedule() { JobInvocation jobInvocation = receiver.prepareJob(callbackMock, getBundleForContentJobExecutionRecurring()); receiver.onJobFinished(jobInvocation, JobService.RESULT_SUCCESS); verify(driverMock).schedule(jobArgumentCaptor.capture()); // No need to callback when job finished. // Reschedule request is treated as two events: completion of old job and scheduling of new // job with the same parameters. verifyZeroInteractions(callbackMock); Job rescheduledJob = jobArgumentCaptor.getValue(); TestUtil.assertJobsEqual(jobInvocation, rescheduledJob); }
@Test public void onJobFinished_failWithRetryRecurringContentJob_sendResult() { JobInvocation jobInvocation = receiver.prepareJob(callbackMock, getBundleForContentJobExecutionRecurring()); receiver.onJobFinished(jobInvocation, JobService.RESULT_FAIL_RETRY); // If a job finishes with RESULT_FAIL_RETRY we don't need to send a reschedule request. // Rescheduling will erase previously triggered URIs. verify(callbackMock).jobFinished(JobService.RESULT_FAIL_RETRY); verifyZeroInteractions(driverMock); }
@Test public void onJobFinished_notRecurringContentJob_sendResult() { jobInvocationBuilder.setTrigger( Trigger.contentUriTrigger(Arrays.asList(new ObservedUri(Contacts.CONTENT_URI, 0)))); JobInvocation jobInvocation = receiver.prepareJob(callbackMock, TestUtil.getBundleForContentJobExecution()); receiver.onJobFinished(jobInvocation, JobService.RESULT_SUCCESS); verify(callbackMock).jobFinished(JobService.RESULT_SUCCESS); verifyZeroInteractions(driverMock); }
@Test public void onStartCommand_executeAction() { JobInvocation job = new JobInvocation.Builder() .setTag("tag") .setService("com.example.foo.FooService") .setTrigger(Trigger.NOW) .setRetryStrategy(RetryStrategy.DEFAULT_EXPONENTIAL) .setLifetime(Lifetime.UNTIL_NEXT_BOOT) .setConstraints(new int[] {Constraint.DEVICE_IDLE}) .build(); Intent execIntent = new Intent("com.google.android.gms.gcm.ACTION_TASK_READY") .putExtra( "extras", new JobCoder(BundleProtocol.PACKED_PARAM_BUNDLE_PREFIX).encode(job, new Bundle())) .putExtra("callback", new InspectableBinder().toPendingCallback()); assertResultWasStartNotSticky(receiver.onStartCommand(execIntent, 0, 101)); verify(receiver, never()).stopSelf(anyInt()); verify(executionDelegatorMock).executeJob(any(JobInvocation.class)); receiver.onJobFinished(job, JobService.RESULT_SUCCESS); verify(receiver).stopSelf(101); }