### Question:
ConstraintController implements ConstraintListener<T> { public void replace(@NonNull List<WorkSpec> workSpecs) { mMatchingWorkSpecIds.clear(); for (WorkSpec workSpec : workSpecs) { if (hasConstraint(workSpec)) { mMatchingWorkSpecIds.add(workSpec.id); } } if (mMatchingWorkSpecIds.isEmpty()) { mTracker.removeListener(this); } else { mTracker.addListener(this); } updateCallback(); } ConstraintController(ConstraintTracker<T> tracker, OnConstraintUpdatedCallback callback); void replace(@NonNull List<WorkSpec> workSpecs); void reset(); boolean isWorkSpecConstrained(@NonNull String workSpecId); @Override void onConstraintChanged(@Nullable T newValue);  }### Answer:
@Test @SmallTest public void testReplace_empty() { mTestIdleController.replace(Collections.<WorkSpec>emptyList()); verify(mMockTracker).removeListener(mTestIdleController); verifyZeroInteractions(mCallback); }
@Test @SmallTest public void testReplace_workSpecNoConstraints() { WorkSpec workSpecNoConstraints = createNoConstraintWorkSpec(); List<WorkSpec> workSpecs = Collections.singletonList(workSpecNoConstraints); mTestIdleController.replace(workSpecs); verify(mMockTracker).removeListener(mTestIdleController); verifyZeroInteractions(mCallback); }
@Test @SmallTest public void testReplace_workSpecWithConstraint_constrained() { WorkSpec workSpecWithConstraint = createTestConstraintWorkSpec(); List<String> expectedWorkIds = Collections.singletonList(workSpecWithConstraint.id); List<WorkSpec> workSpecs = Collections.singletonList(workSpecWithConstraint); mTestIdleController.setDeviceActive(); mTestIdleController.replace(workSpecs); verify(mMockTracker).addListener(mTestIdleController); verify(mCallback).onConstraintNotMet(eq(expectedWorkIds)); }
@Test @SmallTest public void testReplace_workSpecWithConstraint_unconstrained() { WorkSpec workSpecWithConstraint = createTestConstraintWorkSpec(); List<String> expectedWorkIds = Collections.singletonList(workSpecWithConstraint.id); List<WorkSpec> workSpecs = Collections.singletonList(workSpecWithConstraint); mTestIdleController.setDeviceIdle(); mTestIdleController.replace(workSpecs); verify(mMockTracker).addListener(mTestIdleController); verify(mCallback).onConstraintMet(eq(expectedWorkIds)); }
@Test @SmallTest public void testReplace_workSpecWithConstraint_constraintNotSet() { WorkSpec workSpecWithConstraint = createTestConstraintWorkSpec(); List<String> expectedWorkIds = Collections.singletonList(workSpecWithConstraint.id); List<WorkSpec> workSpecs = Collections.singletonList(workSpecWithConstraint); mTestIdleController.replace(workSpecs); verify(mCallback).onConstraintNotMet(expectedWorkIds); }