下面列出了org.apache.commons.cli.Options#getOption ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testDeduceFromMameRuntimeWithBooleanOption ()
throws FileNotFoundException,
IOException,
InterruptedException,
MameExecutionException {
FakeMameRuntime mame = new FakeMameRuntime();
List<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(
new FileInputStream("src/test/resources/showconfig.txt"));
inputStreams.add(
new FileInputStream("src/test/resources/showusage.txt"));
mame.setInputStreamsToReturn(inputStreams);
CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();
assertTrue(mameOpts.hasOption("waitvsync"));
Option opt = mameOpts.getOption("waitvsync");
assertFalse(opt.hasArg());
}
@Test
public void testDeduceFromMameRuntimeWithNegativeBooleanOption ()
throws FileNotFoundException,
IOException,
InterruptedException,
MameExecutionException {
FakeMameRuntime mame = new FakeMameRuntime();
List<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(
new FileInputStream("src/test/resources/showconfig.txt"));
inputStreams.add(
new FileInputStream("src/test/resources/showusage.txt"));
mame.setInputStreamsToReturn(inputStreams);
CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();
assertTrue(mameOpts.hasOption("nowaitvsync"));
Option opt = mameOpts.getOption("nowaitvsync");
assertFalse(opt.hasArg());
}
@Test
public void testDeduceFromMameRuntimeWithNonBooleanOption ()
throws FileNotFoundException,
IOException,
InterruptedException,
MameExecutionException {
FakeMameRuntime mame = new FakeMameRuntime();
List<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(
new FileInputStream("src/test/resources/showconfig.txt"));
inputStreams.add(
new FileInputStream("src/test/resources/showusage.txt"));
mame.setInputStreamsToReturn(inputStreams);
CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();
assertTrue(mameOpts.hasOption("rompath"));
assertFalse(mameOpts.hasOption("norompath"));
Option opt = mameOpts.getOption("rompath");
assertTrue(opt.hasArg());
}
@Test
public void testDeduceFromMameRuntimeWithNonBooleanOptionHavingDefaultValueLikeBoolean ()
throws FileNotFoundException,
IOException,
InterruptedException,
MameExecutionException {
FakeMameRuntime mame = new FakeMameRuntime();
List<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(
new FileInputStream("src/test/resources/showconfig.txt"));
inputStreams.add(
new FileInputStream("src/test/resources/showusage.txt"));
mame.setInputStreamsToReturn(inputStreams);
CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
Options mameOpts = clof.deduceFromMameRuntime(mame).getOptions();
assertTrue(mameOpts.hasOption("prescale"));
assertFalse(mameOpts.hasOption("noprescale"));
Option opt = mameOpts.getOption("prescale");
assertTrue(opt.hasArg());
}
@Test
public void testDeduceFromMameRuntimeWithCommandOption ()
throws FileNotFoundException,
IOException,
InterruptedException,
MameExecutionException {
FakeMameRuntime mame = new FakeMameRuntime();
List<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(
new FileInputStream("src/test/resources/showconfig.txt"));
inputStreams.add(
new FileInputStream("src/test/resources/showusage.txt"));
mame.setInputStreamsToReturn(inputStreams);
CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
Options commands
= clof.deduceFromMameRuntime(mame).getCommands();
assertTrue(commands.hasOption("help"));
Option command = commands.getOption("help");
assertFalse(command.hasArg());
}
@Test
public void testDeduceFromMameRuntimeWithMediaTypeOption ()
throws FileNotFoundException,
IOException,
InterruptedException,
MameExecutionException {
FakeMameRuntime mame = new FakeMameRuntime();
List<InputStream> inputStreams = new ArrayList<>();
inputStreams.add(
new FileInputStream("src/test/resources/showconfig.txt"));
inputStreams.add(
new FileInputStream("src/test/resources/showusage.txt"));
mame.setInputStreamsToReturn(inputStreams);
CommandLineOptionsFactory clof = new CommandLineOptionsFactory ();
Options mediaTypes
= clof.deduceFromMameRuntime(mame).getMediaTypes();
assertTrue(mediaTypes.hasOption("cart"));
Option opt = mediaTypes.getOption("cart");
assertTrue(opt.hasArg());
}
protected void assertOption(Options options, String optionName, boolean isRequired, boolean hasArgument) {
Option option = options.getOption(optionName);
assertNotNull(option);
assertEquals(isRequired, option.isRequired());
assertEquals(hasArgument, option.hasArg());
}