Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 21023 invoked from network); 6 Dec 2006 21:44:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Dec 2006 21:44:09 -0000 Received: (qmail 30728 invoked by uid 500); 6 Dec 2006 21:44:17 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 30709 invoked by uid 500); 6 Dec 2006 21:44:17 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 30700 invoked by uid 99); 6 Dec 2006 21:44:17 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Dec 2006 13:44:17 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Dec 2006 13:44:07 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id D72921A9846; Wed, 6 Dec 2006 13:43:25 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r483249 - /harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java Date: Wed, 06 Dec 2006 21:43:25 -0000 To: commits@harmony.apache.org From: hindessm@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061206214325.D72921A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: hindessm Date: Wed Dec 6 13:43:24 2006 New Revision: 483249 URL: http://svn.apache.org/viewvc?view=rev&rev=483249 Log: Use junit for exception handling to reduce clutter and improve failure messages. Changed one test case to use assertEquals instead of assertTrue for more helpful error messages. Added TODO item as reminder to do the other test cases so I can get on with looking at why the test failed. Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java?view=diff&rev=483249&r1=483248&r2=483249 ============================================================================== --- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java (original) +++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/StreamTokenizerTest.java Wed Dec 6 13:43:24 2006 @@ -26,6 +26,10 @@ import java.io.StringBufferInputStream; import tests.support.Support_StringReader; +// TODO: most of the assertTrue calls in this test case should be +// replaced with assertEquals (possibly two assertEquals) see +// test_ConstructorLjava_io_InputStream for example. +// This gives much more helpful error messages. public class StreamTokenizerTest extends junit.framework.TestCase { Support_StringReader r; @@ -37,324 +41,259 @@ /** * @tests java.io.StreamTokenizer#StreamTokenizer(java.io.InputStream) */ - public void test_ConstructorLjava_io_InputStream() { + public void test_ConstructorLjava_io_InputStream() throws IOException { st = new StreamTokenizer(new StringBufferInputStream( "/comments\n d 8 'h'")); - try { - assertTrue( - "nextTokent() should return the character d skiping the comments", - st.nextToken() == StreamTokenizer.TT_WORD - && st.sval.equals("d")); - assertTrue("the next token returned should be the digit 8", st - .nextToken() == StreamTokenizer.TT_NUMBER - && st.nval == 8.0); - assertTrue("the next token returned should be the quote character", - st.nextToken() == 39 && st.sval.equals("h")); - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } + + assertEquals("the next token returned should be the letter d", + StreamTokenizer.TT_WORD, st.nextToken()); + assertEquals("the next token returned should be the letter d", + "d", st.sval); + + assertEquals("the next token returned should be the digit 8", + StreamTokenizer.TT_NUMBER, st.nextToken()); + assertEquals("the next token returned should be the digit 8", + 8.0, st.nval); + + assertEquals("the next token returned should be the quote character", + 39, st.nextToken()); + assertEquals("the next token returned should be the quote character", + "h", st.sval); } /** * @tests java.io.StreamTokenizer#StreamTokenizer(java.io.Reader) */ - public void test_ConstructorLjava_io_Reader() { + public void test_ConstructorLjava_io_Reader() throws IOException { setTest("/testing\n d 8 'h' "); - try { - assertTrue( - "nextTokent() should return the character d skiping the comments", - st.nextToken() == StreamTokenizer.TT_WORD - && st.sval.equals("d")); - assertTrue("the next token returned should be the digit 8", st - .nextToken() == StreamTokenizer.TT_NUMBER - && st.nval == 8.0); - assertTrue("the next token returned should be the quote character", - st.nextToken() == 39 && st.sval.equals("h")); - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } + assertEquals("the next token returned should be the letter d skipping the comments", + StreamTokenizer.TT_WORD, st.nextToken()); + assertEquals("the next token returned should be the letter d", + "d", st.sval); + + assertEquals("the next token returned should be the digit 8", + StreamTokenizer.TT_NUMBER, st.nextToken()); + assertEquals("the next token returned should be the digit 8", + 8.0, st.nval); + + assertEquals("the next token returned should be the quote character", + 39, st.nextToken()); + assertEquals("the next token returned should be the quote character", + "h", st.sval); } /** * @tests java.io.StreamTokenizer#commentChar(int) */ - public void test_commentCharI() { + public void test_commentCharI() throws IOException { setTest("*comment \n / 8 'h' "); st.ordinaryChar('/'); st.commentChar('*'); - try { - assertEquals("nextTokent() did not return the character / skiping the comments starting with *", - 47, st.nextToken()); - assertTrue("the next token returned should be the digit 8", st - .nextToken() == StreamTokenizer.TT_NUMBER - && st.nval == 8.0); - assertTrue("the next token returned should be the quote character", - st.nextToken() == 39 && st.sval.equals("h")); - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } + assertEquals("nextToken() did not return the character / skiping the comments starting with *", + 47, st.nextToken()); + assertTrue("the next token returned should be the digit 8", st + .nextToken() == StreamTokenizer.TT_NUMBER + && st.nval == 8.0); + assertTrue("the next token returned should be the quote character", + st.nextToken() == 39 && st.sval.equals("h")); } /** * @tests java.io.StreamTokenizer#eolIsSignificant(boolean) */ - public void test_eolIsSignificantZ() { + public void test_eolIsSignificantZ() throws IOException { setTest("d 8\n"); - try { - // by default end of line characters are not significant - assertTrue("nextToken did not return d", - st.nextToken() == StreamTokenizer.TT_WORD - && st.sval.equals("d")); - assertTrue("nextToken did not return 8", - st.nextToken() == StreamTokenizer.TT_NUMBER - && st.nval == 8.0); - assertTrue("nextToken should be the end of file", - st.nextToken() == StreamTokenizer.TT_EOF); - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } + // by default end of line characters are not significant + assertTrue("nextToken did not return d", + st.nextToken() == StreamTokenizer.TT_WORD + && st.sval.equals("d")); + assertTrue("nextToken did not return 8", + st.nextToken() == StreamTokenizer.TT_NUMBER + && st.nval == 8.0); + assertTrue("nextToken should be the end of file", + st.nextToken() == StreamTokenizer.TT_EOF); setTest("d\n"); st.eolIsSignificant(true); - try { - // end of line characters are significant - assertTrue("nextToken did not return d", - st.nextToken() == StreamTokenizer.TT_WORD - && st.sval.equals("d")); - assertTrue("nextToken is the end of line", - st.nextToken() == StreamTokenizer.TT_EOL); - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } + // end of line characters are significant + assertTrue("nextToken did not return d", + st.nextToken() == StreamTokenizer.TT_WORD + && st.sval.equals("d")); + assertTrue("nextToken is the end of line", + st.nextToken() == StreamTokenizer.TT_EOL); } /** * @tests java.io.StreamTokenizer#lineno() */ - public void test_lineno() { + public void test_lineno() throws IOException { setTest("d\n 8\n"); - try { - assertEquals("the lineno should be 1", 1, st.lineno()); - st.nextToken(); - st.nextToken(); - assertEquals("the lineno should be 2", 2, st.lineno()); - st.nextToken(); - assertEquals("the next line no should be 3", 3, st.lineno()); - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } + assertEquals("the lineno should be 1", 1, st.lineno()); + st.nextToken(); + st.nextToken(); + assertEquals("the lineno should be 2", 2, st.lineno()); + st.nextToken(); + assertEquals("the next line no should be 3", 3, st.lineno()); } /** * @tests java.io.StreamTokenizer#lowerCaseMode(boolean) */ - public void test_lowerCaseModeZ() { + public void test_lowerCaseModeZ() throws Exception { // SM. setTest("HELLOWORLD"); st.lowerCaseMode(true); - try { - st.nextToken(); - assertEquals("sval not converted to lowercase.", "helloworld", st.sval - ); - } catch (Exception e) { - fail("Exception during test : " + e.getMessage()); - } + + st.nextToken(); + assertEquals("sval not converted to lowercase.", "helloworld", st.sval + ); } /** * @tests java.io.StreamTokenizer#nextToken() */ - public void test_nextToken() { + public void test_nextToken() throws IOException { // SM. setTest("\r\n/* fje fje 43.4 f \r\n f g */ 456.459 \r\n" + "Hello / \r\n \r\n \n \r \257 Hi \'Hello World\'"); st.ordinaryChar('/'); st.slashStarComments(true); - try { - st.nextToken(); - assertTrue("Wrong Token type1: " + (char) st.ttype, - st.ttype == StreamTokenizer.TT_NUMBER); - st.nextToken(); - assertTrue("Wrong Token type2: " + st.ttype, - st.ttype == StreamTokenizer.TT_WORD); - st.nextToken(); - assertTrue("Wrong Token type3: " + st.ttype, st.ttype == '/'); - st.nextToken(); - assertTrue("Wrong Token type4: " + st.ttype, - st.ttype == StreamTokenizer.TT_WORD); - st.nextToken(); - assertTrue("Wrong Token type5: " + st.ttype, - st.ttype == StreamTokenizer.TT_WORD); - st.nextToken(); - assertTrue("Wrong Token type6: " + st.ttype, st.ttype == '\''); - assertTrue("Wrong Token type7: " + st.ttype, st.sval - .equals("Hello World")); - st.nextToken(); - assertTrue("Wrong Token type8: " + st.ttype, st.ttype == -1); - - } catch (IOException e) { - fail( - "IOException occured while trying to read an input stream - constructor"); - } - - try { - final PipedInputStream pin = new PipedInputStream(); - PipedOutputStream pout = new PipedOutputStream(pin); - pout.write("hello\n\r\r".getBytes()); - StreamTokenizer s = new StreamTokenizer(pin); - s.eolIsSignificant(true); - assertTrue("Wrong token 1,1", - s.nextToken() == StreamTokenizer.TT_WORD - && s.sval.equals("hello")); - assertTrue("Wrong token 1,2", s.nextToken() == '\n'); - assertTrue("Wrong token 1,3", s.nextToken() == '\n'); - assertTrue("Wrong token 1,4", s.nextToken() == '\n'); - pout.close(); - assertTrue("Wrong token 1,5", - s.nextToken() == StreamTokenizer.TT_EOF); - } catch (IOException e) { - fail("IOException during test 1 : " + e.getMessage()); - } - - try { - StreamTokenizer tokenizer = new StreamTokenizer( - new Support_StringReader("\n \r\n#")); - tokenizer.ordinaryChar('\n'); // make \n ordinary - tokenizer.eolIsSignificant(true); - assertTrue("Wrong token 2,1", tokenizer.nextToken() == '\n'); - assertTrue("Wrong token 2,2", tokenizer.nextToken() == '\n'); - assertEquals("Wrong token 2,3", '#', tokenizer.nextToken()); - } catch (IOException e) { - fail("IOException during test 2 : " + e.getMessage()); - } + st.nextToken(); + assertTrue("Wrong Token type1: " + (char) st.ttype, + st.ttype == StreamTokenizer.TT_NUMBER); + st.nextToken(); + assertTrue("Wrong Token type2: " + st.ttype, + st.ttype == StreamTokenizer.TT_WORD); + st.nextToken(); + assertTrue("Wrong Token type3: " + st.ttype, st.ttype == '/'); + st.nextToken(); + assertTrue("Wrong Token type4: " + st.ttype, + st.ttype == StreamTokenizer.TT_WORD); + st.nextToken(); + assertTrue("Wrong Token type5: " + st.ttype, + st.ttype == StreamTokenizer.TT_WORD); + st.nextToken(); + assertTrue("Wrong Token type6: " + st.ttype, st.ttype == '\''); + assertTrue("Wrong Token type7: " + st.ttype, st.sval + .equals("Hello World")); + st.nextToken(); + assertTrue("Wrong Token type8: " + st.ttype, st.ttype == -1); + + final PipedInputStream pin = new PipedInputStream(); + PipedOutputStream pout = new PipedOutputStream(pin); + pout.write("hello\n\r\r".getBytes()); + StreamTokenizer s = new StreamTokenizer(pin); + s.eolIsSignificant(true); + assertTrue("Wrong token 1,1", + s.nextToken() == StreamTokenizer.TT_WORD + && s.sval.equals("hello")); + assertTrue("Wrong token 1,2", s.nextToken() == '\n'); + assertTrue("Wrong token 1,3", s.nextToken() == '\n'); + assertTrue("Wrong token 1,4", s.nextToken() == '\n'); + pout.close(); + assertTrue("Wrong token 1,5", + s.nextToken() == StreamTokenizer.TT_EOF); + StreamTokenizer tokenizer = new StreamTokenizer( + new Support_StringReader("\n \r\n#")); + tokenizer.ordinaryChar('\n'); // make \n ordinary + tokenizer.eolIsSignificant(true); + assertTrue("Wrong token 2,1", tokenizer.nextToken() == '\n'); + assertTrue("Wrong token 2,2", tokenizer.nextToken() == '\n'); + assertEquals("Wrong token 2,3", '#', tokenizer.nextToken()); } /** * @tests java.io.StreamTokenizer#ordinaryChar(int) */ - public void test_ordinaryCharI() { + public void test_ordinaryCharI() throws IOException { // SM. setTest("Ffjein 893"); - try { - st.ordinaryChar('F'); - st.nextToken(); - assertTrue("OrdinaryChar failed." + (char) st.ttype, - st.ttype == 'F'); - } catch (Exception e) { - fail("Exception during test : " + e.getMessage()); - } + st.ordinaryChar('F'); + st.nextToken(); + assertTrue("OrdinaryChar failed." + (char) st.ttype, + st.ttype == 'F'); } /** * @tests java.io.StreamTokenizer#ordinaryChars(int, int) */ - public void test_ordinaryCharsII() { + public void test_ordinaryCharsII() throws IOException { // SM. setTest("azbc iof z 893"); st.ordinaryChars('a', 'z'); - try { - assertEquals("OrdinaryChars failed.", 'a', st.nextToken()); - assertEquals("OrdinaryChars failed.", 'z', st.nextToken()); - } catch (Exception e) { - fail("Exception during test : " + e.getMessage()); - } + assertEquals("OrdinaryChars failed.", 'a', st.nextToken()); + assertEquals("OrdinaryChars failed.", 'z', st.nextToken()); } /** * @tests java.io.StreamTokenizer#parseNumbers() */ - public void test_parseNumbers() { + public void test_parseNumbers() throws IOException { // SM setTest("9.9 678"); - try { - assertTrue("Base behavior failed.", - st.nextToken() == StreamTokenizer.TT_NUMBER); - st.ordinaryChars('0', '9'); - assertEquals("setOrdinary failed.", '6', st.nextToken()); - st.parseNumbers(); - assertTrue("parseNumbers failed.", - st.nextToken() == StreamTokenizer.TT_NUMBER); - } catch (Exception e) { - fail("Exception during test : " + e.getMessage()); - } + assertTrue("Base behavior failed.", + st.nextToken() == StreamTokenizer.TT_NUMBER); + st.ordinaryChars('0', '9'); + assertEquals("setOrdinary failed.", '6', st.nextToken()); + st.parseNumbers(); + assertTrue("parseNumbers failed.", + st.nextToken() == StreamTokenizer.TT_NUMBER); } /** * @tests java.io.StreamTokenizer#pushBack() */ - public void test_pushBack() { + public void test_pushBack() throws IOException { // SM. setTest("Hello 897"); - try { - st.nextToken(); - st.pushBack(); - assertTrue("PushBack failed.", - st.nextToken() == StreamTokenizer.TT_WORD); - } catch (Exception e) { - fail("Exception during test : " + e.getMessage()); - } + st.nextToken(); + st.pushBack(); + assertTrue("PushBack failed.", + st.nextToken() == StreamTokenizer.TT_WORD); } /** * @tests java.io.StreamTokenizer#quoteChar(int) */ - public void test_quoteCharI() { + public void test_quoteCharI() throws IOException { // SM setTest("