commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject svn commit: r278885 - /jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java
Date Mon, 05 Sep 2005 23:35:01 GMT
Author: jkeyes
Date: Mon Sep  5 16:34:50 2005
New Revision: 278885

URL: http://svn.apache.org/viewcvs?rev=278885&view=rev
Log:
- added comparator test

Modified:
    jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java

Modified: jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java?rev=278885&r1=278884&r2=278885&view=diff
==============================================================================
--- jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java
(original)
+++ jakarta/commons/proper/cli/trunk/src/test/org/apache/commons/cli2/util/HelpFormatterTest.java
Mon Sep  5 16:34:50 2005
@@ -21,6 +21,7 @@
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -168,6 +169,75 @@
         assertNull(reader.readLine());
     }
 
+    public void testComparator() throws IOException {
+        final StringWriter writer = new StringWriter();
+        final PrintWriter pw = new PrintWriter(writer);
+        helpFormatter.setPrintWriter(pw);
+        final Comparator comparator = new OptionComparator();
+        helpFormatter.setComparator(comparator);
+        helpFormatter.print();
+
+        // test comparator
+        assertEquals("invalid comparator", comparator, helpFormatter.getComparator());
+        final BufferedReader reader =
+            new BufferedReader(new StringReader(writer.toString()));
+        assertEquals(
+            "+------------------------------------------------------------------------------+",
+            reader.readLine());
+        assertEquals(
+            "|*Jakarta Commons CLI                                                      
  *|",
+            reader.readLine());
+        assertEquals(
+            "+------------------------------------------------------------------------------+",
+            reader.readLine());
+        assertEquals(
+            "|*Usage:                                                                   
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*ant [--verbose --projecthelp --help --diagnostics] [<target1> [<target2>
   *|",
+            reader.readLine());
+        assertEquals(
+            "|*...]]                                                                    
  *|",
+            reader.readLine());
+        assertEquals(
+            "+------------------------------------------------------------------------------+",
+            reader.readLine());
+        assertEquals(
+            "|*options              *-*                                                 
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*  --verbose          *-*print the version information and exit           
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*  --projecthelp      *-*print project help information                   
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*  --help (-?,-h)     *-*Displays the help                                
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*  --diagnostics      *-*print information that might be helpful to diagnose
*|",
+            reader.readLine());
+        assertEquals(
+            "|*                     *-*or report problems.                              
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*  target [target ...]*-*The targets ant should build                     
  *|",
+            reader.readLine());
+        assertEquals(
+            "+------------------------------------------------------------------------------+",
+            reader.readLine());
+        assertEquals(
+            "|*Copyright 2003                                                           
  *|",
+            reader.readLine());
+        assertEquals(
+            "|*Apache Software Foundation                                               
  *|",
+            reader.readLine());
+        assertEquals(
+            "+------------------------------------------------------------------------------+",
+            reader.readLine());
+        assertNull(reader.readLine());
+    }
+
     public void testPrintHelp() throws IOException {
         final StringWriter writer = new StringWriter();
         helpFormatter.setPrintWriter(new PrintWriter(writer));
@@ -528,5 +598,15 @@
             "  target [target ...]    The targets ant should build                      
    ",
             reader.readLine());
         assertNull(reader.readLine());
+    }
+}
+
+
+class OptionComparator implements Comparator {
+
+    public int compare(Object o1, Object o2) {
+        Option opt1 = (Option) o1;
+        Option opt2 = (Option) o2;
+        return -opt1.getPreferredName().compareTo(opt2.getPreferredName());
     }
 }



---------------------------------------------------------------------
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