Skip to content

Commit

Permalink
[test] fix language version tests to check registered rulesets
Browse files Browse the repository at this point in the history
Now categories.properties are tested. rulesets.properties
is only tested, if it exists.
  • Loading branch information
adangel committed Sep 7, 2019
1 parent 4bb1161 commit 20c7d7f
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

Expand Down Expand Up @@ -103,7 +104,7 @@ public void testFindVersionsForLanguageNameAndVersion() {
}

/**
* Makes sure, that for each language a "rulesets.properties" file exists.
* Makes sure, that for each language a "categories.properties" file exists.
*
* @throws Exception
* any error
Expand All @@ -117,10 +118,41 @@ public void testRegisteredRulesets() throws Exception {

ResourceLoader rl = new ResourceLoader();
Properties props = new Properties();
String rulesetsProperties = "rulesets/" + simpleTerseName + "/rulesets.properties";
String rulesetsProperties = "category/" + simpleTerseName + "/categories.properties";
try (InputStream inputStream = rl.loadClassPathResourceAsStreamOrThrow(rulesetsProperties)) {
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");
assertNotNull(rulesetFilenames);

Expand Down

0 comments on commit 20c7d7f

Please sign in to comment.