KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > net > sourceforge > pmd > RuleViolationTest


1 /**
2  * <copyright>
3  * Copyright 1997-2002 InfoEther, LLC
4  * under sponsorship of the Defense Advanced Research Projects Agency
5  (DARPA).
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the Cougaar Open Source License as published
9  by
10  * DARPA on the Cougaar Open Source Website (www.cougaar.org).
11  *
12  * THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
13  * PROVIDED 'AS IS' WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
14  * IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
16  * ANY WARRANTIES AS TO NON-INFRINGEMENT. IN NO EVENT SHALL COPYRIGHT
17  * HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
18  * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
19  * TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THE COUGAAR SOFTWARE.
21  * </copyright>
22  */

23 package test.net.sourceforge.pmd;
24
25 import junit.framework.TestCase;
26
27 public class RuleViolationTest extends TestCase {
28
29     public void testConstructor1() {
30 /*
31         Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
32         RuleContext ctx = new RuleContext();
33         ctx.setSourceCodeFilename("filename");
34         SimpleNode s = new SimpleJavaNode(1);
35         s.testingOnly__setBeginLine(2);
36         RuleViolation r = new RuleViolation(rule, ctx, s);
37         assertEquals("object mismatch", rule, r.getRule());
38         assertEquals("line number is wrong", 2, r.getBeginLine());
39         assertEquals("filename is wrong", "filename", r.getFilename());
40 */

41     }
42
43 /*
44     public void testConstructor2() {
45         Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
46         RuleContext ctx = new RuleContext();
47         ctx.setSourceCodeFilename("filename");
48         SimpleNode s = new SimpleJavaNode(1);
49         s.testingOnly__setBeginLine(2);
50         RuleViolation r = new RuleViolation(rule, ctx, s, "description");
51         assertEquals("object mismatch", rule, r.getRule());
52         assertEquals("line number is wrong", 2, r.getBeginLine());
53         assertEquals("filename is wrong", "filename", r.getFilename());
54         assertEquals("description is wrong", "description", r.getDescription());
55     }
56
57     public void testComparatorWithDifferentFilenames() {
58         Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
59         RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
60         RuleContext ctx = new RuleContext();
61         ctx.setSourceCodeFilename("filename1");
62         SimpleNode s = new SimpleJavaNode(1);
63         s.testingOnly__setBeginLine(10);
64         RuleViolation r1 = new RuleViolation(rule, ctx, s, "description");
65         ctx.setSourceCodeFilename("filename2");
66         SimpleNode s1 = new SimpleJavaNode(1);
67         s1.testingOnly__setBeginLine(10);
68         RuleViolation r2 = new RuleViolation(rule, ctx, s1, "description");
69         assertEquals(-1, comp.compare(r1, r2));
70         assertEquals(1, comp.compare(r2, r1));
71     }
72
73     public void testComparatorWithSameFileDifferentLines() {
74         Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
75         RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
76         RuleContext ctx = new RuleContext();
77         ctx.setSourceCodeFilename("filename");
78         SimpleNode s = new SimpleJavaNode(1);
79         s.testingOnly__setBeginLine(10);
80         SimpleNode s1 = new SimpleJavaNode(1);
81         s1.testingOnly__setBeginLine(20);
82         RuleViolation r1 = new RuleViolation(rule, ctx, s, "description");
83         RuleViolation r2 = new RuleViolation(rule, ctx, s1, "description");
84         assertTrue(comp.compare(r1, r2) < 0);
85         assertTrue(comp.compare(r2, r1) > 0);
86     }
87
88     public void testComparatorWithSameFileSameLines() {
89         Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
90         RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
91         RuleContext ctx = new RuleContext();
92         ctx.setSourceCodeFilename("filename");
93         SimpleNode s = new SimpleJavaNode(1);
94         s.testingOnly__setBeginLine(10);
95         SimpleNode s1 = new SimpleJavaNode(1);
96         s1.testingOnly__setBeginLine(10);
97         RuleViolation r1 = new RuleViolation(rule, ctx, s, "description");
98         RuleViolation r2 = new RuleViolation(rule, ctx, s1, "description");
99         assertEquals(1, comp.compare(r1, r2));
100         assertEquals(1, comp.compare(r2, r1));
101     }
102 */

103 }
104
Popular Tags