@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); }
private void verifyExecuteJob(JobInvocation input) throws Exception { when(mockContext.getPackageName()).thenReturn("com.example.foo"); receiver.setLatch(new CountDownLatch(1)); when(mockContext.bindService( any(Intent.class), any(JobServiceConnection.class), eq(BIND_AUTO_CREATE))) .thenReturn(true); executionDelegator.executeJob(input); verify(mockContext) .bindService(intentCaptor.capture(), connCaptor.capture(), eq(BIND_AUTO_CREATE)); final Intent result = intentCaptor.getValue(); // verify the intent was sent to the right place assertEquals(input.getService(), result.getComponent().getClassName()); assertEquals(JobService.ACTION_EXECUTE, result.getAction()); final JobServiceConnection connection = connCaptor.getValue(); final AtomicReference<JobParameters> jobParametersAtomicReference = new AtomicReference<>(); IRemoteJobService.Stub jobServiceBinder = new IRemoteJobService.Stub() { @Override public void start(Bundle invocationData, IJobCallback callback) { jobParametersAtomicReference.set( GooglePlayReceiver.getJobCoder().decode(invocationData).build()); } @Override public void stop(Bundle invocationData, boolean needToSendResult) {} }; connection.onServiceConnected(null, jobServiceBinder); TestUtil.assertJobsEqual(input, jobParametersAtomicReference.get()); // Clean up started job. Otherwise new job won't be started. ExecutionDelegator.stopJob(input, false); }
@Test public void testCodingIsLossless() { for (JobParameters input : TestUtil.getJobCombinations(builder)) { TestUtil.assertJobsEqual(input, coder.decode(coder.encode(input, new Bundle())).build()); } }