PrefixedPatternDefinitionResolver extends
        AbstractPatternDefinitionResolver<T> { @Override protected Map<String, Definition> addDefinitionsAsPatternMatchers( List<DefinitionPatternMatcher> matchers, Map<String, Definition> defsMap) { Set<String> excludedKeys = new LinkedHashSet<String>(); for (Map.Entry<String, Definition> entry : defsMap.entrySet()) { String key = entry.getKey(); Expression expression = Expression .createExpressionFromDescribedExpression(key); if (expression.getLanguage() != null) { DefinitionPatternMatcherFactory factory = language2matcherFactory .get(expression.getLanguage()); if (factory != null) { DefinitionPatternMatcher matcher = factory .createDefinitionPatternMatcher(expression .getExpression(), new Definition(entry .getValue())); matchers.add(matcher); } else { logger.warn("Cannot find a DefinitionPatternMatcherFactory for expression '{}'", key); } } else { excludedKeys.add(key); } } return PatternUtil.createExtractedMap(defsMap, excludedKeys); } PrefixedPatternDefinitionResolver(); void registerDefinitionPatternMatcherFactory(String language,
            DefinitionPatternMatcherFactory factory);  }
@Test public void testAddDefinitionsAsPatternMatchers() { DefinitionPatternMatcherFactory factory1 = createMock(DefinitionPatternMatcherFactory.class); DefinitionPatternMatcherFactory factory2 = createMock(DefinitionPatternMatcherFactory.class); DefinitionPatternMatcher matcher1 = createMock(DefinitionPatternMatcher.class); DefinitionPatternMatcher matcher2 = createMock(DefinitionPatternMatcher.class); Definition definition1 = new Definition("DF1:definition1", (Attribute) null, null); Definition definition2 = new Definition("DF2:definition2", (Attribute) null, null); Definition definition3 = new Definition("noLanguageHere", (Attribute) null, null); expect(factory1.createDefinitionPatternMatcher("definition1", definition1)).andReturn(matcher1); expect(factory2.createDefinitionPatternMatcher("definition2", definition2)).andReturn(matcher2); replay(factory1, factory2, matcher1, matcher2); PrefixedPatternDefinitionResolver<Integer> resolver = new PrefixedPatternDefinitionResolver<Integer>(); resolver.registerDefinitionPatternMatcherFactory("DF1", factory1); resolver.registerDefinitionPatternMatcherFactory("DF2", factory2); List<DefinitionPatternMatcher> matchers = new ArrayList<DefinitionPatternMatcher>(); Map<String, Definition> definitions = new LinkedHashMap<String, Definition>(); definitions.put("DF1:definition1", definition1); definitions.put("DF2:definition2", definition2); definitions.put("noLanguageHere", definition3); resolver.addDefinitionsAsPatternMatchers(matchers, definitions); assertEquals(2, matchers.size()); assertEquals(matcher1, matchers.get(0)); assertEquals(matcher2, matchers.get(1)); verify(factory1, factory2, matcher1, matcher2); }