Source Code Cross Referenced for RuleContextTest.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.assertNotNull;
027:        import static org.junit.Assert.assertNull;
028:        import static org.junit.Assert.assertTrue;
029:
030:        import java.io.File;
031:
032:        import junit.framework.JUnit4TestAdapter;
033:        import net.sourceforge.pmd.Report;
034:        import net.sourceforge.pmd.RuleContext;
035:
036:        import org.junit.Test;
037:
038:        public class RuleContextTest {
039:
040:            @Test
041:            public void testReport() {
042:                RuleContext ctx = new RuleContext();
043:                assertEquals(0, ctx.getReport().size());
044:                Report r = new Report();
045:                ctx.setReport(r);
046:                Report r2 = ctx.getReport();
047:                assertEquals("report object mismatch", r, r2);
048:            }
049:
050:            @Test
051:            public void testSourceCodeFilename() {
052:                RuleContext ctx = new RuleContext();
053:                assertNull("filename should be null", ctx
054:                        .getSourceCodeFilename());
055:                ctx.setSourceCodeFilename("foo");
056:                assertEquals("filename mismatch", "foo", ctx
057:                        .getSourceCodeFilename());
058:            }
059:
060:            @Test
061:            public void testSourceCodeFile() {
062:                RuleContext ctx = new RuleContext();
063:                assertNull("file should be null", ctx.getSourceCodeFile());
064:                ctx.setSourceCodeFile(new File("somefile.java"));
065:                assertEquals("filename mismatch", new File("somefile.java"),
066:                        ctx.getSourceCodeFile());
067:            }
068:
069:            @Test
070:            public void testAttributes() {
071:                RuleContext ctx1 = new RuleContext();
072:                Object obj1 = new Object();
073:                Object obj2 = new Object();
074:                assertNull("attribute should be null", ctx1
075:                        .getAttribute("attribute"));
076:                boolean set = ctx1.setAttribute("attribute", obj1);
077:                assertTrue("attribute should have been set", set);
078:                assertNotNull("attribute should not be null", ctx1
079:                        .getAttribute("attribute"));
080:                assertTrue("attribute should be expected instance", ctx1
081:                        .getAttribute("attribute") == obj1);
082:                set = ctx1.setAttribute("attribute", obj2);
083:                assertFalse("attribute should not have been set", set);
084:                assertTrue("attribute should be expected instance", ctx1
085:                        .getAttribute("attribute") == obj1);
086:                Object value = ctx1.removeAttribute("attribute");
087:                assertTrue("attribute value should be expected instance",
088:                        value == obj1);
089:                assertNull("attribute should be null", ctx1
090:                        .getAttribute("attribute"));
091:            }
092:
093:            @Test
094:            public void testSharedAttributes() {
095:                RuleContext ctx1 = new RuleContext();
096:                RuleContext ctx2 = new RuleContext(ctx1);
097:                StringBuilder obj1 = new StringBuilder();
098:                StringBuilder obj2 = new StringBuilder();
099:
100:                ctx1.setAttribute("attribute1", obj1);
101:                ctx2.setAttribute("attribute2", obj2);
102:                assertNotNull("attribute should not be null", ctx1
103:                        .getAttribute("attribute1"));
104:                assertNotNull("attribute should not be null", ctx1
105:                        .getAttribute("attribute2"));
106:                assertNotNull("attribute should not be null", ctx2
107:                        .getAttribute("attribute1"));
108:                assertNotNull("attribute should not be null", ctx2
109:                        .getAttribute("attribute2"));
110:                assertTrue("attribute should be expected instance", ctx1
111:                        .getAttribute("attribute1") == obj1);
112:                assertTrue("attribute should be expected instance", ctx1
113:                        .getAttribute("attribute2") == obj2);
114:                assertTrue("attribute should be expected instance", ctx2
115:                        .getAttribute("attribute1") == obj1);
116:                assertTrue("attribute should be expected instance", ctx2
117:                        .getAttribute("attribute2") == obj2);
118:
119:                ctx1.removeAttribute("attribute1");
120:                assertNull("attribute should be null", ctx1
121:                        .getAttribute("attribute1"));
122:                assertNull("attribute should be null", ctx2
123:                        .getAttribute("attribute1"));
124:                assertNotNull("attribute should not be null", ctx1
125:                        .getAttribute("attribute2"));
126:                assertNotNull("attribute should not be null", ctx2
127:                        .getAttribute("attribute2"));
128:
129:                StringBuilder value = (StringBuilder) ctx1
130:                        .getAttribute("attribute2");
131:                assertEquals("attribute value should be empty", "", value
132:                        .toString());
133:                value.append("x");
134:                StringBuilder value1 = (StringBuilder) ctx1
135:                        .getAttribute("attribute2");
136:                assertEquals("attribute value should be 'x'", "x", value1
137:                        .toString());
138:                StringBuilder value2 = (StringBuilder) ctx2
139:                        .getAttribute("attribute2");
140:                assertEquals("attribute value should be 'x'", "x", value2
141:                        .toString());
142:            }
143:
144:            public static junit.framework.Test suite() {
145:                return new JUnit4TestAdapter(RuleContextTest.class);
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.