From 6926ba06476758d7709e4e33b2c27698c904c7be Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 19 Jul 2012 16:47:43 +0000 Subject: [PATCH] pmd: added test for bug 3484404 (NPathComplexity and return statements) git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7705 51baf565-9d33-0410-a72c-fc3788e3496d --- .../rule/codesize/NPathComplexityTest.java | 23 ++++++++++++-- .../rule/codesize/xml/NPathComplexity.xml | 31 +++++++++++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/codesize/NPathComplexityTest.java b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/codesize/NPathComplexityTest.java index 45385331dc..0b3fdb7b3c 100644 --- a/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/codesize/NPathComplexityTest.java +++ b/pmd/src/test/java/net/sourceforge/pmd/lang/java/rule/codesize/NPathComplexityTest.java @@ -10,7 +10,6 @@ import java.util.Iterator; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleViolation; -import net.sourceforge.pmd.lang.java.rule.codesize.NPathComplexityRule; import net.sourceforge.pmd.testframework.RuleTst; import net.sourceforge.pmd.testframework.TestDescriptor; @@ -33,10 +32,30 @@ public class NPathComplexityTest extends RuleTst { rule.setProperty(NPathComplexityRule.MINIMUM_DESCRIPTOR, 1.0); Report report = new Report(); runTestFromString(tests[0].getCode(), rule, report); - Iterator i = report.iterator(); + Iterator i = report.iterator(); RuleViolation rv = (RuleViolation) i.next(); assertEquals("correct violation message", "The method bar() has an NPath complexity of 2", rv.getDescription()); } + + /** + * Runs the 3rd test case with the proper threshold property. + * @throws Exception any error + */ + @Test + public void testReturnValueComplexity() throws Exception { + rule.setProperty(NPathComplexityRule.MINIMUM_DESCRIPTOR, 25.0); + Report report = new Report(); + runTestFromString(tests[2].getCode(), rule, report); + Iterator i = report.iterator(); + String descriptions = ""; + while (i.hasNext()) { + RuleViolation violation = i.next(); + descriptions += violation.getDescription() + "\n"; + } + assertEquals("expected violations", 2, report.size()); + assertEquals("The method x() has an NPath complexity of 25\nThe method y() has an NPath complexity of 25\n", + descriptions); + } public static junit.framework.Test suite() { return new junit.framework.JUnit4TestAdapter(NPathComplexityTest.class); diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NPathComplexity.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NPathComplexity.xml index 98cf228805..c8559fb478 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NPathComplexity.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/codesize/xml/NPathComplexity.xml @@ -39,4 +39,35 @@ public class Foo { } ]]> + + + 0 + +