You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/09/25 17:01:43 UTC
cvs commit: jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/util/test StringUtilTestCase.java
bloritsch 2002/09/25 08:01:43
Modified: event build.xml default.properties
Added: event/src/java/org/apache/excalibur/util StringUtil.java
event/src/test/org/apache/excalibur/util/test
StringUtilTestCase.java
Log:
remove dependency and move the last remaining class
Revision Changes Path
1.34 +0 -2 jakarta-avalon-excalibur/event/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/event/build.xml,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- build.xml 7 Sep 2002 00:17:46 -0000 1.33
+++ build.xml 25 Sep 2002 15:01:43 -0000 1.34
@@ -17,7 +17,6 @@
<pathelement location="${excalibur-threadcontext.jar}"/>
<pathelement location="${excalibur-scratchpad.jar}"/>
<pathelement location="${avalon-framework.jar}"/>
- <pathelement location="${excalibur-util.jar}"/>
<pathelement location="${checkstyle.jar}"/>
<pathelement path="${java.class.path}"/>
</path>
@@ -48,7 +47,6 @@
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkCollections"/>
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkConcurrent"/>
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkFramework"/>
- <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkUtil"/>
<ant antfile="${depchecker.prefix}/depchecker.xml" target="checkThreadcontext"/>
</target>
1.18 +1 -1 jakarta-avalon-excalibur/event/default.properties
Index: default.properties
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/event/default.properties,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- default.properties 14 Aug 2002 14:58:23 -0000 1.17
+++ default.properties 25 Sep 2002 15:01:43 -0000 1.18
@@ -1 +1 @@
-# -------------------------------------------------------------------
# B U I L D P R O P E R T I E S
# -------------------------------------------------------------------
# Specifies default property values
# Overridden by ../default.properties and all ant.properties
# Not user-editable; use ant.properties files instead
name=excalibur-event
Name=Excalibur Event
dir-name=event
version=1.0a
package-version=0.99
year=2002
# --------------------------------------------------
# REQUIRED LIBRARIES
# --------------------------------------------------
# ----- Excalibur util, version 1.0 or later -----
excalibur-util.home=${basedir}/../util/dist
excalibur-util.lib=${excalibur-util.home}
excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
# ----- Excalibur threadcontext, version 1.0 or later -----
excalibur-threadcontext.home=${basedir}/../threadcontext/dist
excalibur-threadcontext.lib=${excalibur-threadcontext.home}
excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
# ----- Excalibur Collections, version 1.0 or later -----
excalibur-collections.home=${basedir}/../collections/dist
excalibur-collections.lib=${excalibur-collections.home}
excalibur-collections.jar=${excalibur-collections.lib}/excalibur-collections-1.0.jar
# ----- Excalibur Concurrent, version 1.0 or later -----
excalibur-concurrent.home=${basedir}/../concurrent/dist
excalibur-concurrent.lib=${excalibur-concurrent.home}
excalibur-concurrent.jar=${excalibur-concurrent.lib}/excalibur-concurrent-1.0.jar
# ----- Excalibur Util, version 1.0 or later -----
excalibur-util.home=${basedir}/../util/build/lib
excalibur-util.lib=${excalibur-util.home}
excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
# ----- Excalibur Core -----
excalibur-core.home=${basedir}/../all
excalibur-core.lib=${excalibur-core.home}/build/lib
excalibur-core.jar=${excalibur-core.lib}/excalibur-core.jar
# ----- Avalon Framework, version 4.1 or later -----
avalon-framework.home=${basedir}/../../jakarta-avalon
avalon-framework.lib=${avalon-framework.home}/build/lib
avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
# --------------------------------------------------
# REQUIRED LIBRARIES FOR UNIT TESTS
# --------------------------------------------------
# For unit testing
# ----- Excalibur Testcase, version 1.0 or later -----
excalibur-testcase.home=${basedir}/../testcase/dist
excalibur-testcase.lib=${excalibur-testcase.home}
excalibur-testcase.jar=${excalibur-testcase.lib}/excalibur-testcase-1.0.jar
# ----- Excalibur Pool, version 1.0 or later -----
excalibur-pool.home=${basedir}/../pool/dist
excalibur-pool.lib=${excalibur-pool.home}
excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
# ----- Logkit -----
logkit.home=${basedir}/../../jakarta-avalon-logkit
logkit.lib=${logkit.home}/build/lib
logkit.jar=${logkit.lib}/logkit.jar
# ----- Excalibur instrument, version 1.0 or later -----
excalibur-instrument.home=${basedir}/../instrument/dist
excalibur-instrument.lib=${excalibur-instrument.home}
excalibur-instrument.jar=${excalibur-instrument.lib}/excalibur-instrument-0.3.jar
# ----- Excalibur instrument-manager, version 1.0 or later -----
excalibur-instrument-manager.home=${basedir}/../instrument-manager/dist
excalibur-instrument-manager.lib=${excalibur-instrument-manager.home}
excalibur-instrument-manager.jar=${excalibur-instrument-manager.lib}/excalibur-instrument-manager-0.3.jar
excalibur-instrument-manager-interfaces.jar=${excalibur-instrument-manager.lib}/excalibur-instrument-manager-interfaces-0.3.jar
# --------------------------------------------------
# Settings used to configure compile environment
build.debug = on
build.optimize = off
build.deprecation = off
build.compress = false
junit.failonerror = false
# location of intermediate products
build.dir = build
build.testsrc = ${build.dir}/testsrc
build.testclasses = ${build.dir}/testclasses
build.lib = ${build.dir}/lib
build.conf = ${build.dir}/conf
build.classes = ${build.dir}/classes
build.tests = ${build.dir}/tests
build.reports = ${build.dir}/reports
# Set the properties for source directories
src.dir = src
java.dir = ${src.dir}/java
conf.dir = ${src.dir}/conf
test.dir = ${src.dir}/test
# needed by Cocoon
build.context = ${build.dir}/documentation
build.docs = ${build.dir}/docs
build.xdocs = ${build.dir}/xdocs
context.dir = ../../jakarta-avalon/src/documentation
tools.dir = ../../jakarta-avalon/tools
tools.jar = ${java.home}/../lib/tools.jar
docs.dir = docs
xdocs.dir = ${src.dir}/xdocs
# Set the properties for distribution directories
dist.dir = dist
dist.javadocs = ${docs.dir}/api
# name of .zip/.tar.gz/.bz2 files and their top-level directory
dist.name = ${name}-${version}
# name of jar file
jar.name = ${name}-${version}.jar
# property indicating directory where all distribution archives are placed
dist.base = distributions
depchecker.prefix=.
\ No newline at end of file
+# -------------------------------------------------------------------
# B U I L D P R O P E R T I E S
# -------------------------------------------------------------------
# Specifies default property values
# Overridden by ../default.properties and all ant.properties
# Not user-editable; use ant.properties files instead
name=excalibur-event
Name=Excalibur Event
dir-name=event
version=1.0a
package-version=0.99
year=2002
# --------------------------------------------------
# REQUIRED LIBRARIES
# --------------------------------------------------
# ----- Excalibur util, version 1.0 or later -----
excalibur-util.home=${basedir}/../util/dist
excalibur-util.lib=${excalibur-util.home}
excalibur-util.jar=${excalibur-util.lib}/excalibur-util-1.0.jar
# ----- Excalibur threadcontext, version 1.0 or later -----
excalibur-threadcontext.home=${basedir}/../threadcontext/dist
excalibur-threadcontext.lib=${excalibur-threadcontext.home}
excalibur-threadcontext.jar=${excalibur-threadcontext.lib}/excalibur-threadcontext-1.0.jar
# ----- Excalibur Collections, version 1.0 or later -----
excalibur-collections.home=${basedir}/../collections/dist
excalibur-collections.lib=${excalibur-collections.home}
excalibur-collections.jar=${excalibur-collections.lib}/excalibur-collections-1.0.jar
# ----- Excalibur Concurrent, version 1.0 or later -----
excalibur-concurrent.home=${basedir}/../concurrent/dist
excalibur-concurrent.lib=${excalibur-concurrent.home}
excalibur-concurrent.jar=${excalibur-concurrent.lib}/excalibur-concurrent-1.0.jar
# ----- Excalibur Core -----
excalibur-core.home=${basedir}/../all
excalibur-core.lib=${excalibur-core.home}/build/lib
excalibur-core.jar=${excalibur-core.lib}/excalibur-core.jar
# ----- Avalon Framework, version 4.1 or later -----
avalon-framework.home=${basedir}/../../jakarta-avalon
avalon-framework.lib=${avalon-framework.home}/build/lib
avalon-framework.jar=${avalon-framework.lib}/avalon-framework.jar
# --------------------------------------------------
# REQUIRED LIBRARIES FOR UNIT TESTS
# --------------------------------------------------
# For unit testing
# ----- Excalibur Testcase, version 1.0 or later -----
excalibur-testcase.home=${basedir}/../testcase/dist
excalibur-testcase.lib=${excalibur-testcase.home}
excalibur-testcase.jar=${excalibur-testcase.lib}/excalibur-testcase-1.0.jar
# ----- Excalibur Pool, version 1.0 or later -----
excalibur-pool.home=${basedir}/../pool/dist
excalibur-pool.lib=${excalibur-pool.home}
excalibur-pool.jar=${excalibur-pool.lib}/excalibur-pool-1.1.jar
# ----- Logkit -----
logkit.home=${basedir}/../../jakarta-avalon-logkit
logkit.lib=${logkit.home}/build/lib
logkit.jar=${logkit.lib}/logkit.jar
# ----- Excalibur instrument, version 1.0 or later -----
excalibur-instrument.home=${basedir}/../instrument/dist
excalibur-instrument.lib=${excalibur-instrument.home}
excalibur-instrument.jar=${excalibur-instrument.lib}/excalibur-instrument-0.3.jar
# ----- Excalibur instrument-manager, version 1.0 or later -----
excalibur-instrument-manager.home=${basedir}/../instrument-manager/dist
excalibur-instrument-manager.lib=${excalibur-instrument-manager.home}
excalibur-instrument-manager.jar=${excalibur-instrument-manager.lib}/excalibur-instrument-manager-0.3.jar
excalibur-instrument-manager-interfaces.jar=${excalibur-instrument-manager.lib}/excalibur-instrument-manager-interfaces-0.3.jar
# --------------------------------------------------
# Settings used to configure compile environment
build.debug = on
build.optimize = off
build.deprecation = off
build.compress = false
junit.failonerror = false
# location of intermediate products
build.dir = build
build.testsrc = ${build.dir}/testsrc
build.testclasses = ${build.dir}/testclasses
build.lib = ${build.dir}/lib
build.conf = ${build.dir}/conf
build.classes = ${build.dir}/classes
build.tests = ${build.dir}/tests
build.reports = ${build.dir}/reports
# Set the properties for source directories
src.dir = src
java.dir = ${src.dir}/java
conf.dir = ${src.dir}/conf
test.dir = ${src.dir}/test
# needed by Cocoon
build.context = ${build.dir}/documentation
build.docs = ${build.dir}/docs
build.xdocs = ${build.dir}/xdocs
context.dir = ../../jakarta-avalon/src/documentation
tools.dir = ../../jakarta-avalon/tools
tools.jar = ${java.home}/../lib/tools.jar
docs.dir = docs
xdocs.dir = ${src.dir}/xdocs
# Set the properties for distribution directories
dist.dir = dist
dist.javadocs = ${docs.dir}/api
# name of .zip/.tar.gz/.bz2 files and their top-level directory
dist.name = ${name}-${version}
# name of jar file
jar.name = ${name}-${version}.jar
# property indicating directory where all distribution archives are placed
dist.base = distributions
depchecker.prefix=.
\ No newline at end of file
1.1 jakarta-avalon-excalibur/event/src/java/org/apache/excalibur/util/StringUtil.java
Index: StringUtil.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.util;
import java.util.StringTokenizer;
/**
* A set of utility operations that work on or create strings.
*
* @author <a href="mailto:peter at apache.org">Peter Donald</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/09/25 15:01:43 $
*/
public final class StringUtil
{
/**
* the line separator for this OS
*/
public static final String LINE_SEPARATOR = System.getProperty( "line.separator" );
private static final String SPACE_16 = " ";
private static final String SPACE_8 = " ";
private static final String SPACE_4 = " ";
private static final String SPACE_2 = " ";
private static final String SPACE_1 = " ";
///Private Constructor to block instantiation
private StringUtil()
{
}
/**
* Convenience utility to concatenate three strings together.
*/
public static final String concat( final String first,
final String second,
final String third )
{
return new StringBuffer( first ).append( second ).append( third ).toString();
}
/**
* Convenience utility to concatenate an array of strings together.
*/
public static final String concat( final String[] list )
{
final StringBuffer buffer = new StringBuffer();
for( int i = 0; i < list.length; i++ )
{
buffer.append( list[ i ] );
}
return buffer.toString();
}
/**
* Replace substrings of one string with another string and return altered string.
*
* @param original input string
* @param oldString the substring section to replace
* @param newString the new substring replacing old substring section
* @return converted string
*/
public static final String replaceSubString( final String original,
final String oldString,
final String newString )
{
final StringBuffer sb = new StringBuffer();
int end = original.indexOf( oldString );
int start = 0;
final int stringSize = oldString.length();
while( end != -1 )
{
sb.append( original.substring( start, end ) );
sb.append( newString );
start = end + stringSize;
end = original.indexOf( oldString, start );
}
end = original.length();
sb.append( original.substring( start, end ) );
return sb.toString();
}
/**
* Display bytes in hex format.
* <p>The display puts hex display on left and then writes out
* textual representation on right. The text replaces any
* non-printing character with a '.'</p>
*
* <p>Note that this code was based on work done by Barry Peterson
* on the Q2Java project</p>
*
* @param data the bytes to display
* @param length the number of bytes to display per line
* @return The display string
*/
public static final String hexDisplay( final byte[] data, final int length )
{
final StringBuffer sb = new StringBuffer();
for( int i = 0; i < length; i += 16 )
{
//int lineEnd = Math.min( i+16, fArrayLength );
int lineSize = Math.min( 16, length - i );
final int lineEnd = lineSize + i;
for( int j = i; j < lineEnd; j++ )
{
final int value = data[ j ] & 0xFF;
if( value < 16 ) sb.append( '0' );
sb.append( Integer.toHexString( value ) );
sb.append( ' ' );
}
int padcount = 16 - lineSize;
while( padcount > 0 )
{
padcount--;
sb.append( " " );
}
sb.append( " " );
for( int j = i; j < lineEnd; j++ )
{
final int value = data[ j ] & 0xFF;
//Shouldn't 255 be lower????????
if( ( value < 32 ) || ( value > 255 ) )
sb.append( '.' );
else
sb.append( (char)value );
}
sb.append( '\n' );
}
return sb.toString();
}
/**
* Truncate a string to maximum length;
*
* @param string the string
* @param length the length
* @return a truncated string or original string if it is short enough
*/
public static final String truncate( final String string, final int length )
{
if( length >= string.length() )
return string;
else
return string.substring( 0, length );
}
/**
* Truncate a string in a nice manner.
* The method will attempt to truncate the string
* on whitespace and append "..." to the end.
*
* @author <a href="mailto:nate@protomatter.com">Nate Sammons</a>
*/
public static final String truncateNicely( final String string, final int length )
{
if( length >= string.length() )
return string;
else if( 3 >= length )
{
final StringBuffer sb = new StringBuffer( length );
for( int i = 0; i < length; i++ ) sb.append( '.' );
return sb.toString();
}
final StringBuffer sb = new StringBuffer( length );
getIndexOfBreak( sb, string, 0, length - 3, true );
sb.append( "..." );
return sb.toString();
}
/**
* Wordwrap string to specified column.
* if force is true then words that exceed column length will be
* cut otherwise each word will exist on a line by itself.
*
* @param string string to word-wrap
* @param column the column at which to wrap
* @param force true if string should be force split at column
* @return The word-wrapped string
*/
public static final String wordWrap( final String string, final int column, final boolean force )
{
final int length = string.length();
final StringBuffer sb = new StringBuffer();
int start = 0;
int end = getIndexOfBreak( sb, string, start, column, force );
while( length != end )
{
//TODO: Make this EOL parameterizable
sb.append( "\n" );
start = end;
end = getIndexOfBreak( sb, string, start, column, force );
}
return sb.toString();
}
/**
* Splits the string on every token into an array of strings.
*
* @param string the string
* @param onToken the token
* @return the resultant array
*/
public static final String[] split( final String string, final String onToken )
{
final StringTokenizer tokenizer = new StringTokenizer( string, onToken );
final String[] result = new String[ tokenizer.countTokens() ];
for( int i = 0; i < result.length; i++ )
{
result[ i ] = tokenizer.nextToken();
}
return result;
}
/**
* Removes all the whitespace in a string
*/
public static final String stripWhitespace( final String string )
{
return concat( split( string, " \t\r\n\b" ) );
}
/**
* Joins the string array using specified separator.
*
* @param strings the array of strings to join
* @param separator the separator to use when joining
* @return the joined string
*/
public static final String join( final String[] strings, final String separator )
{
final StringBuffer sb = new StringBuffer();
for( int i = 0; i < strings.length; i++ )
{
sb.append( strings[ i ] );
sb.append( separator );
}
return sb.toString();
}
/**
* Utility to format a string given a set of constraints.
* TODO: Think of a better name than format!!!! ;)
*
* @param minSize the minimum size of output (0 to ignore)
* @param maxSize the maximum size of output (0 to ignore)
* @param rightJustify true if the string is to be right justified in it's box.
* @param string the input string
*/
public static final String format( final int minSize,
final int maxSize,
final boolean rightJustify,
final String string )
{
final StringBuffer sb = new StringBuffer( maxSize );
format( sb, minSize, maxSize, rightJustify, string );
return sb.toString();
}
/**
* Utility to format a string given a set of constraints.
* TODO: Think of a better name than format!!!! ;)
* Note this was thieved from the logkit project.
*
* @param sb the StringBuffer
* @param minSize the minimum size of output (0 to ignore)
* @param maxSize the maximum size of output (0 to ignore)
* @param rightJustify true if the string is to be right justified in it's box.
* @param string the input string
*/
public static final void format( final StringBuffer sb,
final int minSize,
final int maxSize,
final boolean rightJustify,
final String string )
{
final int size = string.length();
if( size < minSize )
{
//assert( minSize > 0 );
if( rightJustify )
{
appendWhiteSpace( sb, minSize - size );
sb.append( string );
}
else
{
sb.append( string );
appendWhiteSpace( sb, minSize - size );
}
}
else if( maxSize > 0 && maxSize < size )
{
if( rightJustify )
{
sb.append( string.substring( size - maxSize ) );
}
else
{
sb.append( string.substring( 0, maxSize ) );
}
}
else
{
sb.append( string );
}
}
/**
* Append a certain number of whitespace characters to a StringBuffer.
*
* @param sb the StringBuffer
* @param length the number of spaces to append
*/
public static final void appendWhiteSpace( final StringBuffer sb, int length )
{
while( length >= 16 )
{
sb.append( SPACE_16 );
length -= 16;
}
if( length >= 8 )
{
sb.append( SPACE_8 );
length -= 8;
}
if( length >= 4 )
{
sb.append( SPACE_4 );
length -= 4;
}
if( length >= 2 )
{
sb.append( SPACE_2 );
length -= 2;
}
if( length >= 1 )
{
sb.append( SPACE_1 );
length -= 1;
}
}
/**
* Get index of good place to break line.
* The index is the last whitespace character.
*
* @param string the input string
* @param start the start index of line
* @param maxCount the max size of the line
* @return the index to break line
*/
private static final int getIndexOfBreak( final StringBuffer sb,
final String string,
final int start,
final int maxCount,
final boolean forceBreak )
{
final int end = string.length() - start;
int max = Math.min( maxCount, end );
int base = 0;
for( int i = 0; i < max; i++ )
{
final int index = start + i;
final char ch = string.charAt( index );
if( !Character.isWhitespace( ch ) ) break;
base = i + 1;
}
max += base;
int breakIndex = -1;
for( int i = base; i < max; i++ )
{
final int index = start + i;
final char ch = string.charAt( index );
if( Character.isWhitespace( ch ) ) breakIndex = index;
}
if( -1 != breakIndex )
{
final String part = string.substring( start + base, breakIndex );
sb.append( part );
return breakIndex + 1;
}
else
{
if( forceBreak )
{
final String part = string.substring( start + base, start + max );
sb.append( part );
return start + max;
}
else
{
return getIndexOfBreak( sb, string, start, Integer.MAX_VALUE, true );
}
}
}
}
1.1 jakarta-avalon-excalibur/event/src/test/org/apache/excalibur/util/test/StringUtilTestCase.java
Index: StringUtilTestCase.java
===================================================================
/*
* Copyright The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.util.test;
import junit.framework.TestCase;
import org.apache.excalibur.util.StringUtil;
/**
* This is used to test StringUtil for correctness.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
*/
public final class StringUtilTestCase
extends TestCase
{
private static final String S1 = "TestMe";
private static final String S2 = "TestMeTestMe";
private static final String S3 = "TestMeTestMeTestMe";
private static final String S4 = "MeeeMer";
private static final String S5 = "MeeeeMer";
private static final String P11 = "eT";
private static final String P21 = "eT";
private static final String P31 = "eT";
private static final String P41 = "ee";
private static final String P51 = "ee";
private static final String P12 = "Te";
private static final String P22 = "Te";
private static final String P32 = "Te";
private static final String P42 = "ff";
private static final String P52 = "ff";
private static final String SR1 = "TestMe";
private static final String SR2 = "TestMTeestMe";
private static final String SR3 = "TestMTeestMTeestMe";
private static final String SR4 = "MffeMer";
private static final String SR5 = "MffffMer";
private static final String ST1 = "TestMe";
private static final String ST2 = "TestMeT";
private static final String ST3 = "TestMeT";
private static final String ST4 = "MeeeMer";
private static final String ST5 = "MeeeeMe";
private static final String STN1 = "TestMe";
private static final String STN2 = "Test...";
private static final String STN3 = "Test...";
private static final String STN4 = "MeeeMer";
private static final String STN5 = "Meee...";
private static final String[] SS1 = new String[]{"T", "stM"};
private static final String[] SS2 = new String[]{"T", "stM", "T", "stM"};
private static final String[] SS3 = new String[]{"T", "stM", "T", "stM", "T", "stM"};
private static final String[] SS4 = new String[]{"M", "M", "r"};
private static final String[] SS5 = new String[]{"M", "M", "r"};
private static final String SP = " ";
private static final String WU1 = S1 + SP + S2 + SP + S3 + SP + S4 + SP + S5;
private static final String WW1 =
"TestMe\n" +
"TestMeTe\n" +
"stMe\n" +
"TestMeTe\n" +
"stMeTest\n" +
"Me\n" +
"MeeeMer\n" +
"MeeeeMer";
private static final String WW2 =
"TestMe\n" +
"TestMeT\n" +
"estMe\n" +
"TestMeT\n" +
"estMeTe\n" +
"stMe\n" +
"MeeeMer\n" +
"MeeeeMe\n" +
"r";
public StringUtilTestCase( final String name )
{
super( name );
}
public void testReplaceSubString()
throws Exception
{
final String result1 = StringUtil.replaceSubString( S1, P11, P12 );
final String result2 = StringUtil.replaceSubString( S2, P21, P22 );
final String result3 = StringUtil.replaceSubString( S3, P31, P32 );
final String result4 = StringUtil.replaceSubString( S4, P41, P42 );
final String result5 = StringUtil.replaceSubString( S5, P51, P52 );
assertEquals( "ReplaceSubString SR1", SR1, result1 );
assertEquals( "ReplaceSubString SR2", SR2, result2 );
assertEquals( "ReplaceSubString SR3", SR3, result3 );
assertEquals( "ReplaceSubString SR4", SR4, result4 );
assertEquals( "ReplaceSubString SR5", SR5, result5 );
}
public void testWordWrap()
throws Exception
{
assertEquals( "WordWrap S1", WW1, StringUtil.wordWrap( WU1, 8, true ) );
assertEquals( "WordWrap S1", WW2, StringUtil.wordWrap( WU1, 7, true ) );
}
public void testTruncate()
throws Exception
{
assertEquals( "Truncate S1", ST1, StringUtil.truncate( S1, 7 ) );
assertEquals( "Truncate S2", ST2, StringUtil.truncate( S2, 7 ) );
assertEquals( "Truncate S3", ST3, StringUtil.truncate( S3, 7 ) );
assertEquals( "Truncate S4", ST4, StringUtil.truncate( S4, 7 ) );
assertEquals( "Truncate S5", ST5, StringUtil.truncate( S5, 7 ) );
}
public void testTruncateNicely()
throws Exception
{
assertEquals( "Truncate Nicely S1", STN1, StringUtil.truncateNicely( S1, 7 ) );
assertEquals( "Truncate Nicely S2", STN2, StringUtil.truncateNicely( S2, 7 ) );
assertEquals( "Truncate Nicely S3", STN3, StringUtil.truncateNicely( S3, 7 ) );
assertEquals( "Truncate Nicely S4", STN4, StringUtil.truncateNicely( S4, 7 ) );
assertEquals( "Truncate Nicely S5", STN5, StringUtil.truncateNicely( S5, 7 ) );
assertEquals( "Truncate Nicely 1", ".", StringUtil.truncateNicely( S5, 1 ) );
assertEquals( "Truncate Nicely 2", "..", StringUtil.truncateNicely( S5, 2 ) );
assertEquals( "Truncate Nicely 3", "...", StringUtil.truncateNicely( S5, 3 ) );
}
public void testSplitString()
throws Exception
{
assertEqualArrays( SS1, StringUtil.split( S1, "e" ) );
assertEqualArrays( SS2, StringUtil.split( S2, "e" ) );
assertEqualArrays( SS3, StringUtil.split( S3, "e" ) );
assertEqualArrays( SS4, StringUtil.split( S4, "e" ) );
assertEqualArrays( SS5, StringUtil.split( S5, "e" ) );
}
public void testConcatStrings()
throws Exception
{
assertEquals( "TestMeTruly", StringUtil.concat( "Test", "Me", "Truly" ) );
assertEquals( "<prefix:name/>", StringUtil.concat( new String[]{
"<",
"prefix",
":",
"name",
"/>"
} ) );
}
public void testStripWhiteSpace()
{
assertEquals( "TestMeTruly", StringUtil.stripWhitespace( " Test Me Truly" ) );
}
private void assertEqualArrays( final String[] s1, final String[] s2 )
{
assertEquals( "Array Length Equality", s1.length, s2.length );
assertEquals( "Array Type Equality",
s1.getClass().getComponentType(),
s2.getClass().getComponentType() );
for( int i = 0; i < s1.length; i++ )
{
assertEquals( "Array Element " + i, s1[ i ], s2[ i ] );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>