1 10 package org.apache.commons.cli; 11 12 import junit.framework.TestCase; 13 import junit.framework.TestSuite; 14 15 import java.io.StringWriter ; 16 import java.io.PrintWriter ; 17 18 23 public class PatternOptionBuilderTest 24 extends TestCase 25 { 26 public static void main( String [] args ) 27 { 28 String [] testName = { PatternOptionBuilderTest.class.getName() }; 29 junit.textui.TestRunner.main(testName); 30 } 31 32 public static TestSuite suite() 33 { 34 return new TestSuite(PatternOptionBuilderTest.class); 35 } 36 37 public PatternOptionBuilderTest( String s ) 38 { 39 super( s ); 40 } 41 42 public void testSimplePattern() 43 { 44 try { 45 Options options = PatternOptionBuilder.parsePattern("a:b@cde>f+n%t/"); 46 String [] args = new String [] { "-c", "-a", "foo", "-b", "java.util.Vector", "-e", "build.xml", "-f", "java.util.Calendar", "-n", "4.5", "-t", "http://jakarta.apache.org/" }; 47 48 CommandLineParser parser = new PosixParser(); 49 CommandLine line = parser.parse(options,args); 50 51 assertEquals("flag a", "foo", line.getOptionValue("a")); 54 assertEquals("flag a", "foo", line.getOptionValue('a')); 55 assertEquals("string flag a", "foo", line.getOptionObject("a")); 56 assertEquals("string flag a", "foo", line.getOptionObject('a')); 57 assertEquals("object flag b", new java.util.Vector (), line.getOptionObject("b")); 58 assertEquals("object flag b", new java.util.Vector (), line.getOptionObject('b')); 59 assertEquals("boolean true flag c", true, line.hasOption("c")); 60 assertEquals("boolean true flag c", true, line.hasOption('c')); 61 assertEquals("boolean false flag d", false, line.hasOption("d")); 62 assertEquals("boolean false flag d", false, line.hasOption('d')); 63 assertEquals("file flag e", new java.io.File ("build.xml"), line.getOptionObject("e")); 64 assertEquals("file flag e", new java.io.File ("build.xml"), line.getOptionObject('e')); 65 assertEquals("class flag f", java.util.Calendar .class, line.getOptionObject("f")); 66 assertEquals("class flag f", java.util.Calendar .class, line.getOptionObject('f')); 67 assertEquals("number flag n", new Float (4.5), line.getOptionObject("n")); 68 assertEquals("number flag n", new Float (4.5), line.getOptionObject('n')); 69 assertEquals("url flag t", new java.net.URL ("http://jakarta.apache.org/"), line.getOptionObject("t")); 70 assertEquals("url flag t", new java.net.URL ("http://jakarta.apache.org/"), line.getOptionObject('t')); 71 } 75 catch( ParseException exp ) { 76 fail( exp.getMessage() ); 77 } 78 catch( java.net.MalformedURLException exp ) { 79 fail( exp.getMessage() ); 80 } 81 } 82 83 } 84 | Popular Tags |