### Question:
ResourceTypesResource extends RealmAwareResource { @Override public Promise<ResourceResponse, ResourceException> deleteInstance(Context context, String resourceId, DeleteRequest request) { String principalName = "unknown"; try { final Subject callingSubject = getSubject(context); final String realm = getRealm(context); principalName = PrincipalRestUtils.getPrincipalNameFromSubject(callingSubject); resourceTypeService.deleteResourceType(callingSubject, realm, resourceId); final ResourceResponse resource = newResourceResponse(resourceId, "0", JsonValue.json(JsonValue.object())); return newResultPromise(resource); } catch (EntitlementException e) { if (logger.errorEnabled()) { logger.error("ApplicationsResource :: DELETE by " + principalName + ": Application failed to delete the resource specified. ", e); } return exceptionMappingHandler.handleError(context, request, e).asPromise(); } } @Inject  ResourceTypesResource(
            @Named("frRest") Debug logger,
            ExceptionMappingHandler<EntitlementException, ResourceException> exceptionMappingHandler,
            ResourceTypeService resourceTypeService); @Override Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request); @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<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId,
            UpdateRequest request); @Override Promise<QueryResponse, ResourceException> queryCollection(Context context, QueryRequest request,
            QueryResourceHandler handler); @Override Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId,
            ReadRequest request);  }### Answer:
@Test public void shouldDeleteResourceTypes() throws Exception { ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType); DeleteRequest mockDeleteRequest = mock(DeleteRequest.class); doCallRealMethod().when(resourceTypeService).deleteResourceType(any(Subject.class), anyString(), anyString()); Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.deleteInstance(mockServerContext, createdResource.getId(), mockDeleteRequest); assertThat(promise).succeeded().withId().isEqualTo(createdResource.getId()); assertThat(promise).succeeded().withContent().isObject().containsOnly(); }
@Test public void deleteShouldHandleServiceException() throws Exception { ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType); DeleteRequest deleteRequest = mock(DeleteRequest.class); Throwable t = new EntitlementException(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS); doThrow(t).when(resourceTypeService).deleteResourceType(any(Subject.class), anyString(), anyString()); Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.deleteInstance(mockServerContext, createdResource.getId(), deleteRequest); assertResourcePromiseFailedWithCodes(promise, ResourceException.CONFLICT, EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS); }