@Test public void testReadCompoundSources() throws Exception { File adocFile = new File(getClass().getResource("/junit-without-assert.adoc").getFile()); File xmlFile = new File(getClass().getResource("/test-concepts.xml").getFile()); RuleSetReader reader = new CompoundRuleSetReader(); RuleSet ruleSet = reader.read(asList(new FileRuleSource(adocFile), new FileRuleSource(xmlFile))); assertEquals(3, ruleSet.getConcepts().size()); assertEquals(2, ruleSet.getConstraints().size()); for (String id : ruleSet.getConcepts().keySet()) { assertEquals( true, asList("junit4:TestClassOrMethod", "junit4:AssertMethod", "java:Throwable").contains(id)); } for (String id : ruleSet.getConstraints().keySet()) { assertEquals( true, asList("junit4:TestMethodWithoutAssertion", "example:ConstructorOfDateMustNotBeUsed") .contains(id)); } assertEquals(1, ruleSet.getGroups().size()); Group group = ruleSet.getGroups().values().iterator().next(); assertEquals("default", group.getId()); assertEquals(1, group.getConcepts().size()); assertEquals("java:Throwable", group.getConcepts().keySet().iterator().next()); assertEquals(1, group.getConstraints().size()); assertEquals( "example:ConstructorOfDateMustNotBeUsed", group.getConstraints().keySet().iterator().next()); }
@Test public void testReadUrlSource() throws Exception { URL url = getClass().getResource("/test-concepts.xml"); RuleSetReader reader = new XmlRuleSetReader(); RuleSet ruleSet = reader.read(Arrays.asList(new UrlRuleSource(url))); assertEquals(1, ruleSet.getConcepts().size()); assertEquals(1, ruleSet.getConstraints().size()); for (String id : ruleSet.getConcepts().keySet()) { assertEquals(true, asList("java:Throwable").contains(id)); } for (String id : ruleSet.getConstraints().keySet()) { assertEquals(true, asList("example:ConstructorOfDateMustNotBeUsed").contains(id)); } assertEquals(1, ruleSet.getGroups().size()); Group group = ruleSet.getGroups().values().iterator().next(); assertEquals("default", group.getId()); }