### Question:
UsedValuesListQueryBuilder implements QueryBuilder<ListClass> { @Override public Query build(ListClass listClass) throws QueryException { String statement = String.format("select %1$s, count(*) as unfilterable0 " + "from BaseObject as obj, %2$s " + "where obj.className = :className and obj.name <> :templateName" + " and prop.id.id = obj.id and prop.id.name = :propertyName " + "group by %1$s " + "order by count(*) desc", getSelectColumnAndFromTable(listClass)); Query query = this.queryManager.createQuery(statement, Query.HQL); bindParameterValues(query, listClass); query.addFilter(new ViewableValueFilter(listClass)); query.setWiki(listClass.getReference().extractReference(EntityType.WIKI).getName()); return query; }  @Override Query build(ListClass listClass);  }### Answer:
@Test public void buildForStringProperty() throws Exception { listClass.setMultiSelect(false); Query query = mock(Query.class); when(this.queryManager.createQuery( "select prop.value, count(*) as unfilterable0 " + "from BaseObject as obj, StringProperty as prop " + "where obj.className = :className and obj.name <> :templateName" + " and prop.id.id = obj.id and prop.id.name = :propertyName " + "group by prop.value " + "order by count(*) desc", Query.HQL)).thenReturn(query); assertSame(query, this.usedValuesListQueryBuilder.build(listClass)); verify(query).bindValue("className", "Blog.BlogPostClass"); verify(query).bindValue("propertyName", "category"); verify(query).bindValue("templateName", "Blog.BlogPostTemplate"); verify(query).setWiki("apps"); }
@Test public void buildForDBStringListProperty() throws Exception { listClass.setMultiSelect(true); listClass.setRelationalStorage(true); Query query = mock(Query.class); when(this.queryManager.createQuery("select listItem, count(*) as unfilterable0 " + "from BaseObject as obj, DBStringListProperty as prop join prop.list listItem " + "where obj.className = :className and obj.name <> :templateName" + " and prop.id.id = obj.id and prop.id.name = :propertyName " + "group by listItem " + "order by count(*) desc", Query.HQL)).thenReturn(query); assertSame(query, this.usedValuesListQueryBuilder.build(listClass)); }
@Test public void buildForStringListProperty() throws Exception { listClass.setMultiSelect(true); listClass.setRelationalStorage(false); Query query = mock(Query.class); when(this.queryManager.createQuery( "select prop.textValue, count(*) as unfilterable0 " + "from BaseObject as obj, StringListProperty as prop " + "where obj.className = :className and obj.name <> :templateName" + " and prop.id.id = obj.id and prop.id.name = :propertyName " + "group by prop.textValue " + "order by count(*) desc", Query.HQL)).thenReturn(query); assertSame(query, this.usedValuesListQueryBuilder.build(listClass)); }