private void assertOptionWithRequiredArgumentThrowsExceptionWithoutArgument( String shortOption, String longOption) { // @formatter:off assertAll( () -> assertThrows(Exception.class, () -> parseArgLine(shortOption)), () -> assertThrows(Exception.class, () -> parseArgLine(longOption))); // @formatter:on }
@Test public void parseExtraArguments() { // @formatter:off assertAll( () -> assertEquals(asList("foo"), parseArgLine("foo").getArguments()), () -> assertEquals(asList("foo", "bar"), parseArgLine("-h foo bar").getArguments()), () -> assertEquals(asList("foo", "bar"), parseArgLine("-h -- foo bar").getArguments())); // @formatter:on }
@Test public void parseValidTagFilters() { // @formatter:off assertAll( () -> assertEquals(asList("fast"), parseArgLine("-t fast").getTagsFilter()), () -> assertEquals(asList("fast"), parseArgLine("--filter-tags fast").getTagsFilter()), () -> assertEquals(asList("fast"), parseArgLine("--filter-tags=fast").getTagsFilter()), () -> assertEquals(asList("fast", "slow"), parseArgLine("-t fast -t slow").getTagsFilter())); // @formatter:on }
@Test public void parseValidClassnameFilters() { // @formatter:off assertAll( () -> assertEquals(Optional.of(".*Test"), parseArgLine("-n .*Test").getClassnameFilter()), () -> assertEquals( Optional.of(".*Test"), parseArgLine("--filter-classname .*Test").getClassnameFilter()), () -> assertEquals( Optional.of(".*Test"), parseArgLine("--filter-classname=.*Test").getClassnameFilter())); // @formatter:on }
@Test public void parseNoArguments() { String[] noArguments = {}; CommandLineOptions options = createParser().parse(noArguments); // @formatter:off assertAll( () -> assertFalse(options.isAnsiColorOutputDisabled()), () -> assertFalse(options.isDisplayHelp()), () -> assertFalse(options.isExitCodeEnabled()), () -> assertFalse(options.isHideDetails()), () -> assertFalse(options.isRunAllTests()), () -> assertEquals(Optional.empty(), options.getClassnameFilter()), () -> assertEquals(emptyList(), options.getTagsFilter()), () -> assertEquals(emptyList(), options.getAdditionalClasspathEntries()), () -> assertEquals(emptyList(), options.getArguments())); // @formatter:on }
@Test public void parseSwitches() { // @formatter:off assertAll( () -> assertParses( "disable ansi", CommandLineOptions::isAnsiColorOutputDisabled, "-C", "--disable-ansi-colors"), () -> assertParses("help", CommandLineOptions::isDisplayHelp, "-h", "--help"), () -> assertParses( "exit code", CommandLineOptions::isExitCodeEnabled, "-x", "--enable-exit-code"), () -> assertParses("hide details", CommandLineOptions::isHideDetails, "-D", "--hide-details"), () -> assertParses("run all tests", CommandLineOptions::isRunAllTests, "-a", "--all")); // @formatter:on }
@Test public void parseValidAdditionalClasspathEntries() { // @formatter:off assertAll( () -> assertEquals(asList("."), parseArgLine("-p .").getAdditionalClasspathEntries()), () -> assertEquals( asList("."), parseArgLine("--classpath .").getAdditionalClasspathEntries()), () -> assertEquals( asList("."), parseArgLine("--classpath=.").getAdditionalClasspathEntries()), () -> assertEquals( asList(".", "lib/some.jar"), parseArgLine("-p . -p lib/some.jar").getAdditionalClasspathEntries()), () -> assertEquals( asList("." + File.pathSeparator + "lib/some.jar"), parseArgLine("-p ." + File.pathSeparator + "lib/some.jar") .getAdditionalClasspathEntries())); // @formatter:on }