+++ /dev/null
-/* Created on Jan 19, 2004 */
-package com.quantum.util;
-
-import java.lang.reflect.Method;
-
-import junit.framework.TestCase;
-
-/**
- * @author holmesbc
- */
-public class StringUtilTest extends TestCase {
- public void testSubstituteString() throws Exception {
-
- String sample = "This is a test of ${variable} substitution.";
- String replaceAll = replaceAll(sample, "\\$\\{variable\\}", "parameter");
-
- assertEquals("replaceAll", "This is a test of parameter substitution.", replaceAll);
- System.out.println(StringUtil.substituteString(sample, "${variable}", "parameter"));
- assertEquals("substitute String", replaceAll, StringUtil.substituteString(sample, "${variable}", "parameter"));
- }
-
- public void testSubstituteStringAtEnd() throws Exception {
-
- String sample = "Substitute ${variable}";
- String replaceAll = replaceAll(sample, "\\$\\{variable\\}", "parameter");
-
- System.out.println(StringUtil.substituteString(sample, "${variable}", "parameter"));
- assertEquals("substitute String", replaceAll, StringUtil.substituteString(sample, "${variable}", "parameter"));
- }
-
- public void testSubstituteStringAtBeginning() throws Exception {
-
- String sample = "${variable} substitution";
- String replaceAll = replaceAll(sample, "\\$\\{variable\\}", "parameter");
-
- System.out.println(StringUtil.substituteString(sample, "${variable}", "parameter"));
- assertEquals("substitute String", replaceAll, StringUtil.substituteString(sample, "${variable}", "parameter"));
- }
-
- public void testSubstituteStringMultipleTokens() throws Exception {
-
- String sample = "${variable}${variable}";
- String replaceAll = replaceAll(sample, "\\$\\{variable\\}", "parameter");
-
- System.out.println(StringUtil.substituteString(sample, "${variable}", "parameter"));
- assertEquals("substitute String", replaceAll, StringUtil.substituteString(sample, "${variable}", "parameter"));
- }
-
- public void testSubstituteStringZeroLength() throws Exception {
-
- String sample = "This is a test of ${variable} substitution.";
- String replaceAll = replaceAll(sample, "\\$\\{variable\\}", "");
-
- System.out.println(StringUtil.substituteString(sample, "${variable}", ""));
- assertEquals("substitute String", replaceAll, StringUtil.substituteString(sample, "${variable}", ""));
- }
-
- public void testSubstituteStringSpecialChars() throws Exception {
-
- String sample = "This is a test of \r substitution.";
- String replaceAll = replaceAll(sample, "\r", "");
-
- System.out.println(StringUtil.substituteString(sample, "\r", ""));
- assertEquals("substitute String", replaceAll, StringUtil.substituteString(sample, "\r", ""));
- }
-
- private String replaceAll(String original, String regex, String newValue) throws Exception {
- Method method = String.class.getMethod("replaceAll", new Class[] { String.class, String.class } );
- return (String) method.invoke(original, new Object[] { regex, newValue } );
- }
-}