forked from phoedos/pmd
[test] fix language version tests to check registered rulesets
Now categories.properties are tested. rulesets.properties is only tested, if it exists.
This commit is contained in:
@ -7,6 +7,7 @@ package net.sourceforge.pmd;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ public class AbstractLanguageVersionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Makes sure, that for each language a "rulesets.properties" file exists.
|
* Makes sure, that for each language a "categories.properties" file exists.
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* any error
|
* any error
|
||||||
@ -117,10 +118,41 @@ public class AbstractLanguageVersionTest {
|
|||||||
|
|
||||||
ResourceLoader rl = new ResourceLoader();
|
ResourceLoader rl = new ResourceLoader();
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
String rulesetsProperties = "rulesets/" + simpleTerseName + "/rulesets.properties";
|
String rulesetsProperties = "category/" + simpleTerseName + "/categories.properties";
|
||||||
try (InputStream inputStream = rl.loadClassPathResourceAsStreamOrThrow(rulesetsProperties)) {
|
try (InputStream inputStream = rl.loadClassPathResourceAsStreamOrThrow(rulesetsProperties)) {
|
||||||
props.load(inputStream);
|
props.load(inputStream);
|
||||||
}
|
}
|
||||||
|
assertRulesetsAndCategoriesProperties(rl, props);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a rulesets.properties file still exists, test it as well.
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
* any error
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testOldRegisteredRulesets() throws Exception {
|
||||||
|
// only check for languages, that support rules
|
||||||
|
if (expected == null || expected.getLanguage().getRuleChainVisitorClass() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceLoader rl = new ResourceLoader();
|
||||||
|
Properties props = new Properties();
|
||||||
|
String rulesetsProperties = "rulesets/" + simpleTerseName + "/rulesets.properties";
|
||||||
|
InputStream inputStream = rl.loadClassPathResourceAsStream(rulesetsProperties);
|
||||||
|
if (inputStream != null) {
|
||||||
|
// rulesets.properties file exists
|
||||||
|
try (InputStream in = inputStream) {
|
||||||
|
props.load(in);
|
||||||
|
}
|
||||||
|
assertRulesetsAndCategoriesProperties(rl, props);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertRulesetsAndCategoriesProperties(ResourceLoader rl, Properties props)
|
||||||
|
throws IOException, RuleSetNotFoundException {
|
||||||
String rulesetFilenames = props.getProperty("rulesets.filenames");
|
String rulesetFilenames = props.getProperty("rulesets.filenames");
|
||||||
assertNotNull(rulesetFilenames);
|
assertNotNull(rulesetFilenames);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user