### Question:
SPARQLQueryStatistics { public void getStatistics(Query q) { if(q.isSelectType()) { size++; offset+=q.hasOffset()?1:0; aggr+=q.hasAggregators()?1:0; groupBy+=q.hasGroupBy()?1:0; having+=q.hasHaving()?1:0; orderBy+=q.hasOrderBy()?1:0; StatisticsVisitor visitor = new StatisticsVisitor(); visitor.setElementWhere(q.getQueryPattern()); ElementWalker.walk(q.getQueryPattern(), visitor); union+=visitor.union?1:0; optional+=visitor.optional?1:0; filter+=visitor.filter?1:0; triples += visitor.bgps; } }  void getStatistics(Query q); public int aggr; public int filter; public int optional; public int union; public int having; public int groupBy; public int offset; public double size; public int orderBy; public int triples; }### Answer:
@Test public void checkCorrectStats(){ SPARQLQueryStatistics qs = new SPARQLQueryStatistics(); Query q = QueryFactory.create(this.query); qs.getStatistics(q); assertEquals(stats[0], qs.aggr); assertEquals(stats[1], qs.filter); assertEquals(stats[2], qs.optional); assertEquals(stats[3], qs.union); assertEquals(stats[4], qs.having); assertEquals(stats[5], qs.groupBy); assertEquals(stats[6], qs.offset); assertEquals(size, qs.size, 0); assertEquals(stats[7], qs.orderBy); assertEquals(stats[8], qs.triples); }