001: /**
002: * <copyright>
003: * Copyright 1997-2002 InfoEther, LLC
004: * under sponsorship of the Defense Advanced Research Projects Agency
005: (DARPA).
006: *
007: * This program is free software; you can redistribute it and/or modify
008: * it under the terms of the Cougaar Open Source License as published
009: by
010: * DARPA on the Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THE COUGAAR SOFTWARE AND ANY DERIVATIVE SUPPLIED BY LICENSOR IS
013: * PROVIDED 'AS IS' WITHOUT WARRANTIES OF ANY KIND, WHETHER EXPRESS OR
014: * IMPLIED, INCLUDING (BUT NOT LIMITED TO) ALL IMPLIED WARRANTIES OF
015: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND WITHOUT
016: * ANY WARRANTIES AS TO NON-INFRINGEMENT. IN NO EVENT SHALL COPYRIGHT
017: * HOLDER BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT OR CONSEQUENTIAL
018: * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE OF DATA OR PROFITS,
019: * TORTIOUS CONDUCT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
020: * PERFORMANCE OF THE COUGAAR SOFTWARE.
021: * </copyright>
022: */package test.net.sourceforge.pmd;
023:
024: import static org.junit.Assert.assertEquals;
025: import static org.junit.Assert.assertTrue;
026: import junit.framework.JUnit4TestAdapter;
027: import net.sourceforge.pmd.MockRule;
028: import net.sourceforge.pmd.Rule;
029: import net.sourceforge.pmd.RuleContext;
030: import net.sourceforge.pmd.RuleViolation;
031: import net.sourceforge.pmd.ast.SimpleJavaNode;
032: import net.sourceforge.pmd.ast.SimpleNode;
033:
034: import org.junit.Ignore;
035: import org.junit.Test;
036:
037: public class RuleViolationTest {
038:
039: @Ignore
040: @Test
041: public void testConstructor1() {
042: Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
043: RuleContext ctx = new RuleContext();
044: ctx.setSourceCodeFilename("filename");
045: SimpleNode s = new SimpleJavaNode(1);
046: s.testingOnly__setBeginLine(2);
047: RuleViolation r = new RuleViolation(rule, ctx, s);
048: assertEquals("object mismatch", rule, r.getRule());
049: assertEquals("line number is wrong", 2, r.getBeginLine());
050: assertEquals("filename is wrong", "filename", r.getFilename());
051: }
052:
053: @Ignore
054: @Test
055: public void testConstructor2() {
056: Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
057: RuleContext ctx = new RuleContext();
058: ctx.setSourceCodeFilename("filename");
059: SimpleNode s = new SimpleJavaNode(1);
060: s.testingOnly__setBeginLine(2);
061: RuleViolation r = new RuleViolation(rule, ctx, s, "description");
062: assertEquals("object mismatch", rule, r.getRule());
063: assertEquals("line number is wrong", 2, r.getBeginLine());
064: assertEquals("filename is wrong", "filename", r.getFilename());
065: assertEquals("description is wrong", "description", r
066: .getDescription());
067: }
068:
069: @Ignore
070: @Test
071: public void testComparatorWithDifferentFilenames() {
072: Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
073: RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
074: RuleContext ctx = new RuleContext();
075: ctx.setSourceCodeFilename("filename1");
076: SimpleNode s = new SimpleJavaNode(1);
077: s.testingOnly__setBeginLine(10);
078: RuleViolation r1 = new RuleViolation(rule, ctx, s,
079: "description");
080: ctx.setSourceCodeFilename("filename2");
081: SimpleNode s1 = new SimpleJavaNode(1);
082: s1.testingOnly__setBeginLine(10);
083: RuleViolation r2 = new RuleViolation(rule, ctx, s1,
084: "description");
085: assertEquals(-1, comp.compare(r1, r2));
086: assertEquals(1, comp.compare(r2, r1));
087: }
088:
089: @Ignore
090: @Test
091: public void testComparatorWithSameFileDifferentLines() {
092: Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
093: RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
094: RuleContext ctx = new RuleContext();
095: ctx.setSourceCodeFilename("filename");
096: SimpleNode s = new SimpleJavaNode(1);
097: s.testingOnly__setBeginLine(10);
098: SimpleNode s1 = new SimpleJavaNode(1);
099: s1.testingOnly__setBeginLine(20);
100: RuleViolation r1 = new RuleViolation(rule, ctx, s,
101: "description");
102: RuleViolation r2 = new RuleViolation(rule, ctx, s1,
103: "description");
104: assertTrue(comp.compare(r1, r2) < 0);
105: assertTrue(comp.compare(r2, r1) > 0);
106: }
107:
108: @Ignore
109: @Test
110: public void testComparatorWithSameFileSameLines() {
111: Rule rule = new MockRule("name", "desc", "msg", "rulesetname");
112: RuleViolation.RuleViolationComparator comp = new RuleViolation.RuleViolationComparator();
113: RuleContext ctx = new RuleContext();
114: ctx.setSourceCodeFilename("filename");
115: SimpleNode s = new SimpleJavaNode(1);
116: s.testingOnly__setBeginLine(10);
117: SimpleNode s1 = new SimpleJavaNode(1);
118: s1.testingOnly__setBeginLine(10);
119: RuleViolation r1 = new RuleViolation(rule, ctx, s,
120: "description");
121: RuleViolation r2 = new RuleViolation(rule, ctx, s1,
122: "description");
123: assertEquals(1, comp.compare(r1, r2));
124: assertEquals(1, comp.compare(r2, r1));
125: }
126:
127: public static junit.framework.Test suite() {
128: return new JUnit4TestAdapter(RuleViolationTest.class);
129: }
130: }
|