### Question:
PolicyResourceDelegate { public Promise<List<ResourceResponse>, ResourceException> deletePolicies(Context context, Collection<String> policyIds) { List<Promise<ResourceResponse, ResourceException>> promises = new ArrayList<>(); for (String policyId : policyIds) { promises.add(policyResource.handleDelete(context, Requests.newDeleteRequest(policyId))); } return Promises.when(promises); } @Inject  PolicyResourceDelegate(@Named(UMA_BACKEND_POLICY_RESOURCE_HANDLER) RequestHandler policyResource); Promise<List<ResourceResponse>, ResourceException> createPolicies(Context context,
            Set<JsonValue> policies); Promise<List<ResourceResponse>, ResourceException> updatePolicies(Context context,
            Set<JsonValue> policies); Promise<Pair<QueryResponse, List<ResourceResponse>>, ResourceException> queryPolicies(Context context,
            QueryRequest request); Promise<QueryResponse, ResourceException> queryPolicies(Context context,
            QueryRequest request, QueryResourceHandler resultHandler); Promise<List<ResourceResponse>, ResourceException> deletePolicies(Context context,
            Collection<String> policyIds);  }### Answer:
@Test public void shouldDeletePolicies() throws ResourceException { Context context = mock(Context.class); List<ResourceResponse> policies = new ArrayList<ResourceResponse>(); ResourceResponse policyOne = newResourceResponse("ID_1", "REVISION_1", json(object())); ResourceResponse policyTwo = newResourceResponse("ID_2", "REVISION_2", json(object())); policies.add(policyOne); policies.add(policyTwo); Set<String> policyIds = new HashSet<String>(); policyIds.add("ID_1"); policyIds.add("ID_2"); Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(policyOne); Promise<ResourceResponse, ResourceException> deletePolicyTwoPromise = Promises.newResultPromise(policyTwo); given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())) .willReturn(deletePolicyOnePromise) .willReturn(deletePolicyTwoPromise); List<ResourceResponse> deletedPolicies = delegate.deletePolicies(context, policyIds).getOrThrowUninterruptibly(); assertThat(deletedPolicies).isEqualTo(policies); }
@Test(expectedExceptions = ResourceException.class) public void shouldHandleFailureToDeletePolicies() throws ResourceException { Context context = mock(Context.class); ResourceResponse policyOne = newResourceResponse("ID_1", "REVISION_1", json(object())); Set<String> policyIds = new HashSet<String>(); policyIds.add("ID_1"); policyIds.add("ID_2"); ResourceException exception = mock(ResourceException.class); Promise<ResourceResponse, ResourceException> deletePolicyOnePromise = Promises.newResultPromise(policyOne); Promise<ResourceResponse, ResourceException> deletePolicyTwoPromise = Promises.newExceptionPromise(exception); given(policyResource.handleDelete(eq(context), Matchers.<DeleteRequest>anyObject())) .willReturn(deletePolicyOnePromise) .willReturn(deletePolicyTwoPromise); delegate.deletePolicies(context, policyIds).getOrThrowUninterruptibly(); }