### Question:
PolicyResource implements CollectionResourceProvider { @Override public Promise<ResourceResponse, ResourceException> readInstance(Context context, String resourceId, ReadRequest request) { try { Privilege policy = policyStoreProvider.getPolicyStore(context).read(resourceId); return newResultPromise(policyResource(policy)); } catch (EntitlementException ex) { DEBUG.error("PolicyResource :: READ : Error reading policy, " + resourceId + ".", ex); return resourceErrorHandler.handleError(context, 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 shouldReadPoliciesFromStore() throws Exception { String id = "testPolicy"; long lastModified = 1234l; Privilege policy = mockPrivilege(id, lastModified); ReadRequest request = mock(ReadRequest.class); given(mockStore.read(id)).willReturn(policy); JsonValue content = new JsonValue("content"); given(mockParser.printPolicy(policy)).willReturn(content); Promise<ResourceResponse, ResourceException> promise = policyResource.readInstance(mockServerContext, id, request); assertThat(promise).succeeded().withId().isNotNull(); }
@Test public void shouldReportMissingPoliciesInRead() throws Exception { String id = "unknown"; given(mockStore.read(id)).willThrow(new EntitlementException(EntitlementException.NO_SUCH_POLICY)); ReadRequest request = mock(ReadRequest.class); Promise<ResourceResponse, ResourceException> promise = policyResource.readInstance(mockServerContext, id, request); assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class); }