### Question:
FilterBuilder { public TokenStream filter(TokenStream tokenStream, Collection<FilterDescription> filterDescriptions) throws FilterBuildingException { TokenStream filteredTokenStream = tokenStream; for (FilterDescription filterDescription : filterDescriptions) { String filterName = filterDescription.getName(); String factoryClassName = filterDescription.getFactoryClassName(); String className = filterDescription.getClassName(); currentLocateable = filterDescription; if (filterName != null && factoryClassName == null) { TokenFilterFactory tokenFilterFactory = cachedFactories.get(filterName); if (tokenFilterFactory == null) throw createException("No factory registered for " + filterName + ". Please provide a factory"); filteredTokenStream = createTokenFilter(filteredTokenStream, filterDescription, tokenFilterFactory); } else if (className != null) { filteredTokenStream = createTokenFilterWithClassName(filteredTokenStream, className); } else if (factoryClassName != null) { TokenFilterFactory tokenFilterFactory = createTokenFilterFactory(factoryClassName); filteredTokenStream = createTokenFilter(filteredTokenStream, filterDescription, tokenFilterFactory); if( filterDescription.isReuseFactory() ){ if( filterName == null ) throw createException("Provide a name for factory reuse "); cachedFactories.put(filterName, tokenFilterFactory); } } } return filteredTokenStream; } FilterBuilder(Map<String, TokenFilterFactory> predefinedFactories); TokenStream filter(TokenStream tokenStream,
          Collection<FilterDescription> filterDescriptions); static final Logger LOGGER; }### Answer:
@Test public void testFilterWithoutFactory() throws Exception{ Collection<FilterDescription> filterDescriptions = new ArrayList<FilterDescription>(); filterDescriptions.add(new FilterDescription(LowerCaseFilter.class.getCanonicalName(), null, null, false, null)); TokenStream filteredTokenStream = filterBuilder.filter(tokenStream, filterDescriptions); assertEquals(LowerCaseFilter.class, filteredTokenStream.getClass()); }
@Test public void testFilterWithFactory() throws Exception{ Collection<FilterDescription> filterDescriptions = new ArrayList<FilterDescription>(); filterDescriptions.add(new FilterDescription(null, DummyTokenFilterFactory.class.getCanonicalName(), null, false, null)); TokenStream filteredTokenStream = filterBuilder.filter(tokenStream, filterDescriptions); assertEquals(LowerCaseFilter.class, filteredTokenStream.getClass()); }