Add tests for CognitiveComplexity
This commit is contained in:
@ -20,6 +20,7 @@ public class AllMetricsTest extends SimpleAggregatorTst {
|
||||
public void setUp() {
|
||||
addRule(RULESET, "CycloTest");
|
||||
addRule(RULESET, "WmcTest");
|
||||
addRule(RULESET, "CognitiveComplexityTest");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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>
|
@ -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>
|
||||
|
Reference in New Issue
Block a user