|
| 1 | +/** |
| 2 | + * Copyright 2004 The Apache Software Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.apache.commons.cli2.bug; |
| 17 | + |
| 18 | +import junit.framework.TestCase; |
| 19 | + |
| 20 | +import org.apache.commons.cli2.Argument; |
| 21 | +import org.apache.commons.cli2.CommandLine; |
| 22 | +import org.apache.commons.cli2.Group; |
| 23 | +import org.apache.commons.cli2.Option; |
| 24 | +import org.apache.commons.cli2.builder.ArgumentBuilder; |
| 25 | +import org.apache.commons.cli2.builder.GroupBuilder; |
| 26 | +import org.apache.commons.cli2.commandline.Parser; |
| 27 | +import org.apache.commons.cli2.option.PropertyOption; |
| 28 | + |
| 29 | +/** |
| 30 | + * http://issues.apache.org/jira/browse/CLI-12 |
| 31 | + */ |
| 32 | +public class BugCLI12Test extends TestCase { |
| 33 | + |
| 34 | + public void testBug() { |
| 35 | + Argument arg = new ArgumentBuilder().withName("file").create(); |
| 36 | + |
| 37 | + Option option = new PropertyOption(); |
| 38 | + |
| 39 | + Group group = new GroupBuilder().withOption(option).withOption(arg).create(); |
| 40 | + |
| 41 | + Parser p = new Parser(); |
| 42 | + p.setGroup(group); |
| 43 | + |
| 44 | + CommandLine cl = p.parseAndHelp( new String[] { "-Dmyprop1=myval1", "-Dmyprop2=myval2", "myfile" } ); |
| 45 | + if(cl == null) { |
| 46 | + assertTrue("Couldn't parse valid commandLine", false); |
| 47 | + } |
| 48 | + |
| 49 | + assertEquals( "myval1", cl.getProperty("myprop1")); |
| 50 | + assertEquals( "myval2", cl.getProperty("myprop2")); |
| 51 | + |
| 52 | + String extraArgs = (String) cl.getValue(arg); |
| 53 | + assertEquals( "myfile", extraArgs); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments