1 package org.sapia.console; 2 3 import junit.framework.*; 4 5 6 10 public class CmdLineTest extends TestCase { 11 CmdLine _cmd; 12 13 16 public CmdLineTest(String name) { 17 super(name); 18 } 19 20 23 protected void setUp() throws Exception { 24 _cmd = CmdLine.parse( 25 "arg1 arg2 -opt1 val1 arg3 -opt2 val2 -opt3 \"opt3 value\" -opt4 -opt5"); 26 } 27 28 public void testFirst() throws Exception { 29 super.assertEquals("arg1", ((Arg) _cmd.first()).getName()); 30 } 31 32 public void testLast() throws Exception { 33 super.assertEquals("opt5", ((Option) _cmd.last()).getName()); 34 } 35 36 public void testFilterArgs() throws Exception { 37 CmdLine args = _cmd.filterArgs(); 38 super.assertEquals(3, args.size()); 39 } 40 41 public void testAssertNextArg() throws Exception { 42 CmdLine args = _cmd.filterArgs(); 43 44 while (args.hasNext()) { 45 args.assertNextArg(); 46 } 47 } 48 49 public void testAssertArgs() throws Exception { 50 CmdLine args = _cmd.filterArgs(); 51 args.assertNextArg(new String [] { "arg1", "arg2", "arg3" }); 52 args.assertNextArg(new String [] { "arg1", "arg2", "arg3" }); 53 args.assertNextArg(new String [] { "arg1", "arg2", "arg3" }); 54 55 try { 56 args.assertNextArg(new String [] { "arg1", "arg2", "arg3" }); 57 throw new Exception ("InputException should have been thrown"); 58 } catch (InputException e) { 59 } 61 } 62 63 public void testContainsOption() throws Exception { 64 super.assertTrue("Option missing", _cmd.containsOption("opt4", false)); 65 super.assertTrue("Option should not have been found", 66 !_cmd.containsOption("opt4", true)); 67 } 68 69 public void testAssertOption() throws Exception { 70 _cmd.assertOption("opt3", true); 71 _cmd.assertOption("opt2", "val2"); 72 _cmd.assertOption("opt2", new String [] { "val1", "val2", "val3" }); 73 } 74 75 public void testChop() throws Exception { 76 int size = _cmd.size(); 77 _cmd.chop(); 78 super.assertEquals(size - 1, _cmd.size()); 79 } 80 81 public void testChopArg() throws Exception { 82 super.assertEquals("arg1", _cmd.chopArg().getName()); 83 } 84 } 85 | Popular Tags |