}
@Test
public void testFilterWithNamedAndCachedFactory() throws Exception{
Collection<FilterDescription> filterDescriptions = new ArrayList<FilterDescription>();
filterDescriptions.add(new FilterDescription(null, DummyTokenFilterFactory.class.getCanonicalName(), LOWER_CASE_FACTORY_ID, true, null));
TokenStream filteredTokenStream = filterBuilder.filter(tokenStream, filterDescriptions);
assertEquals(LowerCaseFilter.class, filteredTokenStream.getClass());
Map<String, TokenFilterFactory> cachedFactories = filterBuilder.getCachedFactories();
assertEquals(LOWER_CASE_FACTORY_ID, cachedFactories.keySet().iterator().next());
assertTrue(cachedFactories.get(LOWER_CASE_FACTORY_ID) instanceof DummyTokenFilterFactory);
// test caching
filterDescriptions = new ArrayList<FilterDescription>();
filterDescriptions.add(new FilterDescription(null, null, LOWER_CASE_FACTORY_ID, true, null));
TokenFilterFactory factory = createMock(TokenFilterFactory.class);
expect(factory.createTokenFilter(tokenStream, null)).andReturn(null);
replay(factory);
cachedFactories.put(LOWER_CASE_FACTORY_ID, factory);