### Question:
WorkerWrapper implements Runnable { static Worker workerFromWorkSpec(@NonNull Context context, @NonNull WorkSpec workSpec, @NonNull Extras extras) { String workerClassName = workSpec.workerClassName; UUID workSpecId = UUID.fromString(workSpec.id); return workerFromClassName( context, workerClassName, workSpecId, extras); } private  WorkerWrapper(Builder builder); @WorkerThread @Override void run(); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) void interrupt(boolean cancelled); @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) @SuppressWarnings("ClassNewInstance") static Worker workerFromClassName(
            @NonNull Context context,
            @NonNull String workerClassName,
            @NonNull UUID workSpecId,
            @NonNull Extras extras);  }### Answer:
@Test @SmallTest public void testFromWorkSpec_hasAppContext() { OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class).build(); Worker worker = WorkerWrapper.workerFromWorkSpec( mContext, getWorkSpec(work), new Extras(Data.EMPTY, Collections.<String>emptyList(), null, 1)); assertThat(worker, is(notNullValue())); assertThat(worker.getApplicationContext(), is(equalTo(mContext.getApplicationContext()))); }
@Test @SmallTest public void testFromWorkSpec_hasCorrectArguments() { String key = "KEY"; String expectedValue = "VALUE"; Data input = new Data.Builder().putString(key, expectedValue).build(); OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class).setInputData(input).build(); Worker worker = WorkerWrapper.workerFromWorkSpec( mContext, getWorkSpec(work), new Extras(input, Collections.<String>emptyList(), null, 1)); assertThat(worker, is(notNullValue())); assertThat(worker.getInputData().getString(key, null), is(expectedValue)); work = new OneTimeWorkRequest.Builder(TestWorker.class).build(); worker = WorkerWrapper.workerFromWorkSpec( mContext, getWorkSpec(work), new Extras(Data.EMPTY, Collections.<String>emptyList(), null, 1)); assertThat(worker, is(notNullValue())); assertThat(worker.getInputData().size(), is(0)); }
@Test @SmallTest public void testFromWorkSpec_hasCorrectTags() { OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class) .addTag("one") .addTag("two") .addTag("three") .build(); Worker worker = WorkerWrapper.workerFromWorkSpec( mContext, getWorkSpec(work), new Extras(Data.EMPTY, Arrays.asList("one", "two", "three"), null, 1)); assertThat(worker, is(notNullValue())); assertThat(worker.getTags(), containsInAnyOrder("one", "two", "three")); }
@Test @SmallTest public void testFromWorkSpec_hasCorrectRuntimeExtras() { OneTimeWorkRequest work = new OneTimeWorkRequest.Builder(TestWorker.class).build(); Extras.RuntimeExtras runtimeExtras = new Extras.RuntimeExtras(); runtimeExtras.triggeredContentAuthorities = new String[]{"tca1", "tca2", "tca3"}; runtimeExtras.triggeredContentUris = new Uri[]{Uri.parse("tcu1"), Uri.parse("tcu2")}; Worker worker = WorkerWrapper.workerFromWorkSpec( mContext, getWorkSpec(work), new Extras(Data.EMPTY, Collections.<String>emptyList(), runtimeExtras, 1)); assertThat(worker, is(notNullValue())); assertThat(worker.getTriggeredContentAuthorities(), arrayContaining(runtimeExtras.triggeredContentAuthorities)); assertThat(worker.getTriggeredContentUris(), arrayContaining(runtimeExtras.triggeredContentUris)); }