@Test public void testStartJob() { JobParameters jobParameters = mock(JobParameters.class); when(jobParameters.getExtras()) .thenReturn(new SyncDelegate.JobBuilder(service, "1").build().toPersistableBundle()); when(jobParameters.getJobId()).thenReturn(2); service.onStartJob(jobParameters); verify(service.syncDelegate).subscribe(listenerCaptor.capture()); verify(service.syncDelegate).performSync(any(SyncDelegate.Job.class)); listenerCaptor.getValue().onDone("2"); }
@Override public boolean onStartJob(JobParameters jobParameters) { String jobId = String.valueOf(jobParameters.getJobId()); SyncDelegate syncDelegate = createSyncDelegate(); mSyncDelegates.put(jobId, syncDelegate); syncDelegate.subscribe(token -> { if (TextUtils.equals(jobId, token)) { jobFinished(jobParameters, false); mSyncDelegates.remove(jobId); } }); syncDelegate.performSync(new SyncDelegate.Job(jobParameters.getExtras())); return true; }
ItemSyncJobService extends JobService { @Override public boolean onStartJob(JobParameters jobParameters) { String jobId = String.valueOf(jobParameters.getJobId()); SyncDelegate syncDelegate = createSyncDelegate(); mSyncDelegates.put(jobId, syncDelegate); syncDelegate.subscribe(token -> { if (TextUtils.equals(jobId, token)) { jobFinished(jobParameters, false); mSyncDelegates.remove(jobId); } }); syncDelegate.performSync(new SyncDelegate.Job(jobParameters.getExtras())); return true; } }
ItemSyncJobService extends JobService { @Override public boolean onStartJob(JobParameters jobParameters) { String jobId = String.valueOf(jobParameters.getJobId()); SyncDelegate syncDelegate = createSyncDelegate(); mSyncDelegates.put(jobId, syncDelegate); syncDelegate.subscribe(token -> { if (TextUtils.equals(jobId, token)) { jobFinished(jobParameters, false); mSyncDelegates.remove(jobId); } }); syncDelegate.performSync(new SyncDelegate.Job(jobParameters.getExtras())); return true; }  }
ItemSyncJobService extends JobService { @Override public boolean onStartJob(JobParameters jobParameters) { String jobId = String.valueOf(jobParameters.getJobId()); SyncDelegate syncDelegate = createSyncDelegate(); mSyncDelegates.put(jobId, syncDelegate); syncDelegate.subscribe(token -> { if (TextUtils.equals(jobId, token)) { jobFinished(jobParameters, false); mSyncDelegates.remove(jobId); } }); syncDelegate.performSync(new SyncDelegate.Job(jobParameters.getExtras())); return true; }  @Override void onCreate(); @Override boolean onStartJob(JobParameters jobParameters); @Override boolean onStopJob(JobParameters jobParameters); }
ItemSyncJobService extends JobService { @Override public boolean onStartJob(JobParameters jobParameters) { String jobId = String.valueOf(jobParameters.getJobId()); SyncDelegate syncDelegate = createSyncDelegate(); mSyncDelegates.put(jobId, syncDelegate); syncDelegate.subscribe(token -> { if (TextUtils.equals(jobId, token)) { jobFinished(jobParameters, false); mSyncDelegates.remove(jobId); } }); syncDelegate.performSync(new SyncDelegate.Job(jobParameters.getExtras())); return true; }  @Override void onCreate(); @Override boolean onStartJob(JobParameters jobParameters); @Override boolean onStopJob(JobParameters jobParameters);  }