### Question:
FirebaseJobConverter { Job convert(WorkSpec workSpec) { Job.Builder builder = mDispatcher.newJobBuilder() .setService(FirebaseJobService.class) .setTag(workSpec.id) .setLifetime(Lifetime.FOREVER) .setReplaceCurrent(true) .setRetryStrategy(createRetryStrategy(workSpec)) .setConstraints(getConstraints(workSpec)); setExecutionTrigger(builder, workSpec); return builder.build(); } FirebaseJobConverter(FirebaseJobDispatcher dispatcher);   }### Answer:
@Test @SmallTest public void testConvert_basicWorkSpec() { final String expectedWorkSpecId = "026e3422-9cd1-11e7-abc4-cec278b6b50a"; WorkSpec workSpec = new WorkSpec(expectedWorkSpecId, FirebaseTestWorker.class.getName()); Job job = mConverter.convert(workSpec); assertThat(job.getTag(), is(expectedWorkSpecId)); assertThat(job.getLifetime(), is(Lifetime.FOREVER)); assertThat(job.getService(), is(FirebaseJobService.class.getName())); JobTrigger.ImmediateTrigger trigger = (JobTrigger.ImmediateTrigger) job.getTrigger(); assertThat(trigger, is(Trigger.NOW)); }
@Test @SmallTest public void testConvert_backoffPolicy() { long givenBackoffDelayDuration = 50000L; WorkSpec workSpec = new WorkSpec("id", FirebaseTestWorker.class.getName()); workSpec.setBackoffDelayDuration(givenBackoffDelayDuration); workSpec.backoffPolicy = BackoffPolicy.LINEAR; Job job = mConverter.convert(workSpec); int expectedBackoffDelayDuration = (int) TimeUnit.SECONDS .convert(givenBackoffDelayDuration, TimeUnit.MILLISECONDS); assertThat(job.getRetryStrategy().getInitialBackoff(), is(expectedBackoffDelayDuration)); assertThat(job.getRetryStrategy().getPolicy(), is(RetryStrategy.RETRY_POLICY_LINEAR)); }
@Test @SmallTest public void testConvert_initialDelay() { long givenInitialDelayDuration = 50000L; WorkSpec workSpec = new WorkSpec("id", FirebaseTestWorker.class.getName()); workSpec.initialDelay = givenInitialDelayDuration; Job job = mConverter.convert(workSpec); assertThat(job.getTrigger(), is(instanceOf(JobTrigger.ImmediateTrigger.class))); }
@Test @SmallTest @SdkSuppress(minSdkVersion = 24) public void testConvert_requireContentUriTrigger() { final Uri expectedUri = Uri.parse("TEST_URI"); final ObservedUri expectedObservedUri = new ObservedUri(expectedUri, ObservedUri.Flags.FLAG_NOTIFY_FOR_DESCENDANTS); WorkSpec workSpec = new OneTimeWorkRequest.Builder(FirebaseTestWorker.class) .setConstraints(new Constraints.Builder() .addContentUriTrigger(expectedUri, true) .build()) .build() .getWorkSpec(); Job job = mConverter.convert(workSpec); JobTrigger.ContentUriTrigger trigger = (JobTrigger.ContentUriTrigger) job.getTrigger(); List<ObservedUri> observedUriList = trigger.getUris(); MatcherAssert.assertThat(observedUriList, contains(expectedObservedUri)); }