001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.commons.lang;
018:
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022: import junit.textui.TestRunner;
023:
024: /**
025: * Unit tests {@link org.apache.commons.lang.StringUtils} - Substring methods
026: *
027: * @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a>
028: * @author Michael Davey
029: * @version $Id: StringUtilsIsTest.java 437554 2006-08-28 06:21:41Z bayard $
030: */
031: public class StringUtilsIsTest extends TestCase {
032:
033: public StringUtilsIsTest(String name) {
034: super (name);
035: }
036:
037: public static void main(String[] args) {
038: TestRunner.run(suite());
039: }
040:
041: public static Test suite() {
042: TestSuite suite = new TestSuite(StringUtilsIsTest.class);
043: suite.setName("StringUtilsIsXxx Tests");
044: return suite;
045: }
046:
047: protected void setUp() throws Exception {
048: super .setUp();
049: }
050:
051: protected void tearDown() throws Exception {
052: super .tearDown();
053: }
054:
055: //-----------------------------------------------------------------------
056:
057: public void testIsAlpha() {
058: assertEquals(false, StringUtils.isAlpha(null));
059: assertEquals(true, StringUtils.isAlpha(""));
060: assertEquals(false, StringUtils.isAlpha(" "));
061: assertEquals(true, StringUtils.isAlpha("a"));
062: assertEquals(true, StringUtils.isAlpha("A"));
063: assertEquals(true, StringUtils
064: .isAlpha("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl"));
065: assertEquals(false, StringUtils.isAlpha("ham kso"));
066: assertEquals(false, StringUtils.isAlpha("1"));
067: assertEquals(false, StringUtils
068: .isAlpha("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug"));
069: assertEquals(false, StringUtils.isAlpha("_"));
070: assertEquals(false, StringUtils.isAlpha("hkHKHik*khbkuh"));
071: }
072:
073: public void testIsAlphanumeric() {
074: assertEquals(false, StringUtils.isAlphanumeric(null));
075: assertEquals(true, StringUtils.isAlphanumeric(""));
076: assertEquals(false, StringUtils.isAlphanumeric(" "));
077: assertEquals(true, StringUtils.isAlphanumeric("a"));
078: assertEquals(true, StringUtils.isAlphanumeric("A"));
079: assertEquals(true, StringUtils
080: .isAlphanumeric("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl"));
081: assertEquals(false, StringUtils.isAlphanumeric("ham kso"));
082: assertEquals(true, StringUtils.isAlphanumeric("1"));
083: assertEquals(true, StringUtils
084: .isAlphanumeric("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug"));
085: assertEquals(false, StringUtils.isAlphanumeric("_"));
086: assertEquals(false, StringUtils
087: .isAlphanumeric("hkHKHik*khbkuh"));
088: }
089:
090: public void testIsWhitespace() {
091: assertEquals(false, StringUtils.isWhitespace(null));
092: assertEquals(true, StringUtils.isWhitespace(""));
093: assertEquals(true, StringUtils.isWhitespace(" "));
094: assertEquals(true, StringUtils.isWhitespace("\t \n \t"));
095: assertEquals(false, StringUtils.isWhitespace("\t aa\n \t"));
096: assertEquals(true, StringUtils.isWhitespace(" "));
097: assertEquals(false, StringUtils.isWhitespace(" a "));
098: assertEquals(false, StringUtils.isWhitespace("a "));
099: assertEquals(false, StringUtils.isWhitespace(" a"));
100: assertEquals(false, StringUtils.isWhitespace("aba"));
101: assertEquals(true, StringUtils
102: .isWhitespace(StringUtilsTest.WHITESPACE));
103: assertEquals(false, StringUtils
104: .isWhitespace(StringUtilsTest.NON_WHITESPACE));
105: }
106:
107: public void testIsAlphaspace() {
108: assertEquals(false, StringUtils.isAlphaSpace(null));
109: assertEquals(true, StringUtils.isAlphaSpace(""));
110: assertEquals(true, StringUtils.isAlphaSpace(" "));
111: assertEquals(true, StringUtils.isAlphaSpace("a"));
112: assertEquals(true, StringUtils.isAlphaSpace("A"));
113: assertEquals(true, StringUtils
114: .isAlphaSpace("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl"));
115: assertEquals(true, StringUtils.isAlphaSpace("ham kso"));
116: assertEquals(false, StringUtils.isAlphaSpace("1"));
117: assertEquals(false, StringUtils
118: .isAlphaSpace("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug"));
119: assertEquals(false, StringUtils.isAlphaSpace("_"));
120: assertEquals(false, StringUtils.isAlphaSpace("hkHKHik*khbkuh"));
121: }
122:
123: public void testIsAlphanumericSpace() {
124: assertEquals(false, StringUtils.isAlphanumericSpace(null));
125: assertEquals(true, StringUtils.isAlphanumericSpace(""));
126: assertEquals(true, StringUtils.isAlphanumericSpace(" "));
127: assertEquals(true, StringUtils.isAlphanumericSpace("a"));
128: assertEquals(true, StringUtils.isAlphanumericSpace("A"));
129: assertEquals(true, StringUtils
130: .isAlphanumericSpace("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl"));
131: assertEquals(true, StringUtils.isAlphanumericSpace("ham kso"));
132: assertEquals(true, StringUtils.isAlphanumericSpace("1"));
133: assertEquals(
134: true,
135: StringUtils
136: .isAlphanumericSpace("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug"));
137: assertEquals(false, StringUtils.isAlphanumericSpace("_"));
138: assertEquals(false, StringUtils
139: .isAlphanumericSpace("hkHKHik*khbkuh"));
140: }
141:
142: public void testIsAsciiPrintable_String() {
143: assertEquals(false, StringUtils.isAsciiPrintable(null));
144: assertEquals(true, StringUtils.isAsciiPrintable(""));
145: assertEquals(true, StringUtils.isAsciiPrintable(" "));
146: assertEquals(true, StringUtils.isAsciiPrintable("a"));
147: assertEquals(true, StringUtils.isAsciiPrintable("A"));
148: assertEquals(true, StringUtils.isAsciiPrintable("1"));
149: assertEquals(true, StringUtils.isAsciiPrintable("Ceki"));
150: assertEquals(true, StringUtils.isAsciiPrintable("!ab2c~"));
151: assertEquals(true, StringUtils.isAsciiPrintable("1000"));
152: assertEquals(true, StringUtils.isAsciiPrintable("10 00"));
153: assertEquals(false, StringUtils.isAsciiPrintable("10\t00"));
154: assertEquals(true, StringUtils.isAsciiPrintable("10.00"));
155: assertEquals(true, StringUtils.isAsciiPrintable("10,00"));
156: assertEquals(true, StringUtils.isAsciiPrintable("!ab-c~"));
157: assertEquals(
158: true,
159: StringUtils
160: .isAsciiPrintable("hkHK=Hik6i?UGH_KJgU7.tUJgKJ*GI87GI,kug"));
161: assertEquals(true, StringUtils.isAsciiPrintable("\u0020"));
162: assertEquals(true, StringUtils.isAsciiPrintable("\u0021"));
163: assertEquals(true, StringUtils.isAsciiPrintable("\u007e"));
164: assertEquals(false, StringUtils.isAsciiPrintable("\u007f"));
165: assertEquals(true, StringUtils.isAsciiPrintable("G?lc?"));
166: assertEquals(true, StringUtils
167: .isAsciiPrintable("=?iso-8859-1?Q?G=FClc=FC?="));
168: assertEquals(false, StringUtils
169: .isAsciiPrintable("G\u00fclc\u00fc"));
170: }
171:
172: public void testIsNumeric() {
173: assertEquals(false, StringUtils.isNumeric(null));
174: assertEquals(true, StringUtils.isNumeric(""));
175: assertEquals(false, StringUtils.isNumeric(" "));
176: assertEquals(false, StringUtils.isNumeric("a"));
177: assertEquals(false, StringUtils.isNumeric("A"));
178: assertEquals(false, StringUtils
179: .isNumeric("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl"));
180: assertEquals(false, StringUtils.isNumeric("ham kso"));
181: assertEquals(true, StringUtils.isNumeric("1"));
182: assertEquals(true, StringUtils.isNumeric("1000"));
183: assertEquals(false, StringUtils.isNumeric("2.3"));
184: assertEquals(false, StringUtils.isNumeric("10 00"));
185: assertEquals(false, StringUtils
186: .isNumeric("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug"));
187: assertEquals(false, StringUtils.isNumeric("_"));
188: assertEquals(false, StringUtils.isNumeric("hkHKHik*khbkuh"));
189: }
190:
191: public void testIsNumericSpace() {
192: assertEquals(false, StringUtils.isNumericSpace(null));
193: assertEquals(true, StringUtils.isNumericSpace(""));
194: assertEquals(true, StringUtils.isNumericSpace(" "));
195: assertEquals(false, StringUtils.isNumericSpace("a"));
196: assertEquals(false, StringUtils.isNumericSpace("A"));
197: assertEquals(false, StringUtils
198: .isNumericSpace("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl"));
199: assertEquals(false, StringUtils.isNumericSpace("ham kso"));
200: assertEquals(true, StringUtils.isNumericSpace("1"));
201: assertEquals(true, StringUtils.isNumericSpace("1000"));
202: assertEquals(false, StringUtils.isNumericSpace("2.3"));
203: assertEquals(true, StringUtils.isNumericSpace("10 00"));
204: assertEquals(false, StringUtils
205: .isNumericSpace("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug"));
206: assertEquals(false, StringUtils.isNumericSpace("_"));
207: assertEquals(false, StringUtils
208: .isNumericSpace("hkHKHik*khbkuh"));
209: }
210:
211: }
|