Source Code Cross Referenced for StringHelperTests.java in  » Template-Engine » ostermillerutils » com » Ostermiller » 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 » Template Engine » ostermillerutils » com.Ostermiller.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Stephen Ostermiller
003:         * http://ostermiller.org/contact.pl?regarding=Java+Utilities
004:         *
005:         * This program is free software; you can redistribute it and/or modify
006:         * it under the terms of the GNU General Public License as published by
007:         * the Free Software Foundation; either version 2 of the License, or
008:         * (at your option) any later version.
009:         *
010:         * This program is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013:         * GNU General Public License for more details.
014:         *
015:         * See COPYING.TXT for details.
016:         */
017:        package com.Ostermiller.util;
018:
019:        import java.util.*;
020:
021:        /**
022:         * StringHelper regression test.
023:         */
024:        class StringHelperTests {
025:
026:            private static void equalOrDie(String testName, Object[] a,
027:                    Object[] b) throws Exception {
028:                if (!Arrays.equals(a, b)) {
029:                    throw new Exception(testName
030:                            + " failed, arrays are not equal");
031:                }
032:            }
033:
034:            private static void equalOrDie(String testName, String a, String b)
035:                    throws Exception {
036:                if (!a.equals(b)) {
037:                    throw new Exception(testName
038:                            + " failed, arrays are not equal");
039:                }
040:            }
041:
042:            private static void trueOrDie(String testName, boolean b)
043:                    throws Exception {
044:                if (!b) {
045:                    throw new Exception(testName + " failed, condition not met");
046:                }
047:            }
048:
049:            /**
050:             * Main method for tests
051:             * @param args command line arguments (ignored)
052:             */
053:            public static void main(String[] args) {
054:                try {
055:                    equalOrDie("Split Test 1",
056:                            StringHelper.split("1-2-3", "-"), new String[] {
057:                                    "1", "2", "3" });
058:                    equalOrDie("Split Test 2", StringHelper
059:                            .split("-1--2-", "-"), new String[] { "", "1", "",
060:                            "2", "" });
061:                    equalOrDie("Split Test 3", StringHelper.split("123", ""),
062:                            new String[] { "123" });
063:                    equalOrDie("Split Test 4", StringHelper.split(
064:                            "1-2---3----4", "--"), new String[] { "1-2", "-3",
065:                            "", "4" });
066:                    equalOrDie("Split Test 5", StringHelper.split("12345678",
067:                            "--"), new String[] { "12345678" });
068:                    equalOrDie("Prepad Test 1", StringHelper.prepad("a", 8),
069:                            "       a");
070:                    equalOrDie("Prepad Test 2",
071:                            StringHelper.prepad("AaaAa", 2), "AaaAa");
072:                    equalOrDie("Prepad Test 3", StringHelper
073:                            .prepad("a", 8, '-'), "-------a");
074:                    equalOrDie("Postpad Test 1", StringHelper.postpad("a", 8),
075:                            "a       ");
076:                    equalOrDie("Postpad Test 2", StringHelper.postpad("AaaAa",
077:                            2), "AaaAa");
078:                    equalOrDie("Postpad Test 3", StringHelper.postpad("a", 8,
079:                            '-'), "a-------");
080:                    equalOrDie("Midpad Test 1", StringHelper.midpad("a", 3),
081:                            " a ");
082:                    equalOrDie("Midpad Test 2", StringHelper.midpad("a", 4),
083:                            " a  ");
084:                    equalOrDie("Midpad Test 3", StringHelper
085:                            .midpad("a", 5, '-'), "--a--");
086:                    equalOrDie("midpad Test 4",
087:                            StringHelper.midpad("AaaAa", 2), "AaaAa");
088:                    equalOrDie("replace Test 1", StringHelper.replace("1-2-3",
089:                            "-", "|"), "1|2|3");
090:                    equalOrDie("replace Test 2", StringHelper.replace("-1--2-",
091:                            "-", "|"), "|1||2|");
092:                    equalOrDie("replace Test 3", StringHelper.replace("123",
093:                            "", "|"), "123");
094:                    equalOrDie("replace Test 4", StringHelper.replace(
095:                            "1-2---3----4", "--", "|"), "1-2|-3||4");
096:                    equalOrDie("replace Test 5", StringHelper.replace(
097:                            "1-2--3---4----", "--", "---"),
098:                            "1-2---3----4------");
099:                    equalOrDie("escapeHTML Test 1", StringHelper
100:                            .escapeHTML("<>&\"'\0\1\2\n\r\f\t" + "hello"),
101:                            "&lt;&gt;&amp;&quot;&#39;\n\r\f\t" + "hello");
102:                    equalOrDie("escapeSQL Test 1", StringHelper
103:                            .escapeSQL("\0\'\"\r\n" + "hello"),
104:                            "\\0\\'\\\"\r\n" + "hello");
105:                    equalOrDie("escapeJavaLiteral Test 1", StringHelper
106:                            .escapeJavaLiteral("\0\'\"\r\n" + "hello"),
107:                            "\0\\'\\\"\\r\\n" + "hello");
108:                    equalOrDie("trim Test 1", StringHelper.trim("- -\r\n"
109:                            + "hello- -\r\n" + "hello- -\r\n", "\r- \n"),
110:                            "hello- -\r\n" + "hello");
111:                    equalOrDie("unescapeHTML Test 1", StringHelper
112:                            .unescapeHTML("&gt;hello" + "&" + "euro" + ";"),
113:                            ">hello\u20AC");
114:                    trueOrDie("containsAny Test 1", StringHelper.containsAny(
115:                            "on" + "two" + "t" + "h" + "r" + "e", new String[] {
116:                                    "one", "two", "three" }));
117:                    trueOrDie("containsAny Test 2", StringHelper.containsAny(
118:                            "one" + "t" + "w" + "t" + "h" + "r" + "e",
119:                            new String[] { "one", "two", "three" }));
120:                    trueOrDie("containsAny Test 3", StringHelper.containsAny(
121:                            "on" + "t" + "w" + "three", new String[] { "one",
122:                                    "two", "three" }));
123:                    trueOrDie("containsAny Test 4", !StringHelper.containsAny(
124:                            "on" + "t" + "w" + "t" + "h" + "r" + "e",
125:                            new String[] { "one", "two", "three" }));
126:                    trueOrDie("equalsAny Test 1", StringHelper.equalsAny("two",
127:                            new String[] { "one", "two", "three" }));
128:                    trueOrDie("equalsAny Test 2", !StringHelper.equalsAny("one"
129:                            + "two" + "three", new String[] { "one", "two",
130:                            "three" }));
131:                    trueOrDie("startsWithAny Test 1", StringHelper
132:                            .startsWithAny("two", new String[] { "one", "two",
133:                                    "three" }));
134:                    trueOrDie("startsWithAny Test 2", !StringHelper
135:                            .startsWithAny("on" + "two" + "three",
136:                                    new String[] { "one", "two", "three" }));
137:                    trueOrDie("endsWithAny Test 1", StringHelper.endsWithAny(
138:                            "two", new String[] { "one", "two", "three" }));
139:                    trueOrDie("endsWithAny Test 2", !StringHelper.endsWithAny(
140:                            "one" + "two" + "t" + "h" + "r" + "e",
141:                            new String[] { "one", "two", "three" }));
142:                    trueOrDie("containsAnyIgnoreCase Test 1", StringHelper
143:                            .containsAnyIgnoreCase("on" + "two" + "t" + "h"
144:                                    + "r" + "e", new String[] { "One", "Two",
145:                                    "Three" }));
146:                    trueOrDie("containsAnyIgnoreCase Test 2", StringHelper
147:                            .containsAnyIgnoreCase("one" + "t" + "w" + "t"
148:                                    + "h" + "r" + "e", new String[] { "One",
149:                                    "Two", "Three" }));
150:                    trueOrDie("containsAnyIgnoreCase Test 3", StringHelper
151:                            .containsAnyIgnoreCase("on" + "t" + "w" + "three",
152:                                    new String[] { "One", "Two", "Three" }));
153:                    trueOrDie("containsAnyIgnoreCase Test 4", !StringHelper
154:                            .containsAnyIgnoreCase("on" + "t" + "w" + "t" + "h"
155:                                    + "r" + "e", new String[] { "One", "Two",
156:                                    "Three" }));
157:                    trueOrDie("equalsAnyIgnoreCase Test 1", StringHelper
158:                            .equalsAnyIgnoreCase("Two", new String[] { "One",
159:                                    "Two", "Three" }));
160:                    trueOrDie("equalsAnyIgnoreCase Test 2", !StringHelper
161:                            .equalsAnyIgnoreCase("one" + "two" + "three",
162:                                    new String[] { "One", "Two", "Three" }));
163:                    trueOrDie("startsWithAnyIgnoreCase Test 1", StringHelper
164:                            .startsWithAnyIgnoreCase("Two", new String[] {
165:                                    "One", "Two", "Three" }));
166:                    trueOrDie("startsWithAnyIgnoreCase Test 2", !StringHelper
167:                            .startsWithAnyIgnoreCase("on" + "two" + "three",
168:                                    new String[] { "One", "Two", "Three" }));
169:                    trueOrDie("endsWithAnyIgnoreCase Test 1", StringHelper
170:                            .endsWithAnyIgnoreCase("Two", new String[] { "One",
171:                                    "Two", "Three" }));
172:                    trueOrDie("endsWithAnyIgnoreCase Test 2", !StringHelper
173:                            .endsWithAnyIgnoreCase("one" + "two" + "t" + "h"
174:                                    + "r" + "e", new String[] { "One", "Two",
175:                                    "Three" }));
176:                    equalOrDie("splitIncludeDelimiters Test 1", StringHelper
177:                            .splitIncludeDelimiters("1-2-3", "-"),
178:                            new String[] { "1", "-", "2", "-", "3" });
179:                    equalOrDie("splitIncludeDelimiters Test 2", StringHelper
180:                            .splitIncludeDelimiters("-1--2-", "-"),
181:                            new String[] { "", "-", "1", "-", "", "-", "2",
182:                                    "-", "" });
183:                    equalOrDie("splitIncludeDelimiters Test 3", StringHelper
184:                            .splitIncludeDelimiters("123", ""),
185:                            new String[] { "123" });
186:                    equalOrDie("splitIncludeDelimiters Test 4", StringHelper
187:                            .splitIncludeDelimiters("1-2--3---4----5", "--"),
188:                            new String[] { "1-2", "--", "3", "--", "-4", "--",
189:                                    "", "--", "5" });
190:                    equalOrDie("splitIncludeDelimiters Test 5", StringHelper
191:                            .splitIncludeDelimiters("12345678", "--"),
192:                            new String[] { "12345678" });
193:                    equalOrDie("join Test 1", StringHelper
194:                            .join(new String[] { null }), "");
195:                    equalOrDie("join Test 2", StringHelper
196:                            .join(new String[] { "" }), "");
197:                    equalOrDie("join Test 3", StringHelper.join(new String[] {
198:                            "", "" }), "");
199:                    equalOrDie("join Test 4", StringHelper
200:                            .join(new String[] { "one" }), "one");
201:                    equalOrDie("join Test 5", StringHelper.join(new String[] {
202:                            "one", "two", }), "one" + "two");
203:                    equalOrDie("join Test 6", StringHelper.join(new String[] {
204:                            "one", null, "two", "", "three" }), "one" + "two"
205:                            + "three");
206:
207:                    equalOrDie("join Test 7", StringHelper.join(
208:                            new String[] { null }, "|"), "");
209:                    equalOrDie("join Test 8", StringHelper.join(
210:                            new String[] { "" }, "|"), "");
211:                    equalOrDie("join Test 9", StringHelper.join(new String[] {
212:                            "", "" }, "|"), "|");
213:                    equalOrDie("join Test 10", StringHelper.join(
214:                            new String[] { "one" }, "|"), "one");
215:                    equalOrDie("join Test 11", StringHelper.join(new String[] {
216:                            "one", "two", }, "|"), "one|two");
217:                    equalOrDie("join Test 12", StringHelper.join(new String[] {
218:                            "one", null, "two", "", "three" }, "|"),
219:                            "one||two||three");
220:
221:                } catch (Exception x) {
222:                    x.printStackTrace(System.err);
223:                    System.exit(1);
224:                }
225:                System.exit(0);
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.