1 16 package scriptella.util; 17 18 import scriptella.AbstractTestCase; 19 20 import java.util.Random ; 21 22 28 public class StringUtilsTest extends AbstractTestCase { 29 public void testIsEmpty() { 30 assertTrue(StringUtils.isEmpty(null)); 31 assertTrue(StringUtils.isEmpty("")); 32 assertFalse(StringUtils.isEmpty(" test")); 33 } 34 35 public void testIsAsciiWhitespacesOnly() { 36 assertTrue(StringUtils.isAsciiWhitespacesOnly("")); 37 assertTrue(StringUtils.isAsciiWhitespacesOnly(null)); 38 assertTrue(StringUtils.isAsciiWhitespacesOnly(" ")); 39 assertTrue(StringUtils.isAsciiWhitespacesOnly(" \t\r \n ")); 40 assertTrue(StringUtils.isAsciiWhitespacesOnly("\n")); 41 assertFalse(StringUtils.isAsciiWhitespacesOnly(" 1 ")); 42 assertFalse(StringUtils.isAsciiWhitespacesOnly(" abc ")); 43 assertFalse(StringUtils.isAsciiWhitespacesOnly("-----")); 44 } 45 46 public void testIsDecimalInteger() { 47 assertTrue(StringUtils.isDecimalInt("123")); 48 assertFalse(StringUtils.isDecimalInt("")); assertFalse(StringUtils.isDecimalInt(null)); assertTrue(StringUtils.isDecimalInt("0")); 51 assertTrue(StringUtils.isDecimalInt("01")); 52 assertFalse(StringUtils.isDecimalInt("01a")); 53 assertFalse(StringUtils.isDecimalInt("-1")); 55 for (int i=0;i<1000;i++) { 56 assertTrue("i="+i, StringUtils.isDecimalInt(String.valueOf(i))); 57 } 58 Random rnd = new Random (0); for (int i=0;i<1000;i++) { 60 int n = rnd.nextInt(Integer.MAX_VALUE); 61 assertTrue("n="+n, StringUtils.isDecimalInt(String.valueOf(n))); 62 } 63 64 } 65 66 public void testConsoleFormat() { 67 String sep = System.getProperty("line.separator"); 68 String test = " \u0000 test\r\n line2\r line3 "; 69 assertEquals("test"+sep+" line2"+sep+" line3", StringUtils.consoleFormat(test)); 70 } 71 } 72 | Popular Tags |