-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #1767 - NPE on OptionSpec.getValue()
- Loading branch information
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package picocli; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static picocli.CommandLine.ScopeType.INHERIT; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import org.junit.Test; | ||
|
||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.IFactory; | ||
import picocli.CommandLine.Model.CommandSpec; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Spec; | ||
|
||
public class Issue1767 { | ||
@Command(name = "test") | ||
static class TestCommand implements Callable<Integer> { | ||
@ArgGroup TestArgGroup testArgGroup; | ||
@Spec CommandSpec spec; | ||
|
||
public static class TestArgGroup { | ||
@Option(names = "-r") | ||
public Integer option1; | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
Integer value = spec.options().get(0).getValue(); | ||
return value==null ? 0 : value; | ||
} | ||
} | ||
|
||
@Test | ||
public void testIssue1772() { | ||
assertEquals(5, new CommandLine(new TestCommand()).execute("-r", "5")); | ||
assertEquals(0, new CommandLine(new TestCommand()).execute()); | ||
} | ||
} |