### Question:
DefaultQueryLaunchingConstraintsChecker implements QueryLaunchingConstraintsChecker { @VisibleForTesting Set<QueryLaunchingConstraint> prepareAllConstraints(final QueryContext candidateQuery) { ImmutableSet<QueryLaunchingConstraint> driverConstraints = candidateQuery.getSelectedDriverQueryConstraints(); BackOffRetryHandler<QueryContext> retryPolicy = candidateQuery.getRetryPolicy(); Sets.SetView<QueryLaunchingConstraint> constraints = Sets.union(this.lensQueryConstraints, driverConstraints); if (retryPolicy == null) { return constraints; } else { return Sets.union(Collections.singleton(new RetryPolicyToConstraingAdapter(retryPolicy)), constraints); } } DefaultQueryLaunchingConstraintsChecker(
    @NonNull final ImmutableSet<QueryLaunchingConstraint> lensQueryConstraints); @Override boolean canLaunch(final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries);  }### Answer:
@Test public void testPrepareAllConstraints() { QueryLaunchingConstraint c1 = mock(QueryLaunchingConstraint.class); QueryLaunchingConstraint c2 = mock(QueryLaunchingConstraint.class); QueryLaunchingConstraint dc1 = mock(QueryLaunchingConstraint.class); QueryLaunchingConstraint dc2 = mock(QueryLaunchingConstraint.class); QueryContext mockCandidateQuery = mock(QueryContext.class); when(mockCandidateQuery.getSelectedDriverQueryConstraints()).thenReturn(ImmutableSet.of(dc1, dc2)); DefaultQueryLaunchingConstraintsChecker constraintsChecker = new DefaultQueryLaunchingConstraintsChecker(ImmutableSet.of(c1, c2)); assertEquals(constraintsChecker.prepareAllConstraints(mockCandidateQuery), ImmutableSet.of(c1, c2, dc1, dc2)); }
@Test public void testPrepareAllConstraintsWithNoDriverConstraints() { QueryLaunchingConstraint c1 = mock(QueryLaunchingConstraint.class); QueryLaunchingConstraint c2 = mock(QueryLaunchingConstraint.class); ImmutableSet<QueryLaunchingConstraint> emptySet = ImmutableSet.copyOf(Sets.<QueryLaunchingConstraint>newHashSet()); QueryContext mockCandidateQuery = mock(QueryContext.class); when(mockCandidateQuery.getSelectedDriverQueryConstraints()).thenReturn(emptySet); DefaultQueryLaunchingConstraintsChecker constraintsChecker = new DefaultQueryLaunchingConstraintsChecker(ImmutableSet.of(c1, c2)); assertEquals(constraintsChecker.prepareAllConstraints(mockCandidateQuery), ImmutableSet.of(c1, c2)); }