### Question:
ResourceSetRegistrationEndpoint extends ServerResource { @Post public Representation createResourceSet(JsonRepresentation entity) throws NotFoundException, ServerException, BadRequestException { ResourceSetDescription resourceSetDescription = new ResourceSetDescription(null, getClientId(), getResourceOwnerId(), validator.validate(toMap(entity))); OAuth2Request oAuth2Request = requestFactory.create(getRequest()); ResourceSetStore store = providerSettingsFactory.get(oAuth2Request).getResourceSetStore(); QueryFilter<String> query = QueryFilter.and( QueryFilter.equalTo(ResourceSetTokenField.NAME, resourceSetDescription.getName()), QueryFilter.equalTo(ResourceSetTokenField.CLIENT_ID, getClientId()), QueryFilter.equalTo(ResourceSetTokenField.RESOURCE_OWNER_ID, getResourceOwnerId())); if (!store.query(query).isEmpty()) { getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST); Map<String, Object> response = new HashMap<String, Object>(); response.put(OAuth2Constants.Params.ERROR, Status.CLIENT_ERROR_BAD_REQUEST.getReasonPhrase()); response.put(OAuth2Constants.Params.ERROR_DESCRIPTION, "A shared item with the name '" + resourceSetDescription.getName() + "' already exists"); return new JsonRepresentation(response); } JsonValue labels = resourceSetDescription.getDescription().get(OAuth2Constants.ResourceSets.LABELS); resourceSetDescription.getDescription().remove(OAuth2Constants.ResourceSets.LABELS); for (ResourceRegistrationFilter filter : extensionFilterManager.getFilters(ResourceRegistrationFilter.class)) { filter.beforeResourceRegistration(resourceSetDescription); } store.create(oAuth2Request, resourceSetDescription); if (labels.isNotNull()) { resourceSetDescription.getDescription().add(OAuth2Constants.ResourceSets.LABELS, labels.asSet()); } labelRegistration.updateLabelsForNewResourceSet(resourceSetDescription); for (ResourceRegistrationFilter filter : extensionFilterManager.getFilters(ResourceRegistrationFilter.class)) { filter.afterResourceRegistration(resourceSetDescription); } for (ResourceSetRegistrationHook hook : hooks) { hook.resourceSetCreated(oAuth2Request.<String>getParameter("realm"), resourceSetDescription); } getResponse().setStatus(Status.SUCCESS_CREATED); return createJsonResponse(resourceSetDescription, false, true); } @Inject  ResourceSetRegistrationEndpoint(OAuth2ProviderSettingsFactory providerSettingsFactory,
            ResourceSetDescriptionValidator validator, OAuth2RequestFactory<?, Request> requestFactory,
            Set<ResourceSetRegistrationHook> hooks, ResourceSetLabelRegistration labelRegistration,
            ExtensionFilterManager extensionFilterManager, ExceptionHandler exceptionHandler,
            UmaLabelsStore umaLabelsStore, JacksonRepresentationFactory jacksonRepresentationFactory); @Post Representation createResourceSet(JsonRepresentation entity); @Put Representation updateResourceSet(JsonRepresentation entity); @Get Representation readOrListResourceSet(); @Delete Representation deleteResourceSet();  }### Answer:
@Test @SuppressWarnings("unchecked") public void shouldNotCreateExistingResourceSetDescription() throws Exception { JsonRepresentation entity = createCreateRequestRepresentation(); when(store.query(any(QueryFilter.class))).thenReturn( asSet(new ResourceSetDescription("id", "CLIENT_ID", "RESOURCE_OWNER_ID", RESOURCE_SET_DESCRIPTION_CONTENT.asMap()))); noConditions(); Representation result = endpoint.createResourceSet(entity); ArgumentCaptor<QueryFilter> queryCaptor = ArgumentCaptor.forClass(QueryFilter.class); verify(store).query(queryCaptor.capture()); verifyZeroInteractions(resourceRegistrationFilter); String queryString = queryCaptor.getValue().toString(); assertThat(queryString) .contains("name eq \"NAME\"") .contains("clientId eq \"CLIENT_ID\"") .contains("resourceOwnerId eq \"RESOURCE_OWNER_ID\"") .doesNotContain(" or "); verify(response).setStatus(Status.CLIENT_ERROR_BAD_REQUEST); assertThat(result).isInstanceOf(JsonRepresentation.class); assertThat(((JsonRepresentation) result).getJsonObject().get("error")).isEqualTo("Bad Request"); assertThat(((JsonRepresentation) result).getJsonObject().getString("error_description")).contains("'NAME' already exists"); }