/** Schedules the provided Job. */ @Override @ScheduleResult public int schedule(@NonNull Job job) { // Stop the job if it's running first, before we send the broadcast GooglePlayReceiver.onSchedule(job); context.sendBroadcast(createScheduleRequest(job)); return FirebaseJobDispatcher.SCHEDULE_RESULT_SUCCESS; }
@Test public void onReschedule_stopJob() { Bundle bundle = TestUtil.getBundleForContentJobExecution(); JobCoder prefixedCoder = new JobCoder(BundleProtocol.PACKED_PARAM_BUNDLE_PREFIX); JobInvocation invocation = prefixedCoder.decodeIntentBundle(bundle); Job job = TestUtil.getBuilderWithNoopValidator() .setService(TestJobService.class) .setTrigger(invocation.getTrigger()) .setTag(invocation.getTag()) .build(); receiver.prepareJob(jobCallbackMock, bundle); when(contextMock.bindService( any(Intent.class), any(JobServiceConnection.class), eq(BIND_AUTO_CREATE))) .thenReturn(true); new ExecutionDelegator(contextMock, mock(JobFinishedCallback.class), contraintCheckerMock) .executeJob(invocation); verify(contextMock) .bindService(any(Intent.class), jobServiceConnectionCaptor.capture(), eq(BIND_AUTO_CREATE)); assertTrue(jobServiceConnectionCaptor.getValue().hasJobInvocation(invocation)); GooglePlayReceiver.onSchedule(job); assertFalse(jobServiceConnectionCaptor.getValue().hasJobInvocation(invocation)); assertNull( "JobServiceConnection should be removed.", ExecutionDelegator.getJobServiceConnection(invocation.getService())); }
@Test public void onReschedule_notRunning_noException() { Job job = TestUtil.getBuilderWithNoopValidator() .setService(TestJobService.class) .setTrigger(Trigger.NOW) .setTag("TAG") .build(); GooglePlayReceiver.onSchedule(job); }
@Test public void onReschedule_notRunningWrongTag_noException() { Bundle bundle = TestUtil.getBundleForContentJobExecution(); Job job = TestUtil.getBuilderWithNoopValidator() .setService(TestJobService.class) .setTrigger(Trigger.NOW) .setTag("TAG") .build(); receiver.prepareJob(jobCallbackMock, bundle); GooglePlayReceiver.onSchedule(job); }