### Question:
OpenAMResourceSetStore implements ResourceSetStore { @Override public Set<ResourceSetDescription> query(QueryFilter<String> query) throws ServerException { Set<ResourceSetDescription> results; try { results = delegate.query(QueryFilter.and(query, QueryFilter.equalTo(ResourceSetTokenField.REALM, realm))); } catch (org.forgerock.openam.sm.datalayer.store.ServerException e) { throw new ServerException(e); } return results; } @Inject  OpenAMResourceSetStore(@Assisted String realm, OAuth2ProviderSettingsFactory providerSettingsFactory,
            OAuth2UrisFactory<RealmInfo> oauth2UrisFactory, TokenIdGenerator idGenerator,
            @DataLayer(ConnectionType.RESOURCE_SETS) TokenDataStore delegate); @Override void create(OAuth2Request request, ResourceSetDescription resourceSetDescription); @Override ResourceSetDescription read(String resourceSetId, ResourceSetFilter filter); @Override ResourceSetDescription read(String resourceSetId, String resourceOwnerId); @Override void update(ResourceSetDescription resourceSetDescription); @Override void delete(String resourceSetId, String resourceOwnerId); @Override Set<ResourceSetDescription> query(QueryFilter<String> query);  }### Answer:
@Test public void shouldQueryResourceSetToken() throws Exception { Map<String, Object> queryParameters = new HashMap<String, Object>(); queryParameters.put(ResourceSetTokenField.CLIENT_ID, "CLIENT_ID"); ResourceSetDescription resourceSet1 = new ResourceSetDescription("123", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap()); ResourceSetDescription resourceSet2 = new ResourceSetDescription("456", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap()); given(dataStore.query(ArgumentMatchers.<QueryFilter<String>>any())) .willReturn(asSet(resourceSet1, resourceSet2)); resourceSet1.setRealm("REALM"); resourceSet2.setRealm("REALM"); QueryFilter<String> query = QueryFilter.alwaysTrue(); Set<ResourceSetDescription> resourceSetDescriptions = store.query(query); assertThat(resourceSetDescriptions).contains(resourceSet1, resourceSet2); ArgumentCaptor<QueryFilter> tokenFilterCaptor = ArgumentCaptor.forClass(QueryFilter.class); verify(dataStore).query(tokenFilterCaptor.capture()); assertThat(tokenFilterCaptor.getValue()).isEqualTo(QueryFilter.and(query, QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM"))); }
@Test public void shouldQueryResourceSetToken() throws Exception { Map<String, Object> queryParameters = new HashMap<String, Object>(); queryParameters.put(ResourceSetTokenField.CLIENT_ID, "CLIENT_ID"); ResourceSetDescription resourceSet1 = new ResourceSetDescription("123", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap()); ResourceSetDescription resourceSet2 = new ResourceSetDescription("456", "CLIENT_ID", "RESOURCE_OWNER_ID", Collections.<String, Object>emptyMap()); given(dataStore.query(Matchers.<QueryFilter<String>>anyObject())) .willReturn(asSet(resourceSet1, resourceSet2)); resourceSet1.setRealm("REALM"); resourceSet2.setRealm("REALM"); QueryFilter<String> query = QueryFilter.alwaysTrue(); Set<ResourceSetDescription> resourceSetDescriptions = store.query(query); assertThat(resourceSetDescriptions).contains(resourceSet1, resourceSet2); ArgumentCaptor<QueryFilter> tokenFilterCaptor = ArgumentCaptor.forClass(QueryFilter.class); verify(dataStore).query(tokenFilterCaptor.capture()); assertThat(tokenFilterCaptor.getValue()).isEqualTo(QueryFilter.and(query, QueryFilter.equalTo(ResourceSetTokenField.REALM, "REALM"))); }