1
2 /***
3 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
4 */
5 package test/net/sourceforge/pmd/rules/package-summary.html">> test.net.sourceforge.pmd.rules;
6
7 import java.util.Iterator;
8
9 import net.sourceforge.pmd.Report;
10 import net.sourceforge.pmd.Rule;
11 import net.sourceforge.pmd.RuleViolation;
12 import test.net.sourceforge.pmd.testframework.RuleTst;
13 import test.net.sourceforge.pmd.testframework.TestDescriptor;
14
15 public class CyclomaticComplexityTest extends RuleTst {
16 private Rule rule;
17 private TestDescriptor[] tests;
18
19 public void setUp() {
20 rule = findRule("codesize", "CyclomaticComplexity");
21 tests = extractTestsFromXml(rule);
22 }
23
24 public void testOneMethod() throws Throwable {
25 rule.addProperty("reportLevel", "1");
26 Report report = new Report();
27 runTestFromString(tests[0].getCode(), rule, report);
28 Iterator i = report.iterator();
29 RuleViolation rv = (RuleViolation) i.next();
30 assertTrue(rv.getDescription().indexOf("Highest = 1") != -1);
31 }
32
33 public void testNastyComplicatedMethod() throws Throwable {
34 rule.addProperty("reportLevel", "10");
35 Report report = new Report();
36 runTestFromString(tests[1].getCode(), rule, report);
37 Iterator i = report.iterator();
38 RuleViolation rv = (RuleViolation) i.next();
39 assertTrue(rv.getDescription().indexOf("Highest = 11") != -1);
40 }
41
42 public void testConstructor() throws Throwable {
43 rule.addProperty("reportLevel", "1");
44 Report report = new Report();
45 runTestFromString(tests[2].getCode(), rule, report);
46 Iterator i = report.iterator();
47 RuleViolation rv = (RuleViolation) i.next();
48 assertTrue(rv.getDescription().indexOf("Highest = 1") != -1);
49 }
50
51 public void testLessComplicatedThanReportLevel() throws Throwable {
52 rule.addProperty("reportLevel", "10");
53 Report report = new Report();
54 runTestFromString(tests[0].getCode(), rule, report);
55 assertEquals(0, report.size());
56 }
57 }