use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withDefaultNonOptionArgsNameAndNonOptionArgsPresent.
@Test
public void withDefaultNonOptionArgsNameAndNonOptionArgsPresent() {
OptionParser parser = new OptionParser();
parser.accepts("o1").withRequiredArg();
parser.accepts("o2");
OptionSet optionSet = parser.parse("--o1=v1", "noa1", "--o2", "noa2");
PropertySource<?> ps = new JOptCommandLinePropertySource(optionSet);
assertThat(ps.containsProperty("nonOptionArgs"), is(true));
assertThat(ps.containsProperty("o1"), is(true));
assertThat(ps.containsProperty("o2"), is(true));
String nonOptionArgs = (String) ps.getProperty("nonOptionArgs");
assertThat(nonOptionArgs, equalTo("noa1,noa2"));
}
use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withRequiredArg_andMultipleArgsPresent_usingDelimiter.
@Test
public void withRequiredArg_andMultipleArgsPresent_usingDelimiter() {
OptionParser parser = new OptionParser();
parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(',');
OptionSet options = parser.parse("--foo=bar,baz,biz");
CommandLinePropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertEquals(Arrays.asList("bar", "baz", "biz"), ps.getOptionValues("foo"));
assertThat(ps.getProperty("foo"), equalTo("bar,baz,biz"));
}
use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withRequiredArg_ofTypeEnum.
@Test
public void withRequiredArg_ofTypeEnum() {
OptionParser parser = new OptionParser();
parser.accepts("o1").withRequiredArg().ofType(OptionEnum.class);
OptionSet options = parser.parse("--o1=VAL_1");
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertThat(ps.getProperty("o1"), equalTo("VAL_1"));
}
use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withMissingOption.
@Test
public void withMissingOption() {
OptionParser parser = new OptionParser();
parser.accepts("foo").withRequiredArg().withValuesSeparatedBy(',');
// <-- no options whatsoever
OptionSet options = parser.parse();
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
assertThat(ps.getProperty("foo"), nullValue());
}
use of joptsimple.OptionParser in project spring-framework by spring-projects.
the class JOptCommandLinePropertySourceTests method withDefaultNonOptionArgsNameAndNoNonOptionArgsPresent.
@Test
public void withDefaultNonOptionArgsNameAndNoNonOptionArgsPresent() {
OptionParser parser = new OptionParser();
parser.acceptsAll(Arrays.asList("o1", "option1")).withRequiredArg();
parser.accepts("o2");
OptionSet optionSet = parser.parse("--o1=v1", "--o2");
EnumerablePropertySource<?> ps = new JOptCommandLinePropertySource(optionSet);
assertThat(ps.containsProperty("nonOptionArgs"), is(false));
assertThat(ps.containsProperty("o1"), is(true));
assertThat(ps.containsProperty("o2"), is(true));
assertThat(ps.containsProperty("nonOptionArgs"), is(false));
assertThat(ps.getProperty("nonOptionArgs"), nullValue());
assertThat(ps.getPropertyNames().length, is(2));
}
Aggregations