FileDocCategorySizeDatePackage
QuotedStringTokenizerTest.javaAPI DocGlassfish v2 API10596Fri May 04 22:26:00 BST 2007com.sun.enterprise.admin.util

QuotedStringTokenizerTest

public class QuotedStringTokenizerTest extends TestCase
Depends on junit.jar, admin-core/util.jsr

Fields Summary
Constructors Summary
Methods Summary
void_countTokens(java.lang.String s, int expCount)

        QuotedStringTokenizer tok = new QuotedStringTokenizer(s, null);
        Assert.assertEquals(expCount, tok.countTokens());
    
public static voidmain(java.lang.String[] args)

        junit.textui.TestRunner.run(suite());
        //junit.swingui.TestRunner.run(suite());
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(QuotedStringTokenizerTest.class);
        return suite;
    
protected voidtearDown()

    
public voidtestCountTokens()

        _countTokens("", 0);
        _countTokens(" ", 0);
        _countTokens("  ", 0);
        _countTokens("a", 1);
        _countTokens(" a", 1);
        _countTokens(" a ", 1);
        _countTokens("  a ", 1);
        _countTokens("  ab ", 1);
        _countTokens("  a b ", 2);
    
public voidtestCountTokensWithQuotes()

        _countTokens("\"a\"", 1);
        _countTokens("\"a b\"", 1);
        _countTokens(" \"a\" ", 1);
        _countTokens("\"", 1);
        _countTokens("\"\"", 1);
        _countTokens("\" \"", 1);
        _countTokens("\"a\"b", 1);
        _countTokens("\"a\" b", 2);
        _countTokens("\"a\" \"b\"", 2);
        _countTokens("\"a\"\"b\"", 1);
        _countTokens("\" ", 1);
    
public voidtestCreate()

        new QuotedStringTokenizer("");
        new QuotedStringTokenizer("a");
        try {
            new QuotedStringTokenizer(null);
            Assert.assertTrue(false);
        } catch (IllegalArgumentException iae) {}
    
