001: package net.firstpartners.nounit.utility.test;
002:
003: /**
004: * Title: NoUnit - Identify Classes that are not being unit Tested
005: *
006: * Copyright (C) 2001 Paul Browne , FirstPartners.net
007: *
008: *
009: * This program is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU General Public License
011: * as published by the Free Software Foundation; either version 2
012: * of the License, or (at your option) any later version.
013: *
014: * This program is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
017: * GNU General Public License for more details.
018: *
019: * You should have received a copy of the GNU General Public License
020: * along with this program; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * @author Paul Browne
024: * @version 0.7
025: */
026:
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030: import net.firstpartners.nounit.utility.TextUtil;
031:
032: /**
033: * Tests the functions in the Util Class
034: */
035: public class TestTextUtil extends TestCase {
036:
037: /**
038: * Constructor Required by Junit
039: * @param name
040: */
041: public TestTextUtil(String name) {
042: super (name);
043: }
044:
045: /**
046: * Method to setup logging test
047: */
048: public void setUp() {
049:
050: }
051:
052: /**
053: * Enable Junit to run this Class individually
054: * @param args
055: */
056: public static void main(String[] args) {
057: junit.textui.TestRunner.run(suite());
058: }
059:
060: /**
061: * Enable Junit to run this class
062: * @return TestDataCaptureDefaults.class
063: */
064: public static Test suite() {
065: return new TestSuite(TestTextUtil.class);
066: }
067:
068: /**
069: * Tests replace method
070: */
071: public void testReplace() {
072: assertEquals("mainstring", TextUtil.replace("mainstring", "",
073: ""));
074: assertEquals("", TextUtil.replace("", "sub", "string"));
075: assertEquals("string", TextUtil.replace("mainstring", "main",
076: ""));
077: assertEquals("mainstrin", TextUtil.replace("mainstring", "g",
078: ""));
079: assertEquals("mystring", TextUtil.replace("mainstring", "ain",
080: "y"));
081: assertEquals("substring", TextUtil.replace("mainstring",
082: "main", "sub"));
083: }
084:
085: /**
086: * Tests replaceAll method
087: */
088: public void testReplaceAll() {
089: assertEquals(null, TextUtil.replaceAll(null, null, null));
090: assertEquals("", TextUtil.replaceAll("", "", ""));
091: assertEquals("Abc", TextUtil.replaceAll("abc", "a", "A"));
092: assertEquals("aXYZc", TextUtil.replaceAll("abc", "b", "XYZ"));
093: assertEquals("abC", TextUtil.replaceAll("abc", "c", "C"));
094: assertEquals("abcdef", TextUtil.replaceAll("abcdef", "", "XXX"));
095: assertEquals("ABCdef", TextUtil.replaceAll("abcdef", "abc",
096: "ABC"));
097: assertEquals("abcDEF", TextUtil.replaceAll("abcdef", "def",
098: "DEF"));
099: assertEquals("abCDEf", TextUtil.replaceAll("abcdef", "cde",
100: "CDE"));
101:
102: assertEquals("AbcdefAbcxyzdef", TextUtil.replaceAll(
103: "abcdefabcxyzdef", "a", "A"));
104: assertEquals("abcdeFabcxyzdeF", TextUtil.replaceAll(
105: "abcdefabcxyzdef", "f", "F"));
106: assertEquals("ABCdefABCxyzdef", TextUtil.replaceAll(
107: "abcdefabcxyzdef", "abc", "ABC"));
108: assertEquals("abcDEFabcxyzDEF", TextUtil.replaceAll(
109: "abcdefabcxyzdef", "def", "DEF"));
110: assertEquals("abcdefabcXYZdef", TextUtil.replaceAll(
111: "abcdefabcxyzdef", "xyz", "XYZ"));
112: assertEquals("abcdefabcxyzdef", TextUtil.replaceAll(
113: "abcdefabcxyzdef", "F", "XXX"));
114: assertEquals("ABCABCABCxyzdef", TextUtil.replaceAll(
115: "abcabcabcxyzdef", "abc", "ABC"));
116: assertEquals("1231231231231231", TextUtil.replaceAll(
117: "11111111111", "11", "123"));
118: assertEquals("AAAAAA", TextUtil.replaceAll("aaaaaa", "a", "A"));
119: assertEquals("A", TextUtil.replaceAll("a", "a", "A"));
120: }
121:
122: /**
123: * Test the remove funtionality
124: */
125: public void testRemove() {
126: assertTrue(TextUtil.removeAll(" Some String", " ").equals(
127: "SomeString"));
128: }
129:
130: /**
131: * Test the remove trailing functionality
132: */
133: public void testRemoveTrailing() {
134: assertTrue(TextUtil.removeTrailing(" xxxx ", " ").equals(
135: " xxxx"));
136: }
137:
138: }
|