### Question:
ResourceTypesResource extends RealmAwareResource { @Override public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) { String principalName = "unknown"; try { Subject theSubject = getSubject(context); principalName = PrincipalRestUtils.getPrincipalNameFromSubject(theSubject); final String realm = getRealm(context); ResourceType resourceType = resourceTypeService.getResourceType(theSubject, realm, resourceId); if (resourceType == null) { throw new EntitlementException(NO_SUCH_RESOURCE_TYPE, resourceId, realm); } JsonResourceType wrapper = new JsonResourceType(resourceType); final ResourceResponse resource = newResourceResponse(resourceId, String.valueOf(System.currentTimeMillis()), JsonValue.json(wrapper.toJsonValue())); return newResultPromise(resource); } catch (EntitlementException ee) { if (logger.errorEnabled()) { logger.error("ResourceTypesResource :: READ by " + principalName + ": Could not jsonify class associated with defined Type: " + resourceId, ee); } return exceptionMappingHandler.handleError(context, request, ee).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 shouldReadResourceTypes() throws Exception { ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType); ReadRequest readRequest = mock(ReadRequest.class); when(resourceTypeService.getResourceType(any(Subject.class), anyString(), anyString())).thenCallRealMethod(); Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.readInstance(mockServerContext, createdResource.getId(), readRequest); assertThat(promise).succeeded(); }
@Test public void readShouldHandleServiceException() throws Exception { ResourceResponse createdResource = setupExistingResourceTypeFromJson(jsonResourceType); ReadRequest readRequest = mock(ReadRequest.class); Throwable t = new EntitlementException(EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS); when(resourceTypeService.getResourceType(any(Subject.class), anyString(), anyString())).thenThrow(t); Promise<ResourceResponse, ResourceException> promise = resourceTypesResource.readInstance(mockServerContext, createdResource.getId(), readRequest); assertResourcePromiseFailedWithCodes(promise, ResourceException.CONFLICT, EntitlementException.RESOURCE_TYPE_ALREADY_EXISTS); }