Add tests for CognitiveComplexity

This commit is contained in:
Gwilym Kuiper
2020-02-18 11:40:30 +00:00
parent 01da573f5f
commit 8c357fb887
4 changed files with 51 additions and 0 deletions

View File

@ -20,6 +20,7 @@ public class AllMetricsTest extends SimpleAggregatorTst {
public void setUp() {
addRule(RULESET, "CycloTest");
addRule(RULESET, "WmcTest");
addRule(RULESET, "CognitiveComplexityTest");
}
}

View File

@ -0,0 +1,19 @@
package net.sourceforge.pmd.lang.apex.metrics.impl;
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey;
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey;
/**
* @author Gwilym Kuiper
*/
public class CognitiveComplexityTestRule extends AbstractApexMetricTestRule {
@Override
protected ApexClassMetricKey getClassKey() {
return null;
}
@Override
protected ApexOperationMetricKey getOpKey() {
return ApexOperationMetricKey.COGNITIVE;
}
}

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<test-data
xmlns="http://pmd.sourceforge.net/rule-tests"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd">
<test-code>
<description>If statements have complexity 1</description>
<expected-problems>1</expected-problems>
<expected-messages>
<message>'c__Foo#foo(Integer)' has value 1.</message>
</expected-messages>
<code>
<![CDATA[
class Foo {
string foo(integer n) {
if (n == 1) {
return "one";
}
return "not one";
}
}
]]>
</code>
</test-code>
</test-data>

View File

@ -19,4 +19,9 @@
class="net.sourceforge.pmd.lang.apex.metrics.impl.WmcTestRule">
</rule>
<rule name="CognitiveComplexityTest"
message = "''{0}'' has value {1}."
class="net.sourceforge.pmd.lang.apex.metrics.impl.CognitiveComplexityTestRule">
</rule>
</ruleset>