001: package test.net.sourceforge.pmd;
002:
003: import static org.junit.Assert.assertEquals;
004: import static org.junit.Assert.assertNull;
005: import junit.framework.JUnit4TestAdapter;
006: import net.sourceforge.pmd.MockRule;
007: import net.sourceforge.pmd.RuleReference;
008: import net.sourceforge.pmd.RuleSetReference;
009:
010: import org.junit.Test;
011:
012: public class RuleReferenceTest {
013:
014: @Test
015: public void testRuleSetReference() {
016: RuleReference ruleReference = new RuleReference();
017: RuleSetReference ruleSetReference = new RuleSetReference();
018: ruleReference.setRuleSetReference(ruleSetReference);
019: assertEquals("Not same rule set reference", ruleSetReference,
020: ruleReference.getRuleSetReference());
021: }
022:
023: @Test
024: public void testOverride() {
025: MockRule rule = new MockRule();
026: rule.setName("name1");
027: rule.addProperty("property1", "value1");
028: rule.setMessage("message1");
029: rule.setDescription("description1");
030: rule.addExample("example1");
031: rule.setExternalInfoUrl("externalInfoUrl1");
032: rule.setPriority(1);
033:
034: RuleReference ruleReference = new RuleReference();
035: ruleReference.setRule(rule);
036: ruleReference.setName("name2");
037: ruleReference.addProperty("property1", "value2");
038: ruleReference.setMessage("message2");
039: ruleReference.setDescription("description2");
040: ruleReference.addExample("example2");
041: ruleReference.setExternalInfoUrl("externalInfoUrl2");
042: ruleReference.setPriority(2);
043:
044: assertEquals("Override failed", "name2", ruleReference
045: .getName());
046: assertEquals("Override failed", "name2", ruleReference
047: .getOverriddenName());
048:
049: assertEquals("Override failed", "value2", ruleReference
050: .getProperties().getProperty("property1"));
051: assertEquals("Override failed", "value2", ruleReference
052: .getOverriddenProperties().getProperty("property1"));
053:
054: assertEquals("Override failed", "message2", ruleReference
055: .getMessage());
056: assertEquals("Override failed", "message2", ruleReference
057: .getOverriddenMessage());
058:
059: assertEquals("Override failed", "description2", ruleReference
060: .getDescription());
061: assertEquals("Override failed", "description2", ruleReference
062: .getOverriddenDescription());
063:
064: // TODO Examples is being tested as currently working, but needs to be fixed at some point
065: assertEquals("Override failed", "example2", ruleReference
066: .getExample());
067: assertEquals("Override failed", 2, ruleReference.getExamples()
068: .size());
069: assertEquals("Override failed", "example1", ruleReference
070: .getExamples().get(0));
071: assertEquals("Override failed", "example2", ruleReference
072: .getExamples().get(1));
073: assertEquals("Override failed", "example2", ruleReference
074: .getOverriddenExamples().get(0));
075:
076: assertEquals("Override failed", "externalInfoUrl2",
077: ruleReference.getExternalInfoUrl());
078: assertEquals("Override failed", "externalInfoUrl2",
079: ruleReference.getOverriddenExternalInfoUrl());
080:
081: assertEquals("Override failed", 2, ruleReference.getPriority());
082: assertEquals("Override failed", (Integer) 2, ruleReference
083: .getOverriddenPriority());
084: }
085:
086: @Test
087: public void testNotOverride() {
088: MockRule rule = new MockRule();
089: rule.setName("name1");
090: rule.addProperty("property1", "value1");
091: rule.setMessage("message1");
092: rule.setDescription("description1");
093: rule.addExample("example1");
094: rule.setExternalInfoUrl("externalInfoUrl1");
095: rule.setPriority(1);
096:
097: RuleReference ruleReference = new RuleReference();
098: ruleReference.setRule(rule);
099: ruleReference.setName("name1");
100: ruleReference.addProperty("property1", "value1");
101: ruleReference.setMessage("message1");
102: ruleReference.setDescription("description1");
103: ruleReference.addExample("example1");
104: ruleReference.setExternalInfoUrl("externalInfoUrl1");
105: ruleReference.setPriority(1);
106:
107: assertEquals("Override failed", "name1", ruleReference
108: .getName());
109: assertNull("Override failed", ruleReference.getOverriddenName());
110:
111: assertEquals("Override failed", "value1", ruleReference
112: .getProperties().getProperty("property1"));
113: assertNull("Override failed", ruleReference
114: .getOverriddenProperties());
115:
116: assertEquals("Override failed", "message1", ruleReference
117: .getMessage());
118: assertNull("Override failed", ruleReference
119: .getOverriddenMessage());
120:
121: assertEquals("Override failed", "description1", ruleReference
122: .getDescription());
123: assertNull("Override failed", ruleReference
124: .getOverriddenDescription());
125:
126: assertEquals("Override failed", "example1", ruleReference
127: .getExample());
128: assertEquals("Override failed", 1, ruleReference.getExamples()
129: .size());
130: assertEquals("Override failed", "example1", ruleReference
131: .getExamples().get(0));
132: assertNull("Override failed", ruleReference
133: .getOverriddenExamples());
134:
135: assertEquals("Override failed", "externalInfoUrl1",
136: ruleReference.getExternalInfoUrl());
137: assertNull("Override failed", ruleReference
138: .getOverriddenExternalInfoUrl());
139:
140: assertEquals("Override failed", 1, ruleReference.getPriority());
141: assertNull("Override failed", ruleReference
142: .getOverriddenPriority());
143: }
144:
145: public static junit.framework.Test suite() {
146: return new JUnit4TestAdapter(RuleReferenceTest.class);
147: }
148: }
|