### Question:
UnioningWaitingQueriesSelector implements WaitingQueriesSelector { @VisibleForTesting Set<WaitingQueriesSelectionPolicy> prepareAllSelectionPolicies(final FinishedLensQuery finishedQuery) { ImmutableSet<WaitingQueriesSelectionPolicy> driverSelectionPolicies = finishedQuery.getDriverSelectionPolicies(); return Sets.union(this.selectionPolicies, driverSelectionPolicies); } UnioningWaitingQueriesSelector(
    @NonNull final ImmutableSet<WaitingQueriesSelectionPolicy> selectionPolicies); @Override Set<QueryContext> selectQueries(final FinishedLensQuery finishedQuery,
      final EstimatedImmutableQueryCollection waitingQueries);  }### Answer:
@Test public void testPrepareAllSelectionPolicies() { WaitingQueriesSelectionPolicy p1 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy p2 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy dp1 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy dp2 = mock(WaitingQueriesSelectionPolicy.class); FinishedLensQuery mockFinishedQuery = mock(FinishedLensQuery.class); when(mockFinishedQuery.getDriverSelectionPolicies()).thenReturn(ImmutableSet.of(dp1, dp2)); UnioningWaitingQueriesSelector selector = new UnioningWaitingQueriesSelector(ImmutableSet.of(p1, p2)); assertEquals(selector.prepareAllSelectionPolicies(mockFinishedQuery), ImmutableSet.of(p1, p2, dp1, dp2)); }
@Test public void testPrepareAllSelectionPoliciesWithNoDriverSelectionPolicy() { WaitingQueriesSelectionPolicy p1 = mock(WaitingQueriesSelectionPolicy.class); WaitingQueriesSelectionPolicy p2 = mock(WaitingQueriesSelectionPolicy.class); final ImmutableSet<WaitingQueriesSelectionPolicy> emptySet = ImmutableSet.copyOf( Sets.<WaitingQueriesSelectionPolicy>newHashSet()); FinishedLensQuery mockFinishedQuery = mock(FinishedLensQuery.class); when(mockFinishedQuery.getDriverSelectionPolicies()).thenReturn(emptySet); UnioningWaitingQueriesSelector selector = new UnioningWaitingQueriesSelector(ImmutableSet.of(p1, p2)); assertEquals(selector.prepareAllSelectionPolicies(mockFinishedQuery), ImmutableSet.of(p1, p2)); }