1 16 package org.apache.commons.lang; 17 18 import junit.framework.Test; 19 import junit.framework.TestCase; 20 import junit.framework.TestSuite; 21 import junit.textui.TestRunner; 22 23 30 public class StringUtilsIsTest extends TestCase { 31 32 public StringUtilsIsTest(String name) { 33 super(name); 34 } 35 36 public static void main(String [] args) { 37 TestRunner.run(suite()); 38 } 39 40 public static Test suite() { 41 TestSuite suite = new TestSuite(StringUtilsIsTest.class); 42 suite.setName("StringUtilsIsXxx Tests"); 43 return suite; 44 } 45 46 protected void setUp() throws Exception { 47 super.setUp(); 48 } 49 50 protected void tearDown() throws Exception { 51 super.tearDown(); 52 } 53 54 56 public void testIsAlpha() { 57 assertEquals(false, StringUtils.isAlpha(null)); 58 assertEquals(true, StringUtils.isAlpha("")); 59 assertEquals(false, StringUtils.isAlpha(" ")); 60 assertEquals(true, StringUtils.isAlpha("a")); 61 assertEquals(true, StringUtils.isAlpha("A")); 62 assertEquals(true, StringUtils.isAlpha("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); 63 assertEquals(false, StringUtils.isAlpha("ham kso")); 64 assertEquals(false, StringUtils.isAlpha("1")); 65 assertEquals(false, StringUtils.isAlpha("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); 66 assertEquals(false, StringUtils.isAlpha("_")); 67 assertEquals(false, StringUtils.isAlpha("hkHKHik*khbkuh")); 68 } 69 70 public void testIsAlphanumeric() { 71 assertEquals(false, StringUtils.isAlphanumeric(null)); 72 assertEquals(true, StringUtils.isAlphanumeric("")); 73 assertEquals(false, StringUtils.isAlphanumeric(" ")); 74 assertEquals(true, StringUtils.isAlphanumeric("a")); 75 assertEquals(true, StringUtils.isAlphanumeric("A")); 76 assertEquals(true, StringUtils.isAlphanumeric("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); 77 assertEquals(false, StringUtils.isAlphanumeric("ham kso")); 78 assertEquals(true, StringUtils.isAlphanumeric("1")); 79 assertEquals(true, StringUtils.isAlphanumeric("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); 80 assertEquals(false, StringUtils.isAlphanumeric("_")); 81 assertEquals(false, StringUtils.isAlphanumeric("hkHKHik*khbkuh")); 82 } 83 84 public void testIsWhitespace() { 85 assertEquals(false, StringUtils.isWhitespace(null)); 86 assertEquals(true, StringUtils.isWhitespace("")); 87 assertEquals(true, StringUtils.isWhitespace(" ")); 88 assertEquals(true, StringUtils.isWhitespace("\t \n \t")); 89 assertEquals(false, StringUtils.isWhitespace("\t aa\n \t")); 90 assertEquals(true, StringUtils.isWhitespace(" ")); 91 assertEquals(false, StringUtils.isWhitespace(" a ")); 92 assertEquals(false, StringUtils.isWhitespace("a ")); 93 assertEquals(false, StringUtils.isWhitespace(" a")); 94 assertEquals(false, StringUtils.isWhitespace("aba")); 95 assertEquals(true, StringUtils.isWhitespace(StringUtilsTest.WHITESPACE)); 96 assertEquals(false, StringUtils.isWhitespace(StringUtilsTest.NON_WHITESPACE)); 97 } 98 99 public void testIsAlphaspace() { 100 assertEquals(false, StringUtils.isAlphaSpace(null)); 101 assertEquals(true, StringUtils.isAlphaSpace("")); 102 assertEquals(true, StringUtils.isAlphaSpace(" ")); 103 assertEquals(true, StringUtils.isAlphaSpace("a")); 104 assertEquals(true, StringUtils.isAlphaSpace("A")); 105 assertEquals(true, StringUtils.isAlphaSpace("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); 106 assertEquals(true, StringUtils.isAlphaSpace("ham kso")); 107 assertEquals(false, StringUtils.isAlphaSpace("1")); 108 assertEquals(false, StringUtils.isAlphaSpace("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); 109 assertEquals(false, StringUtils.isAlphaSpace("_")); 110 assertEquals(false, StringUtils.isAlphaSpace("hkHKHik*khbkuh")); 111 } 112 113 public void testIsAlphanumericSpace() { 114 assertEquals(false, StringUtils.isAlphanumericSpace(null)); 115 assertEquals(true, StringUtils.isAlphanumericSpace("")); 116 assertEquals(true, StringUtils.isAlphanumericSpace(" ")); 117 assertEquals(true, StringUtils.isAlphanumericSpace("a")); 118 assertEquals(true, StringUtils.isAlphanumericSpace("A")); 119 assertEquals(true, StringUtils.isAlphanumericSpace("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); 120 assertEquals(true, StringUtils.isAlphanumericSpace("ham kso")); 121 assertEquals(true, StringUtils.isAlphanumericSpace("1")); 122 assertEquals(true, StringUtils.isAlphanumericSpace("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); 123 assertEquals(false, StringUtils.isAlphanumericSpace("_")); 124 assertEquals(false, StringUtils.isAlphanumericSpace("hkHKHik*khbkuh")); 125 } 126 127 public void testIsAsciiPrintable_String() { 128 assertEquals(false, StringUtils.isAsciiPrintable(null)); 129 assertEquals(true, StringUtils.isAsciiPrintable("")); 130 assertEquals(true, StringUtils.isAsciiPrintable(" ")); 131 assertEquals(true, StringUtils.isAsciiPrintable("a")); 132 assertEquals(true, StringUtils.isAsciiPrintable("A")); 133 assertEquals(true, StringUtils.isAsciiPrintable("1")); 134 assertEquals(true, StringUtils.isAsciiPrintable("Ceki")); 135 assertEquals(true, StringUtils.isAsciiPrintable("!ab2c~")); 136 assertEquals(true, StringUtils.isAsciiPrintable("1000")); 137 assertEquals(true, StringUtils.isAsciiPrintable("10 00")); 138 assertEquals(false, StringUtils.isAsciiPrintable("10\t00")); 139 assertEquals(true, StringUtils.isAsciiPrintable("10.00")); 140 assertEquals(true, StringUtils.isAsciiPrintable("10,00")); 141 assertEquals(true, StringUtils.isAsciiPrintable("!ab-c~")); 142 assertEquals(true, StringUtils.isAsciiPrintable("hkHK=Hik6i?UGH_KJgU7.tUJgKJ*GI87GI,kug")); 143 assertEquals(true, StringUtils.isAsciiPrintable("\u0020")); 144 assertEquals(true, StringUtils.isAsciiPrintable("\u0021")); 145 assertEquals(true, StringUtils.isAsciiPrintable("\u007e")); 146 assertEquals(false, StringUtils.isAsciiPrintable("\u007f")); 147 assertEquals(true, StringUtils.isAsciiPrintable("G?lc?")); 148 assertEquals(true, StringUtils.isAsciiPrintable("=?iso-8859-1?Q?G=FClc=FC?=")); 149 assertEquals(false, StringUtils.isAsciiPrintable("G\u00fclc\u00fc")); 150 } 151 152 public void testIsNumeric() { 153 assertEquals(false, StringUtils.isNumeric(null)); 154 assertEquals(true, StringUtils.isNumeric("")); 155 assertEquals(false, StringUtils.isNumeric(" ")); 156 assertEquals(false, StringUtils.isNumeric("a")); 157 assertEquals(false, StringUtils.isNumeric("A")); 158 assertEquals(false, StringUtils.isNumeric("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); 159 assertEquals(false, StringUtils.isNumeric("ham kso")); 160 assertEquals(true, StringUtils.isNumeric("1")); 161 assertEquals(true, StringUtils.isNumeric("1000")); 162 assertEquals(false, StringUtils.isNumeric("2.3")); 163 assertEquals(false, StringUtils.isNumeric("10 00")); 164 assertEquals(false, StringUtils.isNumeric("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); 165 assertEquals(false, StringUtils.isNumeric("_")); 166 assertEquals(false, StringUtils.isNumeric("hkHKHik*khbkuh")); 167 } 168 169 public void testIsNumericSpace() { 170 assertEquals(false, StringUtils.isNumericSpace(null)); 171 assertEquals(true, StringUtils.isNumericSpace("")); 172 assertEquals(true, StringUtils.isNumericSpace(" ")); 173 assertEquals(false, StringUtils.isNumericSpace("a")); 174 assertEquals(false, StringUtils.isNumericSpace("A")); 175 assertEquals(false, StringUtils.isNumericSpace("kgKgKgKgkgkGkjkjlJlOKLgHdGdHgl")); 176 assertEquals(false, StringUtils.isNumericSpace("ham kso")); 177 assertEquals(true, StringUtils.isNumericSpace("1")); 178 assertEquals(true, StringUtils.isNumericSpace("1000")); 179 assertEquals(false, StringUtils.isNumericSpace("2.3")); 180 assertEquals(true, StringUtils.isNumericSpace("10 00")); 181 assertEquals(false, StringUtils.isNumericSpace("hkHKHik6iUGHKJgU7tUJgKJGI87GIkug")); 182 assertEquals(false, StringUtils.isNumericSpace("_")); 183 assertEquals(false, StringUtils.isNumericSpace("hkHKHik*khbkuh")); 184 } 185 186 } 187 | Popular Tags |