ProcessorConfig { public <T extends Named> List<T> prepareProcessors(List<T> namedList, String type) { List<T> ret = new ArrayList<>(); Map<String, T> lookup = new HashMap<>(); for (T named : namedList) { lookup.put(named.getName(), named); } for (String inc : includes) { if (use(inc)) { T named = lookup.get(inc); if (named == null) { List<String> keys = new ArrayList<>(lookup.keySet()); Collections.sort(keys); throw new IllegalArgumentException( "No " + type + " with name '" + inc + "' found to include. " + "Please check spelling in your profile / config and your project dependencies. Included " + type + "s: " + StringUtils.join(keys,", ")); } ret.add(named); } } return ret; } ProcessorConfig();  ProcessorConfig(List<String> includes, Set<String> excludes, Map<String, TreeMap> config); String getConfig(String name, String key); Map<String, String> getConfigMap(String name); List<T> prepareProcessors(List<T> namedList, String type); boolean use(String inc); static ProcessorConfig cloneProcessorConfig(ProcessorConfig processorConfig); static ProcessorConfig mergeProcessorConfigs(ProcessorConfig ... processorConfigs); static final ProcessorConfig EMPTY; }
@Test public void empty() { ProcessorConfig pConfig = new ProcessorConfig(Collections.<String>emptyList(), null, config); List<TestNamed> filtered = pConfig.prepareProcessors(getAllTestData(), "test"); assertFalse(contains(filtered, "i2")); assertFalse(contains(filtered, "e1")); assertFalse(contains(filtered, "n1")); }
@Test public void order() { List<TestNamed> data = Arrays.asList( new TestNamed("t1"), new TestNamed("t2"), new TestNamed("t3"), new TestNamed("t4")); List<String> inc = Arrays.asList("t4", "t2"); ProcessorConfig pConfig = new ProcessorConfig(inc, null, null); List<TestNamed> result = pConfig.prepareProcessors(data, "test"); assertEquals(2,result.size()); assertEquals("t4", result.get(0).getName()); assertEquals("t2", result.get(1).getName()); }
@Test public void orderWithInvalidInc() { List<TestNamed> data = Arrays.asList(new TestNamed("t1")); List<String> inc = Arrays.asList("t3", "t1"); ProcessorConfig pConfig = new ProcessorConfig(inc, null, null); try { pConfig.prepareProcessors(data, "bla"); fail(); } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("bla")); } }
@Test public void incAndExc() { ProcessorConfig pConfig = new ProcessorConfig(includes, excludes, config); List<TestNamed> filtered = pConfig.prepareProcessors(getAllTestData(), "test"); assertTrue(contains(filtered, "i2")); assertFalse(contains(filtered, "e1")); assertFalse(contains(filtered, "n1")); }
@Test public void inc() { ProcessorConfig pConfig = new ProcessorConfig(includes, null, config); List<TestNamed> filtered = pConfig.prepareProcessors(getAllTestData(), "test"); assertTrue(contains(filtered, "i2")); assertFalse(contains(filtered, "e1")); assertFalse(contains(filtered, "n1")); }
@Test public void exc() { ProcessorConfig pConfig = new ProcessorConfig(null, excludes, config); List<TestNamed> filtered = pConfig.prepareProcessors(getAllTestData(), "test"); assertFalse(contains(filtered, "i2")); assertFalse(contains(filtered, "e1")); assertFalse(contains(filtered, "n1")); }