1 package net.firstpartners.nounit.utility.test; 2 3 26 27 import junit.framework.Test; 28 import junit.framework.TestCase; 29 import junit.framework.TestSuite; 30 import net.firstpartners.nounit.utility.TextUtil; 31 32 33 36 public class TestTextUtil extends TestCase{ 37 38 42 public TestTextUtil(String name) { 43 super(name); 44 } 45 46 49 public void setUp() { 50 51 } 52 53 57 public static void main(String [] args) { 58 junit.textui.TestRunner.run(suite()); 59 } 60 61 65 public static Test suite() { 66 return new TestSuite(TestTextUtil.class); 67 } 68 69 70 73 public void testReplace() { 74 assertEquals("mainstring", TextUtil.replace("mainstring", "", "")); 75 assertEquals("", TextUtil.replace("", "sub", "string")); 76 assertEquals("string", TextUtil.replace("mainstring", "main", "")); 77 assertEquals("mainstrin", TextUtil.replace("mainstring", "g", "")); 78 assertEquals("mystring", TextUtil.replace("mainstring", "ain", "y")); 79 assertEquals("substring", TextUtil.replace("mainstring", "main", "sub")); 80 } 81 82 83 86 public void testReplaceAll() { 87 assertEquals(null, TextUtil.replaceAll(null, null, null)); 88 assertEquals("", TextUtil.replaceAll("", "", "")); 89 assertEquals("Abc",TextUtil.replaceAll("abc", "a", "A")); 90 assertEquals("aXYZc", TextUtil.replaceAll("abc", "b", "XYZ")); 91 assertEquals("abC", TextUtil.replaceAll("abc", "c", "C")); 92 assertEquals("abcdef", TextUtil.replaceAll("abcdef", "", "XXX")); 93 assertEquals("ABCdef", TextUtil.replaceAll("abcdef", "abc", "ABC")); 94 assertEquals("abcDEF", TextUtil.replaceAll("abcdef", "def", "DEF")); 95 assertEquals("abCDEf", TextUtil.replaceAll("abcdef", "cde", "CDE")); 96 97 assertEquals("AbcdefAbcxyzdef", TextUtil.replaceAll("abcdefabcxyzdef", "a", "A")); 98 assertEquals("abcdeFabcxyzdeF", TextUtil.replaceAll("abcdefabcxyzdef", "f", "F")); 99 assertEquals("ABCdefABCxyzdef", TextUtil.replaceAll("abcdefabcxyzdef", "abc", "ABC")); 100 assertEquals("abcDEFabcxyzDEF", TextUtil.replaceAll("abcdefabcxyzdef", "def", "DEF")); 101 assertEquals("abcdefabcXYZdef", TextUtil.replaceAll("abcdefabcxyzdef", "xyz", "XYZ")); 102 assertEquals("abcdefabcxyzdef", TextUtil.replaceAll("abcdefabcxyzdef", "F", "XXX")); 103 assertEquals("ABCABCABCxyzdef", TextUtil.replaceAll("abcabcabcxyzdef", "abc", "ABC")); 104 assertEquals("1231231231231231", TextUtil.replaceAll("11111111111", "11", "123")); 105 assertEquals("AAAAAA", TextUtil.replaceAll("aaaaaa", "a", "A")); 106 assertEquals("A", TextUtil.replaceAll("a", "a", "A")); 107 } 108 109 112 public void testRemove() { 113 assertTrue(TextUtil.removeAll(" Some String"," ").equals("SomeString")); 114 } 115 116 117 118 121 public void testRemoveTrailing(){ 122 assertTrue(TextUtil.removeTrailing(" xxxx "," ").equals(" xxxx")); 123 } 124 125 126 } 127 | Popular Tags |