Fix more tests

This commit is contained in:
Clément Fournier
2022-02-06 13:45:33 +01:00
parent 42b1fa1314
commit a8966e9749
5 changed files with 12 additions and 4 deletions

View File

@ -86,8 +86,10 @@ public class ApexSharingViolationsNestedClassTest extends RuleTst {
public void testSharingPermutation() {
String apexClass = generateClass(outerSharingDeclared, outerOperation, innerSharingDeclared, innerOperation);
Report rpt = new Report();
runTestFromString(apexClass, new ApexSharingViolationsRule(), rpt,
LanguageRegistry.getLanguage(ApexLanguageModule.NAME).getDefaultVersion());
ApexSharingViolationsRule rule = new ApexSharingViolationsRule();
rule.setMessage("a message");
runTestFromString(apexClass, rule, rpt,
LanguageRegistry.getLanguage(ApexLanguageModule.NAME).getDefaultVersion());
List<RuleViolation> violations = rpt.getViolations();
assertEquals("Unexpected Violation Size\n" + apexClass, expectedViolations, violations.size());
List<Integer> lineNumbers = violations.stream().map(v -> v.getBeginLine()).collect(Collectors.toList());

View File

@ -35,7 +35,7 @@ public class AvoidTabCharacterRule extends AbstractPLSQLRule {
while ((line = in.readLine()) != null) {
lineNumber++;
if (line.indexOf('\t') != -1) {
addViolationWithMessage(data, null, "Tab characters are not allowed. Use spaces for indentation",
addViolationWithMessage(data, node, "Tab characters are not allowed. Use spaces for indentation",
lineNumber, lineNumber);
if (!eachLine) {

View File

@ -43,7 +43,7 @@ public class LineLengthRule extends AbstractPLSQLRule {
while ((line = in.readLine()) != null) {
lineNumber++;
if (line.length() > maxLineLength) {
addViolationWithMessage(data, null, "The line is too long. Only " + maxLineLength + " characters are allowed.",
addViolationWithMessage(data, node, "The line is too long. Only " + maxLineLength + " characters are allowed.",
lineNumber, lineNumber);
if (!eachLine) {

View File

@ -59,6 +59,7 @@ public class PLSQLXPathRuleTest extends AbstractPLSQLParserTst {
rule.setMessage("Test Violation");
RuleContext ctx = new RuleContext();
ctx.setCurrentRule(rule);
ctx.setLanguageVersion(plsql.getDefaultVersion());
rule.apply(singletonList(node), ctx);

View File

@ -42,6 +42,11 @@ public class ScalaRuleTest extends BaseScalaTest {
@Test
public void testDummyRule() {
ScalaRule rule = new ScalaRule() {
@Override
public String getMessage() {
return "a message";
}
@Override
public RuleContext visit(ASTTermApply node, RuleContext data) {
ASTTermName child = node.getFirstChildOfType(ASTTermName.class);