Source Code Cross Referenced for AbstractRuleTest.java in  » Code-Analyzer » pmd-4.2rc1 » test » net » sourceforge » pmd » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Code Analyzer » pmd 4.2rc1 » test.net.sourceforge.pmd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.assertFalse;
026:        import static org.junit.Assert.assertTrue;
027:        import net.sourceforge.pmd.AbstractRule;
028:        import net.sourceforge.pmd.PropertyDescriptor;
029:        import net.sourceforge.pmd.Report;
030:        import net.sourceforge.pmd.RuleContext;
031:        import net.sourceforge.pmd.RuleViolation;
032:        import net.sourceforge.pmd.ast.SimpleJavaNode;
033:        import net.sourceforge.pmd.ast.SimpleNode;
034:        import net.sourceforge.pmd.properties.StringProperty;
035:        import net.sourceforge.pmd.symboltable.SourceFileScope;
036:
037:        import org.junit.Test;
038:
039:        import java.util.HashMap;
040:        import java.util.Map;
041:
042:        public class AbstractRuleTest {
043:
044:            private static class MyRule extends AbstractRule {
045:                private static final PropertyDescriptor pd = new StringProperty(
046:                        "foo", "foo property", "x", 1.0f);
047:
048:                private static final PropertyDescriptor xpath = new StringProperty(
049:                        "xpath", "xpath property", "", 2.0f);
050:
051:                private static final Map<String, PropertyDescriptor> propertyDescriptorsByName = asFixedMap(new PropertyDescriptor[] {
052:                        pd, xpath });
053:
054:                protected Map<String, PropertyDescriptor> propertiesByName() {
055:                    return propertyDescriptorsByName;
056:                }
057:
058:                public MyRule() {
059:                    setName("MyRule");
060:                    setMessage("my rule msg");
061:                    setPriority(3);
062:                    setProperty(pd, "value");
063:                }
064:            }
065:
066:            private static class MyOtherRule extends AbstractRule {
067:                private static final PropertyDescriptor pd = new StringProperty(
068:                        "foo", "foo property", "x", 1.0f);
069:
070:                private static final Map<String, PropertyDescriptor> propertyDescriptorsByName = asFixedMap(new PropertyDescriptor[] { pd });
071:
072:                protected Map<String, PropertyDescriptor> propertiesByName() {
073:                    return propertyDescriptorsByName;
074:                }
075:
076:                public MyOtherRule() {
077:                    setName("MyOtherRule");
078:                    setMessage("my other rule");
079:                    setPriority(3);
080:                    setProperty(pd, "value");
081:                }
082:            }
083:
084:            @Test
085:            public void testCreateRV() {
086:                MyRule r = new MyRule();
087:                r.setRuleSetName("foo");
088:                RuleContext ctx = new RuleContext();
089:                ctx.setSourceCodeFilename("filename");
090:                SimpleNode s = new SimpleJavaNode(1);
091:                s.testingOnly__setBeginColumn(5);
092:                s.testingOnly__setBeginLine(5);
093:                s.setScope(new SourceFileScope("foo"));
094:                RuleViolation rv = new RuleViolation(r, ctx, s);
095:                assertEquals("Line number mismatch!", 5, rv.getBeginLine());
096:                assertEquals("Filename mismatch!", "filename", rv.getFilename());
097:                assertEquals("Rule object mismatch!", r, rv.getRule());
098:                assertEquals("Rule msg mismatch!", "my rule msg", rv
099:                        .getDescription());
100:                assertEquals("RuleSet name mismatch!", "foo", rv.getRule()
101:                        .getRuleSetName());
102:            }
103:
104:            @Test
105:            public void testCreateRV2() {
106:                MyRule r = new MyRule();
107:                RuleContext ctx = new RuleContext();
108:                ctx.setSourceCodeFilename("filename");
109:                SimpleNode s = new SimpleJavaNode(1);
110:                s.testingOnly__setBeginColumn(5);
111:                s.testingOnly__setBeginLine(5);
112:                s.setScope(new SourceFileScope("foo"));
113:                RuleViolation rv = new RuleViolation(r, ctx, s,
114:                        "specificdescription");
115:                assertEquals("Line number mismatch!", 5, rv.getBeginLine());
116:                assertEquals("Filename mismatch!", "filename", rv.getFilename());
117:                assertEquals("Rule object mismatch!", r, rv.getRule());
118:                assertEquals("Rule description mismatch!",
119:                        "specificdescription", rv.getDescription());
120:            }
121:
122:            @Test
123:            public void testRuleExclusion() {
124:                MyRule r = new MyRule();
125:                RuleContext ctx = new RuleContext();
126:                Map<Integer, String> m = new HashMap<Integer, String>();
127:                m.put(new Integer(5), "");
128:                ctx.setReport(new Report());
129:                ctx.excludeLines(m);
130:                ctx.setSourceCodeFilename("filename");
131:                SimpleNode n = new SimpleJavaNode(1);
132:                n.testingOnly__setBeginColumn(5);
133:                n.testingOnly__setBeginLine(5);
134:                n.setScope(new SourceFileScope("foo"));
135:                RuleViolation rv = new RuleViolation(r, ctx, n,
136:                        "specificdescription");
137:                ctx.getReport().addRuleViolation(rv);
138:                assertTrue(ctx.getReport().isEmpty());
139:            }
140:
141:            @Test
142:            public void testEquals1() {
143:                MyRule r = new MyRule();
144:                assertFalse("A rule is never equals to null!", r.equals(null));
145:            }
146:
147:            @Test
148:            public void testEquals2() {
149:                MyRule r = new MyRule();
150:                assertEquals("A rule must be equals to itself", r, r);
151:            }
152:
153:            @Test
154:            public void testEquals3() {
155:                MyRule r1 = new MyRule();
156:                MyRule r2 = new MyRule();
157:                assertEquals("Two instances of the same rule are equal", r1, r2);
158:                assertEquals(
159:                        "Hashcode for two instances of the same rule must be equal",
160:                        r1.hashCode(), r2.hashCode());
161:            }
162:
163:            @Test
164:            public void testEquals4() {
165:                MyRule myRule = new MyRule();
166:                assertFalse(
167:                        "A rule cannot be equal to an object of another class",
168:                        myRule.equals("MyRule"));
169:            }
170:
171:            @Test
172:            public void testEquals5() {
173:                MyRule myRule = new MyRule();
174:                MyOtherRule myOtherRule = new MyOtherRule();
175:                assertFalse("Two rules from different classes cannot be equal",
176:                        myRule.equals(myOtherRule));
177:            }
178:
179:            @Test
180:            public void testEquals6() {
181:                MyRule r1 = new MyRule();
182:                MyRule r2 = new MyRule();
183:                r2.setName("MyRule2");
184:                assertFalse("Rules with different names cannot be equal", r1
185:                        .equals(r2));
186:            }
187:
188:            @Test
189:            public void testEquals7() {
190:                MyRule r1 = new MyRule();
191:                MyRule r2 = new MyRule();
192:                r2.setPriority(1);
193:                assertFalse(
194:                        "Rules with different priority levels cannot be equal",
195:                        r1.equals(r2));
196:            }
197:
198:            @Test
199:            public void testEquals8() {
200:                MyRule r1 = new MyRule();
201:                r1.setProperty(MyRule.xpath, "something");
202:                MyRule r2 = new MyRule();
203:                r2.setProperty(MyRule.xpath, "something else");
204:                assertFalse(
205:                        "Rules with different properties values cannot be equal",
206:                        r1.equals(r2));
207:            }
208:
209:            @Test
210:            public void testEquals9() {
211:                MyRule r1 = new MyRule();
212:                MyRule r2 = new MyRule();
213:                r2.setProperty(MyRule.xpath, "something else");
214:                assertFalse("Rules with different properties cannot be equal",
215:                        r1.equals(r2));
216:            }
217:
218:            @Test
219:            public void testEquals10() {
220:                MyRule r1 = new MyRule();
221:                MyRule r2 = new MyRule();
222:                r2.setMessage("another message");
223:                assertTrue("Rules with different messages are still equal", r1
224:                        .equals(r2));
225:                assertTrue("Rules that are equal must have the same hashcode",
226:                        r1.hashCode() == r2.hashCode());
227:            }
228:
229:            public static junit.framework.Test suite() {
230:                return new junit.framework.JUnit4TestAdapter(
231:                        AbstractRuleTest.class);
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.