### Question:
ResourceSetService { Promise<ResourceSetDescription, ResourceException> getResourceSet(final Context context, String realm, final String resourceSetId, String resourceOwnerId, final boolean augmentWithPolicy) { return getResourceSet(realm, resourceSetId, resourceOwnerId) .thenOnResult(new ResultHandler<ResourceSetDescription>() { @Override public void handleResult(ResourceSetDescription resourceSet) { if (augmentWithPolicy) { augmentWithPolicy(context, resourceSetId, resourceSet); } } }); } @Inject  ResourceSetService(ResourceSetStoreFactory resourceSetStoreFactory, UmaPolicyService policyService,
            CoreWrapper coreWrapper, UmaProviderSettingsFactory umaProviderSettingsFactory); Collection<ResourceSetDescription> filterPolicies(Set<ResourceSetDescription> resourceSets,
                                                             ResourceSetWithPolicyQuery query); boolean isSharedWith(ResourceSetDescription resourceSet, String resourceUserId, String realm);  }### Answer:
@Test public void shouldGetResourceSetWithoutPolicy() throws Exception { Context context = mock(Context.class); String realm = "REALM"; String resourceSetId = "RESOURCE_SET_ID"; String resourceOwnerId = "RESOURCE_OWNER_ID"; boolean augmentWithPolicy = false; ResourceSetDescription resourceSetDescription = mock(ResourceSetDescription.class); given(resourceSetStore.read(eq(resourceSetId), any(ResourceSetSharedFilter.class))) .willReturn(resourceSetDescription); ResourceSetDescription resourceSet = service.getResourceSet(context, realm, resourceSetId, resourceOwnerId, augmentWithPolicy).getOrThrowUninterruptibly(); assertThat(resourceSet).isEqualTo(resourceSetDescription); verifyZeroInteractions(policyService); verify(resourceSet, never()).setPolicy(ArgumentMatchers.<JsonValue>any()); }
@Test public void shouldGetResourceSetWithoutPolicy() throws Exception { Context context = mock(Context.class); String realm = "REALM"; String resourceSetId = "RESOURCE_SET_ID"; String resourceOwnerId = "RESOURCE_OWNER_ID"; boolean augmentWithPolicy = false; ResourceSetDescription resourceSetDescription = mock(ResourceSetDescription.class); given(resourceSetStore.read(eq(resourceSetId), any(ResourceSetSharedFilter.class))) .willReturn(resourceSetDescription); ResourceSetDescription resourceSet = service.getResourceSet(context, realm, resourceSetId, resourceOwnerId, augmentWithPolicy).getOrThrowUninterruptibly(); assertThat(resourceSet).isEqualTo(resourceSetDescription); verifyZeroInteractions(policyService); verify(resourceSet, never()).setPolicy(Matchers.<JsonValue>anyObject()); }
@Test public void shouldGetResourceWithPolicy() throws Exception { Context context = mock(Context.class); String realm = "REALM"; String resourceSetId = "RESOURCE_SET_ID"; String resourceOwnerId = "RESOURCE_OWNER_ID"; boolean augmentWithPolicy = true; ResourceSetDescription resourceSetDescription = mock(ResourceSetDescription.class); UmaPolicy policy = mock(UmaPolicy.class); Promise<UmaPolicy, ResourceException> policyPromise = Promises.newResultPromise(policy); JsonValue policyJson = mock(JsonValue.class); given(resourceSetStore.read(eq(resourceSetId), any(ResourceSetSharedFilter.class))) .willReturn(resourceSetDescription); given(policyService.readPolicy(context, resourceSetId)).willReturn(policyPromise); given(policy.asJson()).willReturn(policyJson); ResourceSetDescription resourceSet = service.getResourceSet(context, realm, resourceSetId, resourceOwnerId, augmentWithPolicy).getOrThrowUninterruptibly(); assertThat(resourceSet).isEqualTo(resourceSetDescription); verify(policyService).readPolicy(context, resourceSetId); verify(resourceSet).setPolicy(policyJson); }