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/java/org/apache/commons/cli2/commandline DefaultingCommandLine.java
Date Wed, 25 Feb 2004 00:01:14 GMT
roxspring    2004/02/24 16:01:14

  Modified:    cli/src/test/org/apache/commons/cli2/commandline Tag:
                        RESEARCH_CLI_2_ROXSPRING CommandLineImplTest.java
               cli/src/java/org/apache/commons/cli2/commandline Tag:
                        RESEARCH_CLI_2_ROXSPRING DefaultingCommandLine.java
  Added:       cli/src/test/org/apache/commons/cli2/commandline Tag:
                        RESEARCH_CLI_2_ROXSPRING
                        DefaultingCommandLineTest.java
  Log:
  DefaultingCommandLine test and bugfix
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.2   +1 -149    jakarta-commons/cli/src/test/org/apache/commons/cli2/commandline/Attic/CommandLineImplTest.java
  
  Index: CommandLineImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli2/commandline/Attic/CommandLineImplTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- CommandLineImplTest.java	22 Feb 2004 13:13:32 -0000	1.1.2.1
  +++ CommandLineImplTest.java	25 Feb 2004 00:01:14 -0000	1.1.2.2
  @@ -28,155 +28,7 @@
   
   public class CommandLineImplTest extends CLITestCase {
   	
  -	final Option present = new DefaultOptionBuilder().withLongName("present").create();
  -	final Option missing = new DefaultOptionBuilder().withLongName("missing").create();
  -	final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create();
  +	private CommandLine commandLine;
   	
  -	private CommandLine cmd;
   	
  -	/*
  -	 * @see TestCase#setUp()
  -	 */
  -	protected void setUp() throws Exception {
  -		final Option root = new GroupBuilder().create();
  -		
  -		final WriteableCommandLine writeable = new WriteableCommandLineImpl(root,new ArrayList());
  -		writeable.addOption(present);
  -		writeable.addProperty("present","present property");
  -		writeable.addSwitch(present,true);
  -		writeable.addValue(present,"present value");
  -		writeable.addOption(multiple);
  -		writeable.addValue(multiple,"value 1");
  -		writeable.addValue(multiple,"value 2");
  -		writeable.addValue(multiple,"value 3");
  -		
  -		cmd = writeable;
  -	}
  -	
  -	public final void testHasOption() {
  -		assertTrue(cmd.hasOption(present));
  -		assertFalse(cmd.hasOption(missing));
  -	}
  -	
  -	/*
  -	 * Class to test for List getValues(String)
  -	 */
  -	public final void testGetValuesString() {
  -		assertListContentsEqual(list("present value"),cmd.getValues("--present"));
  -		assertTrue(cmd.getValues("--missing").isEmpty());
  -	}
  -	
  -	/*
  -	 * Class to test for List getValues(String, List)
  -	 */
  -	public final void testGetValuesStringList() {
  -		assertListContentsEqual(list("present value"),cmd.getValues("--present",null));
  -		assertTrue(cmd.getValues("--missing",null).isEmpty());
  -		final List def = Collections.singletonList("default value");
  -		assertSame(def,cmd.getValues("--missing",def));
  -	}
  -	/*
  -	 * Class to test for List getValues(Option)
  -	 */
  -	public final void testGetValuesOption() {
  -		assertListContentsEqual(list("present value"),cmd.getValues(present));
  -		assertTrue(cmd.getValues(missing).isEmpty());
  -	}
  -	/*
  -	 * Class to test for Object getValue(String)
  -	 */
  -	public final void testGetValueString() {
  -		assertEquals("present value",cmd.getValue("--present"));
  -		assertNull(cmd.getValue("--missing"));
  -		try{
  -			cmd.getValue("--multiple");
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(String, Object)
  -	 */
  -	public final void testGetValueStringObject() {
  -		assertEquals("present value",cmd.getValue("--present","default value"));
  -		assertEquals("default value",cmd.getValue("--missing","default value"));
  -		try{
  -			cmd.getValue("--multiple");
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(Option)
  -	 */
  -	public final void testGetValueOption() {
  -		assertEquals("present value",cmd.getValue(present));
  -		assertNull(cmd.getValue(missing));
  -		try{
  -			cmd.getValue(multiple);
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(Option, Object)
  -	 */
  -	public final void testGetValueOptionObject() {
  -		assertEquals("present value",cmd.getValue(present,"default value"));
  -		assertEquals("default value",cmd.getValue(missing,"default value"));
  -		try{
  -			cmd.getValue(multiple);
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(String)
  -	 */
  -	public final void testGetSwitchString() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch("--present"));
  -		assertNull(cmd.getSwitch("--missing"));
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(String, Boolean)
  -	 */
  -	public final void testGetSwitchStringBoolean() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch("--present",Boolean.FALSE));
  -		assertEquals(Boolean.FALSE,cmd.getSwitch("--missing",Boolean.FALSE));
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(Option)
  -	 */
  -	public final void testGetSwitchOption() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch(present));
  -		assertNull(cmd.getSwitch(missing));
  -	}
  -	public final void testGetProperty() {
  -		assertEquals("present property",cmd.getProperty("present"));
  -		assertNull(cmd.getProperty("missing"));
  -	}
  -	/*
  -	 * Class to test for int getOptionCount(String)
  -	 */
  -	public final void testGetOptionCountString() {
  -		// one option, one switch
  -		assertEquals(2,cmd.getOptionCount("--present"));
  -		assertEquals(0,cmd.getOptionCount("--missing"));
  -	}
  -	/*
  -	 * Class to test for int getOptionCount(Option)
  -	 */
  -	public final void testGetOptionCountOption() {
  -		// one option, one switch
  -		assertEquals(2,cmd.getOptionCount(present));
  -		assertEquals(0,cmd.getOptionCount(missing));
  -	}
   }
  
  
  
  No                   revision
  
  Index: CommandLineImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli2/commandline/Attic/CommandLineImplTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- CommandLineImplTest.java	22 Feb 2004 13:13:32 -0000	1.1.2.1
  +++ CommandLineImplTest.java	25 Feb 2004 00:01:14 -0000	1.1.2.2
  @@ -28,155 +28,7 @@
   
   public class CommandLineImplTest extends CLITestCase {
   	
  -	final Option present = new DefaultOptionBuilder().withLongName("present").create();
  -	final Option missing = new DefaultOptionBuilder().withLongName("missing").create();
  -	final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create();
  +	private CommandLine commandLine;
   	
  -	private CommandLine cmd;
   	
  -	/*
  -	 * @see TestCase#setUp()
  -	 */
  -	protected void setUp() throws Exception {
  -		final Option root = new GroupBuilder().create();
  -		
  -		final WriteableCommandLine writeable = new WriteableCommandLineImpl(root,new ArrayList());
  -		writeable.addOption(present);
  -		writeable.addProperty("present","present property");
  -		writeable.addSwitch(present,true);
  -		writeable.addValue(present,"present value");
  -		writeable.addOption(multiple);
  -		writeable.addValue(multiple,"value 1");
  -		writeable.addValue(multiple,"value 2");
  -		writeable.addValue(multiple,"value 3");
  -		
  -		cmd = writeable;
  -	}
  -	
  -	public final void testHasOption() {
  -		assertTrue(cmd.hasOption(present));
  -		assertFalse(cmd.hasOption(missing));
  -	}
  -	
  -	/*
  -	 * Class to test for List getValues(String)
  -	 */
  -	public final void testGetValuesString() {
  -		assertListContentsEqual(list("present value"),cmd.getValues("--present"));
  -		assertTrue(cmd.getValues("--missing").isEmpty());
  -	}
  -	
  -	/*
  -	 * Class to test for List getValues(String, List)
  -	 */
  -	public final void testGetValuesStringList() {
  -		assertListContentsEqual(list("present value"),cmd.getValues("--present",null));
  -		assertTrue(cmd.getValues("--missing",null).isEmpty());
  -		final List def = Collections.singletonList("default value");
  -		assertSame(def,cmd.getValues("--missing",def));
  -	}
  -	/*
  -	 * Class to test for List getValues(Option)
  -	 */
  -	public final void testGetValuesOption() {
  -		assertListContentsEqual(list("present value"),cmd.getValues(present));
  -		assertTrue(cmd.getValues(missing).isEmpty());
  -	}
  -	/*
  -	 * Class to test for Object getValue(String)
  -	 */
  -	public final void testGetValueString() {
  -		assertEquals("present value",cmd.getValue("--present"));
  -		assertNull(cmd.getValue("--missing"));
  -		try{
  -			cmd.getValue("--multiple");
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(String, Object)
  -	 */
  -	public final void testGetValueStringObject() {
  -		assertEquals("present value",cmd.getValue("--present","default value"));
  -		assertEquals("default value",cmd.getValue("--missing","default value"));
  -		try{
  -			cmd.getValue("--multiple");
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(Option)
  -	 */
  -	public final void testGetValueOption() {
  -		assertEquals("present value",cmd.getValue(present));
  -		assertNull(cmd.getValue(missing));
  -		try{
  -			cmd.getValue(multiple);
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(Option, Object)
  -	 */
  -	public final void testGetValueOptionObject() {
  -		assertEquals("present value",cmd.getValue(present,"default value"));
  -		assertEquals("default value",cmd.getValue(missing,"default value"));
  -		try{
  -			cmd.getValue(multiple);
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(String)
  -	 */
  -	public final void testGetSwitchString() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch("--present"));
  -		assertNull(cmd.getSwitch("--missing"));
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(String, Boolean)
  -	 */
  -	public final void testGetSwitchStringBoolean() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch("--present",Boolean.FALSE));
  -		assertEquals(Boolean.FALSE,cmd.getSwitch("--missing",Boolean.FALSE));
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(Option)
  -	 */
  -	public final void testGetSwitchOption() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch(present));
  -		assertNull(cmd.getSwitch(missing));
  -	}
  -	public final void testGetProperty() {
  -		assertEquals("present property",cmd.getProperty("present"));
  -		assertNull(cmd.getProperty("missing"));
  -	}
  -	/*
  -	 * Class to test for int getOptionCount(String)
  -	 */
  -	public final void testGetOptionCountString() {
  -		// one option, one switch
  -		assertEquals(2,cmd.getOptionCount("--present"));
  -		assertEquals(0,cmd.getOptionCount("--missing"));
  -	}
  -	/*
  -	 * Class to test for int getOptionCount(Option)
  -	 */
  -	public final void testGetOptionCountOption() {
  -		// one option, one switch
  -		assertEquals(2,cmd.getOptionCount(present));
  -		assertEquals(0,cmd.getOptionCount(missing));
  -	}
   }
  
  
  
  No                   revision
  
  Index: CommandLineImplTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli2/commandline/Attic/CommandLineImplTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- CommandLineImplTest.java	22 Feb 2004 13:13:32 -0000	1.1.2.1
  +++ CommandLineImplTest.java	25 Feb 2004 00:01:14 -0000	1.1.2.2
  @@ -28,155 +28,7 @@
   
   public class CommandLineImplTest extends CLITestCase {
   	
  -	final Option present = new DefaultOptionBuilder().withLongName("present").create();
  -	final Option missing = new DefaultOptionBuilder().withLongName("missing").create();
  -	final Option multiple = new DefaultOptionBuilder().withLongName("multiple").create();
  +	private CommandLine commandLine;
   	
  -	private CommandLine cmd;
   	
  -	/*
  -	 * @see TestCase#setUp()
  -	 */
  -	protected void setUp() throws Exception {
  -		final Option root = new GroupBuilder().create();
  -		
  -		final WriteableCommandLine writeable = new WriteableCommandLineImpl(root,new ArrayList());
  -		writeable.addOption(present);
  -		writeable.addProperty("present","present property");
  -		writeable.addSwitch(present,true);
  -		writeable.addValue(present,"present value");
  -		writeable.addOption(multiple);
  -		writeable.addValue(multiple,"value 1");
  -		writeable.addValue(multiple,"value 2");
  -		writeable.addValue(multiple,"value 3");
  -		
  -		cmd = writeable;
  -	}
  -	
  -	public final void testHasOption() {
  -		assertTrue(cmd.hasOption(present));
  -		assertFalse(cmd.hasOption(missing));
  -	}
  -	
  -	/*
  -	 * Class to test for List getValues(String)
  -	 */
  -	public final void testGetValuesString() {
  -		assertListContentsEqual(list("present value"),cmd.getValues("--present"));
  -		assertTrue(cmd.getValues("--missing").isEmpty());
  -	}
  -	
  -	/*
  -	 * Class to test for List getValues(String, List)
  -	 */
  -	public final void testGetValuesStringList() {
  -		assertListContentsEqual(list("present value"),cmd.getValues("--present",null));
  -		assertTrue(cmd.getValues("--missing",null).isEmpty());
  -		final List def = Collections.singletonList("default value");
  -		assertSame(def,cmd.getValues("--missing",def));
  -	}
  -	/*
  -	 * Class to test for List getValues(Option)
  -	 */
  -	public final void testGetValuesOption() {
  -		assertListContentsEqual(list("present value"),cmd.getValues(present));
  -		assertTrue(cmd.getValues(missing).isEmpty());
  -	}
  -	/*
  -	 * Class to test for Object getValue(String)
  -	 */
  -	public final void testGetValueString() {
  -		assertEquals("present value",cmd.getValue("--present"));
  -		assertNull(cmd.getValue("--missing"));
  -		try{
  -			cmd.getValue("--multiple");
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(String, Object)
  -	 */
  -	public final void testGetValueStringObject() {
  -		assertEquals("present value",cmd.getValue("--present","default value"));
  -		assertEquals("default value",cmd.getValue("--missing","default value"));
  -		try{
  -			cmd.getValue("--multiple");
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(Option)
  -	 */
  -	public final void testGetValueOption() {
  -		assertEquals("present value",cmd.getValue(present));
  -		assertNull(cmd.getValue(missing));
  -		try{
  -			cmd.getValue(multiple);
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Object getValue(Option, Object)
  -	 */
  -	public final void testGetValueOptionObject() {
  -		assertEquals("present value",cmd.getValue(present,"default value"));
  -		assertEquals("default value",cmd.getValue(missing,"default value"));
  -		try{
  -			cmd.getValue(multiple);
  -			fail("expected IllegalStateException");
  -		}
  -		catch(IllegalStateException e){
  -			assertEquals("More than one value was supplied",e.getMessage());
  -		}
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(String)
  -	 */
  -	public final void testGetSwitchString() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch("--present"));
  -		assertNull(cmd.getSwitch("--missing"));
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(String, Boolean)
  -	 */
  -	public final void testGetSwitchStringBoolean() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch("--present",Boolean.FALSE));
  -		assertEquals(Boolean.FALSE,cmd.getSwitch("--missing",Boolean.FALSE));
  -	}
  -	/*
  -	 * Class to test for Boolean getSwitch(Option)
  -	 */
  -	public final void testGetSwitchOption() {
  -		assertEquals(Boolean.TRUE,cmd.getSwitch(present));
  -		assertNull(cmd.getSwitch(missing));
  -	}
  -	public final void testGetProperty() {
  -		assertEquals("present property",cmd.getProperty("present"));
  -		assertNull(cmd.getProperty("missing"));
  -	}
  -	/*
  -	 * Class to test for int getOptionCount(String)
  -	 */
  -	public final void testGetOptionCountString() {
  -		// one option, one switch
  -		assertEquals(2,cmd.getOptionCount("--present"));
  -		assertEquals(0,cmd.getOptionCount("--missing"));
  -	}
  -	/*
  -	 * Class to test for int getOptionCount(Option)
  -	 */
  -	public final void testGetOptionCountOption() {
  -		// one option, one switch
  -		assertEquals(2,cmd.getOptionCount(present));
  -		assertEquals(0,cmd.getOptionCount(missing));
  -	}
   }
  
  
  
  1.1.2.1   +132 -0    jakarta-commons/cli/src/test/org/apache/commons/cli2/commandline/Attic/DefaultingCommandLineTest.java
  
  
  
  
  No                   revision
  No                   revision
  1.1.2.2   +16 -2     jakarta-commons/cli/src/java/org/apache/commons/cli2/commandline/Attic/DefaultingCommandLine.java
  
  Index: DefaultingCommandLine.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/commandline/Attic/DefaultingCommandLine.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- DefaultingCommandLine.java	18 Feb 2004 00:30:57 -0000	1.1.2.1
  +++ DefaultingCommandLine.java	25 Feb 2004 00:01:14 -0000	1.1.2.2
  @@ -68,6 +68,15 @@
           final CommandLine commandLine) {
           commandLines.add(index, commandLine);
       }
  +    
  +    /**
  +     * Builds an iterator over the build in CommandLines.
  +     * 
  +     * @return an unmodifiable iterator
  +     */
  +    public Iterator commandLines(){
  +    	return Collections.unmodifiableList(commandLines).iterator();
  +    }
   
       /*
        * (non-Javadoc)
  @@ -145,11 +154,16 @@
           for (final Iterator i = commandLines.iterator(); i.hasNext();) {
               final CommandLine commandLine = (CommandLine)i.next();
               final List actual = commandLine.getValues(option);
  -            if (actual != null) {
  +            if (actual != null && !actual.isEmpty()) {
                   return actual;
               }
           }
  -        return defaultValues;
  +        if(defaultValues==null){
  +        	return Collections.EMPTY_LIST;
  +        }
  +        else{
  +        	return defaultValues;
  +        }
       }
   
       /*
  
  
  

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