1 20 package org.enhydra.barracuda.plankton; 21 22 import java.util.*; 23 27 import junit.framework.*; 28 import org.apache.log4j.*; 30 import org.enhydra.barracuda.testbed.*; 31 32 33 36 public class TestStringUtil extends DefaultTestCase { 37 private static String testClass = TestStringUtil.class.getName(); 39 private static final Logger logger = Logger.getLogger("test."+testClass); 40 41 protected String sourceStr = null; 43 protected String oldPattern = null; 44 protected String newPattern = null; 45 protected String expectedResult = null; 46 47 51 public TestStringUtil(String name) { 52 super(name); 53 } 56 57 60 public TestStringUtil(String name, String isourceStr, String ioldPattern, String inewPattern, String iexpectedResult) { 61 super(name); 62 sourceStr = isourceStr; 63 oldPattern = ioldPattern; 64 newPattern = inewPattern; 65 expectedResult = iexpectedResult; 66 } 67 68 75 public static void main(String args[]) { 76 TestUtil.parseParams(args); 78 79 if (TestUtil.BATCH_MODE) junit.textui.TestRunner.main(new String [] {testClass}); 81 else junit.swingui.TestRunner.main(new String [] {testClass}); 82 } 83 84 87 public static Test suite() { 88 TestSuite suite = new TestSuite(); 90 91 suite.addTest(new TestStringUtil("testReplace", null, null, "Blah", "Blah")); 93 suite.addTest(new TestStringUtil("testReplace", null, "a", "Blah", null)); 94 suite.addTest(new TestStringUtil("testReplace", "Foo Blah", null, "_", "Foo Blah")); 95 suite.addTest(new TestStringUtil("testReplace", "Foo Blah", " ", "_", "Foo_Blah")); 96 suite.addTest(new TestStringUtil("testReplace", "Foo Blah Blah", " ", "_", "Foo_Blah_Blah")); 97 suite.addTest(new TestStringUtil("testReplace", "Foo Blah", " ", "_", "Foo__Blah")); 98 suite.addTest(new TestStringUtil("testReplace", "~Some Text", "~", null, "Some Text")); 99 suite.addTest(new TestStringUtil("testReplace", "Some Text~", "~", null, "Some Text")); 100 suite.addTest(new TestStringUtil("testReplace", "~Some~Text~", "~", null, "SomeText")); 101 suite.addTest(new TestStringUtil("testReplace", "~~~", "~", null, null)); 102 suite.addTest(new TestStringUtil("testReplace", "~~~", "~", "", "")); 103 suite.addTest(new TestStringUtil("testReplace", "", " ", null, "")); 104 105 return suite; 107 } 108 109 113 public void testReplace() { 116 logger.info("running testReplace()"); 117 118 String actualResult = StringUtil.replace(sourceStr, oldPattern, newPattern); 119 assertTrue("Replace err on source:'"+sourceStr+"' ('"+oldPattern+"'-->'"+newPattern+"') got:'"+actualResult+"' expected:'"+expectedResult+"'", actualResult==expectedResult || (actualResult!=null && actualResult.equals(expectedResult))); 120 } 121 } 122 | Popular Tags |