RuleSetReferenceId { public static List<RuleSetReferenceId> parse(String referenceString) { List<RuleSetReferenceId> references = new ArrayList<>(); if (referenceString != null && referenceString.trim().length() > 0) { if (referenceString.indexOf(',') == -1) { references.add(new RuleSetReferenceId(referenceString)); } else { for (String name : referenceString.split(",")) { references.add(new RuleSetReferenceId(name.trim())); } } } return references; } RuleSetReferenceId(final String id);  RuleSetReferenceId(final String id, final RuleSetReferenceId externalRuleSetReferenceId); static List<RuleSetReferenceId> parse(String referenceString); boolean isExternal(); boolean isAllRules(); String getRuleSetFileName(); String getRuleName(); InputStream getInputStream(final ResourceLoader rl); @Override String toString();  }
@Test public void testOneSimpleRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("dummy-basic"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "rulesets/dummy/basic.xml", true, null, "rulesets/dummy/basic.xml", references.get(0)); }
@Test public void testMultipleSimpleRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("dummy-unusedcode,dummy-basic"); assertEquals(2, references.size()); assertRuleSetReferenceId(true, "rulesets/dummy/unusedcode.xml", true, null, "rulesets/dummy/unusedcode.xml", references.get(0)); assertRuleSetReferenceId(true, "rulesets/dummy/basic.xml", true, null, "rulesets/dummy/basic.xml", references.get(1)); }
@Test public void testMultipleRulesWithSpaces() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("dummy-basic, dummy-unusedcode, dummy2-basic"); assertEquals(3, references.size()); assertRuleSetReferenceId(true, "rulesets/dummy/basic.xml", true, null, "rulesets/dummy/basic.xml", references.get(0)); assertRuleSetReferenceId(true, "rulesets/dummy/unusedcode.xml", true, null, "rulesets/dummy/unusedcode.xml", references.get(1)); assertRuleSetReferenceId(true, "rulesets/dummy2/basic.xml", true, null, "rulesets/dummy2/basic.xml", references.get(2)); }
@Test public void testOneReleaseRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("50"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "rulesets/releases/50.xml", true, null, "rulesets/releases/50.xml", references.get(0)); }
@Test public void testOneFullRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("rulesets/java/unusedcode.xml"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "rulesets/java/unusedcode.xml", true, null, "rulesets/java/unusedcode.xml", references.get(0)); }
@Test public void testOneFullRuleSetURL() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("file: assertEquals(1, references.size()); assertRuleSetReferenceId(true, "file: "file: }
@Test public void testMultipleFullRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId .parse("rulesets/java/unusedcode.xml,rulesets/java/basic.xml"); assertEquals(2, references.size()); assertRuleSetReferenceId(true, "rulesets/java/unusedcode.xml", true, null, "rulesets/java/unusedcode.xml", references.get(0)); assertRuleSetReferenceId(true, "rulesets/java/basic.xml", true, null, "rulesets/java/basic.xml", references.get(1)); }
@Test public void testMixRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("rulesets/dummy/unusedcode.xml,dummy2-basic"); assertEquals(2, references.size()); assertRuleSetReferenceId(true, "rulesets/dummy/unusedcode.xml", true, null, "rulesets/dummy/unusedcode.xml", references.get(0)); assertRuleSetReferenceId(true, "rulesets/dummy2/basic.xml", true, null, "rulesets/dummy2/basic.xml", references.get(1)); }
@Test public void testUnknownRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("nonexistant.xml"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "nonexistant.xml", true, null, "nonexistant.xml", references.get(0)); }
@Test public void testUnknownAndSimpleRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("dummy-basic,nonexistant.xml"); assertEquals(2, references.size()); assertRuleSetReferenceId(true, "rulesets/dummy/basic.xml", true, null, "rulesets/dummy/basic.xml", references.get(0)); assertRuleSetReferenceId(true, "nonexistant.xml", true, null, "nonexistant.xml", references.get(1)); }
@Test public void testSimpleRuleSetAndRule() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("dummy-basic/DummyBasicMockRule"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "rulesets/dummy/basic.xml", false, "DummyBasicMockRule", "rulesets/dummy/basic.xml/DummyBasicMockRule", references.get(0)); }
@Test public void testFullRuleSetAndRule() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("rulesets/java/basic.xml/EmptyCatchBlock"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "rulesets/java/basic.xml", false, "EmptyCatchBlock", "rulesets/java/basic.xml/EmptyCatchBlock", references.get(0)); }
@Test public void testFullRuleSetURLAndRule() { List<RuleSetReferenceId> references = RuleSetReferenceId .parse("file: assertEquals(1, references.size()); assertRuleSetReferenceId(true, "file: "file: }
@Test public void testInternalRuleSetAndRule() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("EmptyCatchBlock"); assertEquals(1, references.size()); assertRuleSetReferenceId(false, null, false, "EmptyCatchBlock", "EmptyCatchBlock", references.get(0)); }
@Test public void testRelativePathRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("pmd/pmd-ruleset.xml"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "pmd/pmd-ruleset.xml", true, null, "pmd/pmd-ruleset.xml", references.get(0)); }
@Test public void testAbsolutePathRuleSet() { List<RuleSetReferenceId> references = RuleSetReferenceId.parse("/home/foo/pmd/pmd-ruleset.xml"); assertEquals(1, references.size()); assertRuleSetReferenceId(true, "/home/foo/pmd/pmd-ruleset.xml", true, null, "/home/foo/pmd/pmd-ruleset.xml", references.get(0)); }
@Test public void testFooRules() throws Exception { String fooRulesFile = new File("./src/test/resources/net/sourceforge/pmd/rulesets/foo-project/foo-rules") .getCanonicalPath(); List<RuleSetReferenceId> references = RuleSetReferenceId.parse(fooRulesFile); assertEquals(1, references.size()); assertRuleSetReferenceId(true, fooRulesFile, true, null, fooRulesFile, references.get(0)); }
@Test public void testNullRulesetString() throws Exception { List<RuleSetReferenceId> references = RuleSetReferenceId.parse(null); assertTrue(references.isEmpty()); }