### Question:
PolicyResource implements CollectionResourceProvider { @Override public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, DeleteRequest request) { try { PolicyStore store = policyStoreProvider.getPolicyStore(context); store.delete(resourceId); if (DEBUG.messageEnabled()) { DEBUG.message("PolicyResource :: DELETE : Deleted policy with ID, " + resourceId); } return newResultPromise(newResourceResponse(resourceId, "0", json(object()))); } catch (EntitlementException ex) { String debug = "PolicyResource :: DELETE : Error performing delete for policy, " + resourceId; return resourceErrorHandler.handleError(context, debug, request, ex).asPromise(); } } @Inject  PolicyResource(final PolicyEvaluatorFactory factory,
                          final PolicyRequestFactory requestFactory,
                          final PolicyParser parser,
                          final PolicyStoreProvider provider,
                          final ExceptionMappingHandler<EntitlementException, ResourceException> handler); @Override Promise<ActionResponse, ResourceException> actionCollection(Context context,
            ActionRequest actionRequest); @Override Promise<ActionResponse, ResourceException> actionInstance(Context context, String resourceId,
            ActionRequest request); @Override Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request); @Override Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId,
            DeleteRequest request); @Override Promise<ResourceResponse, ResourceException> patchInstance(Context context, String resourceId,
            PatchRequest request); @Override Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request,
            QueryResourceHandler handler); @Override Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId,
            ReadRequest request); @Override Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId,
            UpdateRequest request);  }### Answer:
@Test public void shouldDeletePoliciesFromStore() throws Exception { String id = "uniqueId"; DeleteRequest request = mock(DeleteRequest.class); Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request); verify(mockStore).delete(id); assertThat(promise).succeeded().withId().isNotNull(); }
@Test public void shouldRejectNullPolicyIdInDelete() throws Exception { String id = null; DeleteRequest request = mock(DeleteRequest.class); willThrow(new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME)) .given(mockStore).delete(id); Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request); assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class); }
@Test public void shouldReportMissingPoliciesInDelete() throws Exception { String id = "unknown"; DeleteRequest request = mock(DeleteRequest.class); willThrow(new EntitlementException(EntitlementException.NO_SUCH_POLICY)) .given(mockStore).delete(id); Promise<ResourceResponse, ResourceException> promise = policyResource.deleteInstance(mockServerContext, id, request); assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class); }