KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > firstpartners > nounit > utility > test > TestTextUtil


1 package net.firstpartners.nounit.utility.test;
2
3 /**
4  * Title: NoUnit - Identify Classes that are not being unit Tested
5  *
6  * Copyright (C) 2001 Paul Browne , FirstPartners.net
7  *
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @author Paul Browne
24  * @version 0.7
25  */

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 /**
34  * Tests the functions in the Util Class
35  */

36 public class TestTextUtil extends TestCase{
37         
38     /**
39      * Constructor Required by Junit
40      * @param name
41      */

42     public TestTextUtil(String JavaDoc name) {
43         super(name);
44     }
45     
46     /**
47      * Method to setup logging test
48      */

49     public void setUp() {
50         
51     }
52     
53     /**
54      * Enable Junit to run this Class individually
55      * @param args
56      */

57     public static void main(String JavaDoc[] args) {
58         junit.textui.TestRunner.run(suite());
59     }
60     
61     /**
62      * Enable Junit to run this class
63      * @return TestDataCaptureDefaults.class
64      */

65   public static Test suite() {
66       return new TestSuite(TestTextUtil.class);
67   }
68     
69     
70     /**
71      * Tests replace method
72      */

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     /**
84      * Tests replaceAll method
85      */

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     /**
110      * Test the remove funtionality
111      */

112     public void testRemove() {
113         assertTrue(TextUtil.removeAll(" Some String"," ").equals("SomeString"));
114     }
115     
116     
117     
118     /**
119      * Test the remove trailing functionality
120      */

121     public void testRemoveTrailing(){
122         assertTrue(TextUtil.removeTrailing(" xxxx "," ").equals(" xxxx"));
123     }
124     
125     
126 }
127
Popular Tags