[apex] Verify StdCyclomaticComplexity with triggers

This commit is contained in:
Andreas Dangel 2024-09-06 19:51:52 +02:00
parent 1038eaa283
commit 5f1b13cadd
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,11 @@
/**
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
*/
package net.sourceforge.pmd.lang.apex.rule.design;
import net.sourceforge.pmd.test.PmdRuleTst;
class StdCyclomaticComplexityTest extends PmdRuleTst {
// no additional unit tests
}

View File

@ -173,4 +173,36 @@ public class Test {
<expected-problems>0</expected-problems>
<code-ref id="constructor-violation"/>
</test-code>
<test-code>
<description>StdCyclomaticComplexity for triggers</description>
<rule-property name="reportLevel">1</rule-property>
<expected-problems>3</expected-problems>
<expected-messages>
<message>The method 'invoke' has a Standard Cyclomatic Complexity of 4.</message>
<message>The trigger 'Accounts' has a Standard Cyclomatic Complexity of 4 (Highest = 4).</message>
<message>The method 'anotherMethod' has a Standard Cyclomatic Complexity of 3.</message>
</expected-messages>
<code><![CDATA[
trigger Accounts on Account (before insert, before update, before delete, after insert, after update, after delete, after undelete) {
for(Account acc : Trigger.new) {
if(Trigger.isInsert) {
// ...
}
// ...
if(Trigger.isDelete) {
// ...
}
}
void anotherMethod(Integer i) {
if (i == 1) {
} else if (i == 2) {
}
}
}
]]></code>
</test-code>
</test-data>