### Question:
UmaPolicyResource implements CollectionResourceProvider { @Override public Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request) { return umaPolicyService.createPolicy(context, request.getContent()) .thenAsync(new AsyncFunction<UmaPolicy, ResourceResponse, ResourceException>() { @Override public Promise<ResourceResponse, ResourceException> apply(UmaPolicy result) { return newResultPromise(newResourceResponse(result.getId(), result.getRevision(), json(object()))); } }); } @Inject  UmaPolicyResource(UmaPolicyService umaPolicyService); @Override Promise<ResourceResponse, ResourceException> createInstance(Context context, CreateRequest request); @Override Promise<ResourceResponse, ResourceException> readInstance(Context context, final String resourceId,
            ReadRequest request); @Override Promise<ResourceResponse, ResourceException> updateInstance(Context context, String resourceId,
            UpdateRequest request); @Override Promise<ResourceResponse, ResourceException> deleteInstance(Context context, final String resourceId,
            DeleteRequest request); @Override Promise<ResourceResponse, ResourceException> patchInstance(Context context, String resourceId,
            PatchRequest request); @Override Promise<ActionResponse, ResourceException> actionCollection(Context context, ActionRequest request); @Override Promise<ActionResponse, ResourceException> actionInstance(Context context, String resourceId,
            ActionRequest request); @Override Promise<QueryResponse, ResourceException> queryCollection(Context context, final QueryRequest request,
            final QueryResourceHandler handler);  }### Answer:
@Test @SuppressWarnings("unchecked") public void shouldSuccessfullyCreatePolicy() { Context context = mock(Context.class); CreateRequest request = Requests.newCreateRequest("/policies", json(object())); UmaPolicy policy = mock(UmaPolicy.class); Promise<UmaPolicy, ResourceException> promise = Promises.newResultPromise(policy); given(policy.getId()).willReturn("ID"); given(policy.getRevision()).willReturn("REVISION"); given(policyService.createPolicy(context, request.getContent())).willReturn(promise); Promise<ResourceResponse, ResourceException> result = policyResource.createInstance(context, request); assertThat(result).succeeded().withId().isEqualTo("ID"); assertThat(result).succeeded().withRevision().isEqualTo("REVISION"); assertThat(result).succeeded().withContent().isEmpty(); }
@Test @SuppressWarnings("unchecked") public void shouldHandledFailedCreatePolicy() { Context context = mock(Context.class); CreateRequest request = Requests.newCreateRequest("/policies", json(object())); ResourceException resourceException = mock(ResourceException.class); Promise<UmaPolicy, ResourceException> promise = Promises.newExceptionPromise(resourceException); given(policyService.createPolicy(context, request.getContent())).willReturn(promise); Promise<ResourceResponse, ResourceException> result = policyResource.createInstance(context, request); assertThat(result).failedWithResourceException().isEqualTo(resourceException); }