AbstractQueryBuilderFactory { public void addFilterBefore(IRuleFilter filter, Class<? extends IRuleFilter> beforeFilter) { int index = getIndexOfClass(filters, beforeFilter); if (index == -1) { throw new FilterAddException("filter " + beforeFilter.getSimpleName() + " has not been added"); } filters.add(index, filter); } AbstractQueryBuilderFactory(); abstract AbstractBuilder builder(); void addFilter(IRuleFilter filter); void addFilterBefore(IRuleFilter filter, Class<? extends IRuleFilter> beforeFilter); void addFilterAfter(IRuleFilter filter, Class<? extends IRuleFilter> afterFilter); void addFilterAt(IRuleFilter filter, Class<? extends IRuleFilter> atFilter); void addRuleParser(IRuleParser parser); void addRuleParserBefore(IRuleParser parser, Class<? extends IRuleParser> beforeParser); void addRuleParserAfter(IRuleParser parser, Class<? extends IRuleParser> afterParser); void addRuleParserAt(IRuleParser parser, Class<? extends IRuleParser> atParser); List<IRuleFilter> getFilters(); List<IRuleParser> getRuleParsers(); IGroupParser getGroupParser(); void setGroupParser(IGroupParser groupParser);  }
@Test public void addFilterBefore() throws Exception { AbstractQueryBuilderFactory factory = new SqlQueryBuilderFactory(); factory.addFilterBefore(testFilter, ValidateFilter.class); Assert.assertEquals(getIndexOfClass(factory.getFilters(), testFilter.getClass()) + 1, getIndexOfClass(factory.getFilters(), ValidateFilter.class)); }
@Test(expected = FilterAddException.class) public void testAddFilterBeforeUnknownClass(){ AbstractQueryBuilderFactory factory = new SqlQueryBuilderFactory(); factory.addFilterBefore(testFilter, Test2Filter.class); }