/** * Create a new {@code SimpleCommandLinePropertySource} having the given name * and backed by the given {@code String[]} of command line arguments. */ public SimpleCommandLinePropertySource(String name, String[] args) { super(name, new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the default name * and backed by the given {@code String[]} of command line arguments. * @see CommandLinePropertySource#COMMAND_LINE_PROPERTY_SOURCE_NAME * @see CommandLinePropertySource#CommandLinePropertySource(Object) */ public SimpleCommandLinePropertySource(String... args) { super(new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the given name * and backed by the given {@code String[]} of command line arguments. */ public SimpleCommandLinePropertySource(String name, String[] args) { super(name, new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the default name * and backed by the given {@code String[]} of command line arguments. * @see CommandLinePropertySource#COMMAND_LINE_PROPERTY_SOURCE_NAME * @see CommandLinePropertySource#CommandLinePropertySource(Object) */ public SimpleCommandLinePropertySource(String... args) { super(new SimpleCommandLineArgsParser().parse(args)); }
@Test(expected = IllegalArgumentException.class) public void withEmptyOptionNameAndEmptyOptionValue() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); parser.parse("--="); }
@Test(expected = IllegalArgumentException.class) public void withEmptyOptionText() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); parser.parse("--"); }
@Test(expected = IllegalArgumentException.class) public void withEmptyOptionName() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); parser.parse("--=v1"); }
@Test(expected = IllegalArgumentException.class) public void withEmptyOptionValue() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); parser.parse("--o1="); }
@Test(expected = UnsupportedOperationException.class) public void assertOptionNamesIsUnmodifiable() { CommandLineArgs args = new SimpleCommandLineArgsParser().parse(); args.getOptionNames().add("bogus"); }
@Test(expected = UnsupportedOperationException.class) public void assertNonOptionArgsIsUnmodifiable() { CommandLineArgs args = new SimpleCommandLineArgsParser().parse(); args.getNonOptionArgs().add("foo"); }
@Test public void withNonOptionArguments() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); CommandLineArgs args = parser.parse("--o1=v1", "noa1", "--o2=v2", "noa2"); assertThat(args.getOptionValues("o1").get(0), equalTo("v1")); assertThat(args.getOptionValues("o2").get(0), equalTo("v2")); List<String> nonOptions = args.getNonOptionArgs(); assertThat(nonOptions.get(0), equalTo("noa1")); assertThat(nonOptions.get(1), equalTo("noa2")); assertThat(nonOptions.size(), equalTo(2)); }
@Test public void withNoOptions() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); assertThat(parser.parse().getOptionValues("foo"), nullValue()); }
@Test public void withSingleOptionAndValue() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); CommandLineArgs args = parser.parse("--o1=v1"); assertThat(args.containsOption("o1"), is(true)); assertThat(args.getOptionValues("o1").get(0), equalTo("v1")); }
@Test public void withSingleOptionAndNoValue() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); CommandLineArgs args = parser.parse("--o1"); assertThat(args.containsOption("o1"), is(true)); assertThat(args.getOptionValues("o1"), equalTo(Collections.EMPTY_LIST)); }
@Test public void withMixOfOptionsHavingValueAndOptionsHavingNoValue() { SimpleCommandLineArgsParser parser = new SimpleCommandLineArgsParser(); CommandLineArgs args = parser.parse("--o1=v1", "--o2"); assertThat(args.containsOption("o1"), is(true)); assertThat(args.containsOption("o2"), is(true)); assertThat(args.containsOption("o3"), is(false)); assertThat(args.getOptionValues("o1").get(0), equalTo("v1")); assertThat(args.getOptionValues("o2"), equalTo(Collections.EMPTY_LIST)); assertThat(args.getOptionValues("o3"), nullValue()); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the default name * and backed by the given {@code String[]} of command line arguments. * @see CommandLinePropertySource#COMMAND_LINE_PROPERTY_SOURCE_NAME * @see CommandLinePropertySource#CommandLinePropertySource(Object) */ public SimpleCommandLinePropertySource(String... args) { super(new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the given name * and backed by the given {@code String[]} of command line arguments. */ public SimpleCommandLinePropertySource(String name, String[] args) { super(name, new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the default name * and backed by the given {@code String[]} of command line arguments. * @see CommandLinePropertySource#COMMAND_LINE_PROPERTY_SOURCE_NAME * @see CommandLinePropertySource#CommandLinePropertySource(Object) */ public SimpleCommandLinePropertySource(String... args) { super(new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the given name * and backed by the given {@code String[]} of command line arguments. */ public SimpleCommandLinePropertySource(String name, String[] args) { super(name, new SimpleCommandLineArgsParser().parse(args)); }
/** * Create a new {@code SimpleCommandLinePropertySource} having the given name * and backed by the given {@code String[]} of command line arguments. */ public SimpleCommandLinePropertySource(String name, String[] args) { super(name, new SimpleCommandLineArgsParser().parse(args)); }