commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roxspr...@apache.org
Subject cvs commit: jakarta-commons/cli/src/test/org/apache/commons/cli BugsTest.java
Date Mon, 06 Sep 2004 22:51:45 GMT
roxspring    2004/09/06 15:51:45

  Modified:    cli/src/test/org/apache/commons/cli BugsTest.java
  Log:
  Test checks the displayed output and does so quietly
  
  Revision  Changes    Path
  1.19      +27 -5     jakarta-commons/cli/src/test/org/apache/commons/cli/BugsTest.java
  
  Index: BugsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/BugsTest.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- BugsTest.java	22 Apr 2004 23:00:07 -0000	1.18
  +++ BugsTest.java	6 Sep 2004 22:51:45 -0000	1.19
  @@ -15,6 +15,10 @@
    */
   package org.apache.commons.cli;
   
  +import java.io.ByteArrayOutputStream;
  +import java.io.PrintStream;
  +import java.io.StringWriter;
  +
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -274,12 +278,30 @@
                                          .hasArg()
                                          .create( 'd' );
           options.addOption( dir );
  -        try {
  -            HelpFormatter formatter = new HelpFormatter();
  -            formatter.printHelp( "dir", options );
  +        
  +        
  +        final PrintStream oldSystemOut = System.out;
  +        try{
  +            final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  +            final PrintStream print = new PrintStream(bytes);
  +            
  +            // capture this platform's eol symbol
  +            print.println();
  +            final String eol = bytes.toString();
  +            bytes.reset();
  +            
  +            System.setOut(new PrintStream(bytes));
  +            try {
  +                HelpFormatter formatter = new HelpFormatter();
  +                formatter.printHelp( "dir", options );
  +            }
  +            catch( Exception exp ) {
  +                fail( "Unexpected Exception: " + exp.getMessage() );
  +            }
  +            assertEquals("usage: dir"+eol+" -d <arg>   dir"+eol,bytes.toString());
           }
  -        catch( Exception exp ) {
  -            fail( "Unexpected Exception: " + exp.getMessage() );
  +        finally {
  +            System.setOut(oldSystemOut);
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message