public voidtestIsDelimiter()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("");
        Assert.assertTrue(tok.isDelimiter('\t"));
    
public voidtestJavaStringTokenizer()

        StringTokenizer tok = new StringTokenizer("\" ", " ");
        Assert.assertEquals("\"", tok.nextToken());
        tok = new StringTokenizer("a", "\"");
        Assert.assertEquals("a", tok.nextToken());
        tok = new StringTokenizer("\"\"", "\" ");
        Assert.assertEquals(0, tok.countTokens());
        tok = new StringTokenizer("\t\"\t", "\" ");
        Assert.assertEquals(2, tok.countTokens());
    
public voidtestNextToken1()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("a");
        Assert.assertTrue(tok.hasMoreTokens());
        Assert.assertEquals("a", tok.nextToken());
        Assert.assertFalse(tok.hasMoreTokens());
        try {
            tok.nextToken();
            Assert.assertTrue(false);
        } catch (java.util.NoSuchElementException nsee) {}
    
public voidtestNextToken2()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("");
        Assert.assertFalse(tok.hasMoreTokens());
        try {
            tok.nextToken();
            Assert.assertTrue(false);
        } catch (java.util.NoSuchElementException nsee) {}
    
public voidtestNextToken3()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("a b c d e f");
        Assert.assertTrue(tok.countTokens() == 6);
        tok.nextToken();
        Assert.assertEquals("b", tok.nextToken());
        Assert.assertTrue(tok.hasMoreTokens());
        while (tok.hasMoreTokens())
            tok.nextToken();
        try {
            tok.nextToken();
            Assert.assertTrue(false);
        } catch (java.util.NoSuchElementException nsee) {}
    
public voidtestNextToken4()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("abcdef");
        Assert.assertTrue(tok.countTokens() == 1);
        Assert.assertEquals("abcdef", tok.nextToken());
        tok = new QuotedStringTokenizer("     abcdef       g      ");
        Assert.assertTrue(tok.countTokens() == 2);
        Assert.assertEquals("abcdef", tok.nextToken());
        Assert.assertEquals("g", tok.nextToken());
    
public voidtestNextToken5()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("abc \t d \t\t ef");
        Assert.assertEquals(3, tok.countTokens());
        Assert.assertEquals("abc", tok.nextToken());
        Assert.assertEquals("d", tok.nextToken());
        Assert.assertEquals("ef", tok.nextToken());
    
public voidtestNextTokenWithQuotes()

        QuotedStringTokenizer mtok = new QuotedStringTokenizer("\"\"");
        Assert.assertEquals("\"\"", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\"");
        Assert.assertEquals("\"", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        //??
        mtok = new QuotedStringTokenizer("\" ");
        Assert.assertEquals("\" ", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        //??
        mtok = new QuotedStringTokenizer(" \" ");
        Assert.assertEquals("\" ", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\t\"\t");
        Assert.assertEquals("\"\t", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\"a\"");
        Assert.assertEquals("\"a\"", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer(" \"a\" ");
        Assert.assertEquals("\"a\"", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\"a");
        Assert.assertEquals("\"a", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\"a\" \"b\"");
        Assert.assertEquals("\"a\"", mtok.nextToken());
        Assert.assertEquals("\"b\"", mtok.nextToken());

        mtok = new QuotedStringTokenizer("\"a\"b");
        Assert.assertEquals("\"a\"b", mtok.nextToken());

        //??
        mtok = new QuotedStringTokenizer("\"a ");
        Assert.assertEquals("\"a ", mtok.nextToken());

        mtok = new QuotedStringTokenizer("\"a b\"");
        Assert.assertEquals(1, mtok.countTokens());
        Assert.assertEquals("\"a b\"", mtok.nextToken());
    
public voidtestQuotesInQuotes()

        QuotedStringTokenizer tok = new QuotedStringTokenizer("\"abc\"def g");
        Assert.assertEquals("\"abc\"def", tok.nextToken());
        Assert.assertEquals("g", tok.nextToken());

        tok = new QuotedStringTokenizer("\"abc\"def\"");
        Assert.assertEquals("\"abc\"def\"", tok.nextToken());

        tok = new QuotedStringTokenizer(" \"abc\"def\" ");
        Assert.assertEquals("\"abc\"def\" ", tok.nextToken());
    
public voidtestWithQuoteAsDelimiter()

        QuotedStringTokenizer mtok = new QuotedStringTokenizer("\"\"", "\" ");
        Assert.assertEquals(0, mtok.countTokens());

        mtok = new QuotedStringTokenizer("\"", "\" ");
        Assert.assertEquals(0, mtok.countTokens());

        mtok = new QuotedStringTokenizer("\" ", "\" ");
        Assert.assertEquals(0, mtok.countTokens());

        mtok = new QuotedStringTokenizer(" \" ", "\" ");
        Assert.assertEquals(0, mtok.countTokens());

        mtok = new QuotedStringTokenizer("\t\"\t", "\" ");
        Assert.assertEquals(2, mtok.countTokens());

        mtok = new QuotedStringTokenizer("\"a\"", "\" ");
        Assert.assertEquals("a", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer(" \"a\" ", "\" ");
        Assert.assertEquals("a", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\"a", "\" ");
        Assert.assertEquals("a", mtok.nextToken());
        Assert.assertFalse(mtok.hasMoreTokens());

        mtok = new QuotedStringTokenizer("\"a\" \"b\"", "\" ");
        Assert.assertEquals("a", mtok.nextToken());
        Assert.assertEquals("b", mtok.nextToken());

        mtok = new QuotedStringTokenizer("\"a\"b", "\" ");
        Assert.assertEquals("a", mtok.nextToken());
        Assert.assertEquals("b", mtok.nextToken());

        mtok = new QuotedStringTokenizer("ab", "\" ");
        Assert.assertEquals("ab", mtok.nextToken());