### Question:
DBListClassPropertyValuesProvider extends AbstractListClassPropertyValuesProvider<DBListClass> { @Override public PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue) throws XWikiRestException { PropertyValue propertyValue = null; DBListClass dbListClass = getPropertyDefinition(propertyReference); if (rawValue != null) { try { propertyValue = this.authorExecutor .call(() -> getValue(this.allowedValuesQueryBuilder.build(dbListClass), rawValue.toString(), dbListClass), dbListClass.getOwnerDocument().getAuthorReference(), dbListClass.getDocumentReference()); } catch (Exception e) { throw new XWikiRestException(e); } } if (propertyValue == null) { propertyValue = super.getValue(propertyReference, rawValue); } return propertyValue; }  @Override PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue);  }### Answer:
@Test public void getValuesMixedWithUsed() throws Exception { ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference); DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference(); PropertyValues values = new PropertyValues(); PropertyValue red = new PropertyValue(); red.setValue("red"); red.setMetaData(new HashMap<>()); red.getMetaData().put("label", "Red"); values.getPropertyValues().add(red); when(this.authorExecutor.call(any(), eq(authorReference), eq(this.dbListClass.getDocumentReference()))) .thenReturn(values); Query query = mock(Query.class); QueryParameter queryParameter = mock(QueryParameter.class); when(this.usedValuesQueryBuilder.build(dbListClass)).thenReturn(query); when(query.bindValue("text")).thenReturn(queryParameter); when(queryParameter.anyChars()).thenReturn(queryParameter); when(queryParameter.literal("bar")).thenReturn(queryParameter); when(query.execute()).thenReturn(Arrays.asList(new Object[] { "blue", 21L }, new Object[] { "red", 17L })); assertSame(values, this.provider.getValues(propertyReference, 3, "bar")); verify(query).setLimit(2); verify(query).addFilter(this.componentManager.getInstance(QueryFilter.class, "text")); verify(queryParameter, times(2)).anyChars(); assertEquals(2, values.getPropertyValues().size()); assertEquals("red", values.getPropertyValues().get(0).getValue()); assertEquals(17L, values.getPropertyValues().get(0).getMetaData().get("count")); assertEquals("blue", values.getPropertyValues().get(1).getValue()); assertEquals(21L, values.getPropertyValues().get(1).getMetaData().get("count")); }
@Test public void getValue() throws Exception { ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference); when(this.authorExecutor.call(any(), any(), any())) .thenAnswer(answer -> ((Callable) answer.getArgument(0)).call()); PropertyValue red = new PropertyValue(); red.setValue("red"); red.setMetaData(new HashMap<>()); red.getMetaData().put("label", "Red"); Query query = mock(Query.class); QueryParameter queryParameter = mock(QueryParameter.class); when(this.allowedValuesQueryBuilder.build(dbListClass)).thenReturn(query); when(query.bindValue("text")).thenReturn(queryParameter); when(queryParameter.literal("red")).thenReturn(queryParameter); when(query.execute()).thenReturn(Collections.singletonList(new Object[] { "red", "Red" })); PropertyValue propertyValue = this.provider.getValue(propertyReference, "red"); assertEquals(red.getValue(), propertyValue.getValue()); assertEquals(red.getMetaData(), propertyValue.getMetaData()); verify(query).addFilter(this.componentManager.getInstance(QueryFilter.class, "text")); }