Source Code Cross Referenced for AbstractPropertyDescriptorTester.java in  » Code-Analyzer » pmd-4.2rc1 » test » net » sourceforge » pmd » properties » 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.properties 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package test.net.sourceforge.pmd.properties;
002:
003:        import static org.junit.Assert.assertTrue;
004:        import net.sourceforge.pmd.PropertyDescriptor;
005:        import net.sourceforge.pmd.util.CollectionUtil;
006:
007:        import org.junit.Test;
008:
009:        /**
010:         * 
011:         * @author Brian Remedios
012:         */
013:        public abstract class AbstractPropertyDescriptorTester {
014:
015:            private static final int maxCardinality = 10;
016:
017:            public static final String punctuationChars = "!@#$%^&*()_-+=[]{}\\|;:'\",.<>/?`~";
018:            public static final String whitespaceChars = " \t\n";
019:            public static final String digitChars = "0123456789";
020:            public static final String alphaChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmniopqrstuvwxyz";
021:            public static final String alphaNumericChars = digitChars
022:                    + alphaChars;
023:            public static final String allChars = punctuationChars
024:                    + whitespaceChars + alphaNumericChars;
025:
026:            /**
027:             * Method createValue.
028:             * @param count int
029:             * @return Object
030:             */
031:            protected abstract Object createValue(int count);
032:
033:            /**
034:             * Method createProperty.
035:             * @param maxCount int
036:             * @return PropertyDescriptor
037:             */
038:            protected abstract PropertyDescriptor createProperty(int maxCount);
039:
040:            @Test
041:            public void testAsDelimitedString() {
042:
043:                Object testValue = createValue(maxCardinality);
044:                PropertyDescriptor pmdProp = createProperty(maxCardinality);
045:
046:                String storeValue = pmdProp.asDelimitedString(testValue);
047:
048:                Object returnedValue = pmdProp.valueFrom(storeValue);
049:
050:                assertTrue(CollectionUtil.areEqual(returnedValue, testValue));
051:            }
052:
053:            @Test
054:            public void testValueFrom() {
055:
056:                Object testValue = createValue(1);
057:                PropertyDescriptor pmdProp = createProperty(1);
058:
059:                String storeValue = pmdProp.asDelimitedString(testValue);
060:
061:                Object returnedValue = pmdProp.valueFrom(storeValue);
062:
063:                assertTrue(CollectionUtil.areEqual(returnedValue, testValue));
064:            }
065:
066:            @Test
067:            public void testErrorFor() {
068:
069:                Object testValue = createValue(1);
070:                PropertyDescriptor pmdProp = createProperty(1);
071:                String errorMsg = pmdProp.errorFor(testValue);
072:                assertTrue(errorMsg == null);
073:
074:                testValue = createValue(maxCardinality);
075:                pmdProp = createProperty(maxCardinality);
076:                errorMsg = pmdProp.errorFor(testValue);
077:                assertTrue(errorMsg == null);
078:            }
079:
080:            @Test
081:            public void testType() {
082:
083:                PropertyDescriptor pmdProp = createProperty(1);
084:
085:                assertTrue(pmdProp.type() != null);
086:            }
087:
088:            /**
089:             * Method randomInt.
090:             * @return int
091:             */
092:            public static int randomInt() {
093:
094:                int randomVal = (int) (Math.random() * 100 + 1D);
095:                return randomVal + (int) (Math.random() * 100000D);
096:            }
097:
098:            /**
099:             * Method randomInt.
100:             * @param min int
101:             * @param max int
102:             * @return int
103:             */
104:            public static int randomInt(int min, int max) {
105:                if (max < min)
106:                    max = min;
107:                int range = Math.abs(max - min);
108:                int x = (int) ((range * Math.random()) + .5);
109:                return x + min;
110:            }
111:
112:            /**
113:             * Method randomChar.
114:             * @param characters char[]
115:             * @return char
116:             */
117:            public static char randomChar(char[] characters) {
118:                return characters[randomInt(0, characters.length - 1)];
119:            }
120:
121:            /**
122:             * Method randomChoice.
123:             * @param items Object[]
124:             * @return Object
125:             */
126:            public static Object randomChoice(Object[] items) {
127:                return items[randomInt(0, items.length - 1)];
128:            }
129:
130:            /**
131:             * Method filter.
132:             * @param chars char[]
133:             * @param removeChar char
134:             * @return char[]
135:             */
136:            protected static final char[] filter(char[] chars, char removeChar) {
137:                int count = 0;
138:                for (int i = 0; i < chars.length; i++)
139:                    if (chars[i] == removeChar)
140:                        count++;
141:                char[] results = new char[chars.length - count];
142:
143:                int index = 0;
144:                for (int i = 0; i < chars.length; i++) {
145:                    if (chars[i] != removeChar)
146:                        results[index++] = chars[i];
147:                }
148:                return results;
149:            }
150:
151:            public static junit.framework.Test suite() {
152:                return new junit.framework.JUnit4TestAdapter(
153:                        AbstractPropertyDescriptorTester.class);
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.