FileDocCategorySizeDatePackage
StringUtilsTest.javaAPI DocApache Ant 1.704147Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util

StringUtilsTest

public class StringUtilsTest extends TestCase
Test for StringUtils

Fields Summary
Constructors Summary
public StringUtilsTest(String s)

        super(s);
    
Methods Summary
private java.lang.StringBuffergetFilledBuffer(int size, char ch)

        StringBuffer buf = new StringBuffer(size);
        for (int i = 0; i < size; i++) { buf.append(ch); };
        return buf;
    
public voidtestEndsWithBothEmpty()

        assertTrue( StringUtils.endsWith( new StringBuffer(), "") );
    
public voidtestEndsWithEmptyBuffer()

        assertFalse( StringUtils.endsWith( new StringBuffer(""), "12345667") );
    
public voidtestEndsWithEmptyString()

        assertTrue( StringUtils.endsWith( new StringBuffer("12234545"), "") );
    
public voidtestEndsWithJDKPerf()

        StringBuffer buf = getFilledBuffer(1024*300, 'a");
        for (int i = 0; i < 1000; i++) {
            assertTrue(buf.toString().endsWith("aa"));
        }
    
public voidtestEndsWithLongerString()

        assertFalse( StringUtils.endsWith( new StringBuffer("12"), "1245"));
    
public voidtestEndsWithNoMatch()

        assertFalse( StringUtils.endsWith( new StringBuffer("12345678"), "789"));
    
public voidtestEndsWithPerf()

        StringBuffer buf = getFilledBuffer(1024*300, 'a");
        for (int i = 0; i < 1000; i++) {
            assertTrue(StringUtils.endsWith(buf, "aa"));
        }
    
public voidtestEndsWithSameString()

        assertTrue( StringUtils.endsWith( new StringBuffer("123"), "123"));
    
public voidtestEndsWithShorterString()

        assertTrue( StringUtils.endsWith( new StringBuffer("12345678"), "78"));
    
public voidtestParseHumanSizes()

    	final long KILOBYTE = 1024;
    	final long MEGABYTE = KILOBYTE * 1024;
    	final long GIGABYTE = MEGABYTE * 1024;
    	final long TERABYTE = GIGABYTE * 1024;
    	final long PETABYTE = TERABYTE * 1024;
    	assertEquals(StringUtils.parseHumanSizes("1K"), KILOBYTE);
    	assertEquals(StringUtils.parseHumanSizes("1M"), MEGABYTE);
    	assertEquals(StringUtils.parseHumanSizes("1G"), GIGABYTE);
    	assertEquals(StringUtils.parseHumanSizes("1T"), TERABYTE);
    	assertEquals(StringUtils.parseHumanSizes("1P"), PETABYTE);
    	assertEquals(StringUtils.parseHumanSizes("1"), 1L);
    
public voidtestReplace()

        final String data = "abcabcabca";
        String res = StringUtils.replace(data, "a", "");
        assertEquals("bcbcbc", res);
    
public voidtestSplit()

        final String data = "a,b,,";
        Vector res = StringUtils.split(data, ',");
        assertEquals(4, res.size());
        assertEquals("a", res.elementAt(0));
        assertEquals("b", res.elementAt(1));
        assertEquals("", res.elementAt(2));
        assertEquals("", res.elementAt(3));
    
public voidtestSplitLines()

        final String data = "a\r\nb\nc\nd\ne";
        Vector res = StringUtils.lineSplit(data);
        assertEquals(5, res.size());
        assertEquals("a\r", res.elementAt(0));
        assertEquals("b", res.elementAt(1));
        assertEquals("c", res.elementAt(2));
        assertEquals("d", res.elementAt(3));
        assertEquals("e", res.elementAt(4));