Source Code Cross Referenced for StringUtilsTest.java in  » Database-ORM » JPOX » org » jpox » util » 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 » Database ORM » JPOX » org.jpox.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**********************************************************************
002:        Copyright (c) 26-Oct-2004 Andy Jefferson and others.
003:        Licensed under the Apache License, Version 2.0 (the "License");
004:        you may not use this file except in compliance with the License.
005:        You may obtain a copy of the License at
006:
007:            http://www.apache.org/licenses/LICENSE-2.0
008:
009:        Unless required by applicable law or agreed to in writing, software
010:        distributed under the License is distributed on an "AS IS" BASIS,
011:        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012:        See the License for the specific language governing permissions and
013:        limitations under the License.
014:
015:         
016:
017:        Contributors:
018:            ...
019:         **********************************************************************/package org.jpox.util;
020:
021:        import java.util.ArrayList;
022:        import java.util.Collection;
023:        import java.util.HashSet;
024:
025:        import org.apache.log4j.Category;
026:
027:        import junit.framework.TestCase;
028:
029:        /**
030:         * Series of tests for string manipulation utilities.
031:         * @version $Revision: 1.3 $
032:         */
033:        public class StringUtilsTest extends TestCase {
034:            protected static final Category LOG = Category
035:                    .getInstance("JPOX.TEST");
036:
037:            /**
038:             * Start of the test, so log it and initialise.
039:             * @param name Name of the test case (not used)
040:             */
041:            public StringUtilsTest(String name) {
042:                super (name);
043:            }
044:
045:            /**
046:             * Test for isWhitespace method.
047:             */
048:            public void testIsWhitespace() {
049:                assertTrue(
050:                        "null String should have been confirmed as whitespace but wasn't",
051:                        StringUtils.isWhitespace(null));
052:                assertTrue(
053:                        "empty String should have been confirmed as whitespace but wasn't",
054:                        StringUtils.isWhitespace("   "));
055:                assertTrue(
056:                        "Non empty String should have been defined as not whitespace but was",
057:                        !StringUtils.isWhitespace("JPOX"));
058:                assertTrue(
059:                        "Partly empty String should have been defined as not whitespace but was",
060:                        !StringUtils.isWhitespace("   JPOXWorld "));
061:            }
062:
063:            /**
064:             * Test for areStringsEqual method
065:             */
066:            public void testAreStringsEqual() {
067:                assertTrue(
068:                        "Identical Strings should have been decreed equal but weren't",
069:                        StringUtils.areStringsEqual("JPOX", "JPOX"));
070:                assertTrue(
071:                        "Non-identical Strings should have been decreed as non-equal but were",
072:                        !StringUtils.areStringsEqual("JPOX", "Kodo"));
073:                assertTrue(
074:                        "Null strings should have been decreed equal but weren't",
075:                        StringUtils.areStringsEqual(null, null));
076:                assertTrue(
077:                        "Null and non-null Strings should have been decreed as non-equal, but were",
078:                        !StringUtils.areStringsEqual("null", null));
079:            }
080:
081:            /**
082:             * Test for left-aligned padded strings.
083:             */
084:            public void testLeftAlignedPaddedString() {
085:                assertTrue(
086:                        "String left aligned (extending the string) was incorrect",
087:                        StringUtils.leftAlignedPaddedString("JPOX", 10).equals(
088:                                "JPOX      "));
089:                assertTrue("String left aligned (same length) was incorrect",
090:                        StringUtils.leftAlignedPaddedString("JPOX", 4).equals(
091:                                "JPOX"));
092:            }
093:
094:            /**
095:             * Test for right-aligned padded strings.
096:             */
097:            public void testRightAlignedPaddedString() {
098:                assertTrue(
099:                        "String right aligned (extending the string) was incorrect",
100:                        StringUtils.rightAlignedPaddedString("JPOX", 10)
101:                                .equals("      JPOX"));
102:                assertTrue("String right aligned (same length) was incorrect",
103:                        StringUtils.rightAlignedPaddedString("JPOX", 4).equals(
104:                                "JPOX"));
105:            }
106:
107:            /**
108:             * Test for splitting strings at identifiers.
109:             */
110:            public void testSplit() {
111:                String[] tokens = StringUtils.split("JPOX Kodo JDOGenie", " ");
112:                assertTrue("First token of split string is incorrect",
113:                        tokens[0].equals("JPOX"));
114:                assertTrue("Second token of split string is incorrect",
115:                        tokens[1].equals("Kodo"));
116:                assertTrue("Third token of split string is incorrect",
117:                        tokens[2].equals("JDOGenie"));
118:
119:                String[] tokens2 = StringUtils.split(
120:                        "Andy Jefferson::Erik Bengtson::David Ezzio::Eagle",
121:                        "::");
122:                assertTrue("First token of split string is incorrect",
123:                        tokens2[0].equals("Andy Jefferson"));
124:                assertTrue("Second token of split string is incorrect",
125:                        tokens2[1].equals("Erik Bengtson"));
126:                assertTrue("Third token of split string is incorrect",
127:                        tokens2[2].equals("David Ezzio"));
128:                assertTrue("Fourth token of split string is incorrect",
129:                        tokens2[3].equals("Eagle"));
130:            }
131:
132:            /**
133:             * Test for conversion of a boolean array to a String.
134:             */
135:            public void testBooleanArrayToString() {
136:                boolean[] values = new boolean[] { true, false, false, true,
137:                        true };
138:                assertTrue("String version of boolean array [5] is incorrect",
139:                        StringUtils.booleanArrayToString(values).equals(
140:                                "[YNNYY]"));
141:
142:                assertTrue("String version of null boolean array is incorrect",
143:                        StringUtils.booleanArrayToString(null).equals("null"));
144:
145:                boolean[] values2 = new boolean[] { false };
146:                assertTrue("String version of boolean array [1] is incorrect",
147:                        StringUtils.booleanArrayToString(values2).equals("[N]"));
148:            }
149:
150:            /**
151:             * Test for conversion of a int array to a String.
152:             */
153:            public void testIntArrayToString() {
154:                int[] values = new int[] { 9876, 5432, 1, -6, 5 };
155:                assertTrue("String version of int array [5] is incorrect",
156:                        StringUtils.intArrayToString(values).equals(
157:                                "[9876, 5432, 1, -6, 5]"));
158:
159:                assertTrue("String version of null int array is incorrect",
160:                        StringUtils.intArrayToString(null).equals("null"));
161:
162:                int[] values2 = new int[] { 1234567 };
163:                assertTrue("String version of int array [1] is incorrect",
164:                        StringUtils.intArrayToString(values2).equals(
165:                                "[1234567]"));
166:            }
167:
168:            /**
169:             * Test for conversion of a collection to a String.
170:             */
171:            public void testCollectionToString() {
172:                Collection coll = new ArrayList();
173:                coll.add("JPOX version 1.0");
174:                coll.add("JPOX version 1.1.0-alpha-3");
175:                coll.add("BCEL version 5.1");
176:                assertTrue(
177:                        "String version of Collection is incorrect",
178:                        StringUtils
179:                                .collectionToString(coll)
180:                                .equals(
181:                                        "JPOX version 1.0, JPOX version 1.1.0-alpha-3, BCEL version 5.1"));
182:
183:                assertTrue("String version of empty Collection is incorrect",
184:                        StringUtils.collectionToString(new HashSet()).equals(
185:                                "<none>"));
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.