### Question:
ExplicitlyAllowedValuesDBListQueryBuilder implements QueryBuilder<DBListClass> { @Override public Query build(DBListClass dbListClass) throws QueryException { String statement = dbListClass.getSql(); DocumentReference authorReference = dbListClass.getOwnerDocument().getAuthorReference(); if (this.authorizationManager.hasAccess(Right.SCRIPT, authorReference, dbListClass.getReference())) { String namespace = this.entityReferenceSerializer.serialize(dbListClass.getDocumentReference()); try { statement = this.authorExecutor.call(() -> evaluateVelocityCode(dbListClass.getSql(), namespace), authorReference, dbListClass.getDocumentReference()); } catch (Exception e) { this.logger.warn( "Failed to evaluate the Velocity code from the query [{}]." + " Root cause is [{}]. Continuing with the raw query.", statement, ExceptionUtils.getRootCauseMessage(e)); } } Query query = this.secureQueryManager.createQuery(statement, Query.HQL); query.setWiki(dbListClass.getOwnerDocument().getDocumentReference().getWikiReference().getName()); return query; }  @Override Query build(DBListClass dbListClass);  }### Answer:
@Test public void buildWithScriptRight() throws Exception { DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference(); when(this.authorizationManager.hasAccess(Right.SCRIPT, authorReference, dbListClass.getReference())) .thenReturn(true); AuthorExecutor authorExector = this.mocker.getInstance(AuthorExecutor.class); String evaluatedStatement = "test"; when(authorExector.call(any(), eq(authorReference), eq(this.dbListClass.getDocumentReference()))) .thenReturn(evaluatedStatement); Query query = mock(Query.class); when(this.secureQueryManager.createQuery(evaluatedStatement, Query.HQL)).thenReturn(query); assertSame(query, this.mocker.getComponentUnderTest().build(this.dbListClass)); }
@Test public void buildWithoutScriptRight() throws Exception { Query query = mock(Query.class); when(this.secureQueryManager.createQuery(this.dbListClass.getSql(), Query.HQL)).thenReturn(query); assertSame(query, this.mocker.getComponentUnderTest().build(this.dbListClass)); verify(query).setWiki("math"); }