### Question:
TotalQueryCostCeilingConstraint implements QueryLaunchingConstraint { @Override public String allowsLaunchOf( final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries) { if (!totalQueryCostCeilingPerUser.isPresent()) { return null; } final String currentUser = candidateQuery.getSubmittedUser(); QueryCost totalQueryCostForCurrentUser = launchedQueries.getTotalQueryCost(currentUser); if (totalQueryCostForCurrentUser.compareTo(totalQueryCostCeilingPerUser.get()) > 0) { return totalQueryCostForCurrentUser + "/" + totalQueryCostCeilingPerUser + " capacity utilized by " + candidateQuery.getSubmittedUser(); } return null; } TotalQueryCostCeilingConstraint(@NonNull final Optional<QueryCost> totalQueryCostCeilingPerUser); @Override String allowsLaunchOf(
    final QueryContext candidateQuery, final EstimatedImmutableQueryCollection launchedQueries);  }### Answer:
@Test(dataProvider = "dpTestAllowsLaunchOfQuery") public void testAllowsLaunchOfQuery(final double totalQueryCostForCurrentUser, final boolean expectedCanLaunch) { final QueryCost totalQueryCostCeilingPerUser = new FactPartitionBasedQueryCost(90.0); final QueryLaunchingConstraint queryConstraint = new TotalQueryCostCeilingConstraint(Optional.of(totalQueryCostCeilingPerUser)); final QueryContext query = mock(QueryContext.class); final EstimatedImmutableQueryCollection launchedQueries = mock(EstimatedImmutableQueryCollection.class); final String mockUser = "MockUser"; when(query.getSubmittedUser()).thenReturn(mockUser); when(launchedQueries.getTotalQueryCost(mockUser)) .thenReturn(new FactPartitionBasedQueryCost(totalQueryCostForCurrentUser)); String actualCanLaunch = queryConstraint.allowsLaunchOf(query, launchedQueries); if (expectedCanLaunch) { assertNull(actualCanLaunch); } else { assertNotNull(actualCanLaunch); } }
@Test public void testAllowsLaunchOfQueryWhenCeilingIsAbsent() { final QueryLaunchingConstraint queryConstraint = new TotalQueryCostCeilingConstraint(Optional.<QueryCost>absent()); final QueryContext query = mock(QueryContext.class); final EstimatedImmutableQueryCollection launchedQueries = mock(EstimatedImmutableQueryCollection.class); String actualCanLaunch = queryConstraint.allowsLaunchOf(query, launchedQueries); assertNull(actualCanLaunch); }