/** * Set the line to split into several commandline arguments. * * @param line line to split into several commandline arguments. */ public void setLine(String line) { if (line == null) { return; } parts = translateCommandline(line); }
/** * Create a command line from a string. * @param toProcess the line: the first element becomes the executable, the rest * the arguments. */ public Commandline(String toProcess) { super(); String[] tmp = translateCommandline(toProcess); if (tmp != null && tmp.length > 0) { setExecutable(tmp[0]); for (int i = 1; i < tmp.length; i++) { createArgument().setValue(tmp[i]); } } }
@Test(expected = ParseException.class) public void sinceDate_unsupportedFormats_throwsParseException() throws ParseException { String sinceDate = "01 July 17"; String input = DEFAULT_MANDATORY_ARGS + String.format("-since %s", sinceDate); ArgsParser.parse(translateCommandline(input)); }
@Test(expected = ParseException.class) public void parse_extraArgumentForIgnore_throwsParseException() throws ParseException { String input = String.format("-config %s --ignore-standalone-config true", CONFIG_FOLDER_ABSOLUTE); ArgsParser.parse(translateCommandline(input)); } }
@Test(expected = ParseException.class) public void sinceDate_laterThanUntilDate_throwsParseException() throws ParseException { String sinceDate = "01/12/2017"; String untilDate = "30/11/2017"; String input = DEFAULT_MANDATORY_ARGS + String.format("-since %s -until %s", sinceDate, untilDate); ArgsParser.parse(translateCommandline(input)); }
@Test(expected = ParseException.class) public void formats_notInAlphanumeric_throwsParseException() throws ParseException { String formats = ".java"; String input = DEFAULT_MANDATORY_ARGS + String.format("-formats %s", formats); ArgsParser.parse(translateCommandline(input)); }
@Test(expected = ParseException.class) public void parse_mutuallyExclusiveArgumentsConfigAndReposTogether_throwsParseException() throws ParseException { String input = String.format("-config %s -repos %s", CONFIG_FOLDER_ABSOLUTE, TEST_REPO_REPOSENSE); ArgsParser.parse(translateCommandline(input)); }
@Test public void parse_repoAliases_sameResult() throws ParseException, IOException { String input = String.format("-repos %s", TEST_REPO_BETA); CliArguments repoAliasCliArguments = ArgsParser.parse(translateCommandline(input)); input = String.format("-repo %s", TEST_REPO_BETA); CliArguments reposAliasCliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertEquals(repoAliasCliArguments, reposAliasCliArguments); }
@Test(expected = ParseException.class) public void untilDate_unsupportedFormats_throwsParseException() throws ParseException { String untilDate = "11/31/2017"; String input = DEFAULT_MANDATORY_ARGS + String.format("-until %s", untilDate); ArgsParser.parse(translateCommandline(input)); }
@Test(expected = ParseException.class) public void parse_missingConfigValue_throwsParseException() throws ParseException { String input = "-config"; ArgsParser.parse(translateCommandline(input)); }
@Test public void parse_repoLocationsAndViewWithArgCwd_returnsViewCliArguments() throws ParseException { String input = String.format("-repos \"%s\" %s -view .", TEST_REPO_REPOSENSE, TEST_REPO_DELTA); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ViewCliArguments); }
@Test public void outputPath_nonExistentDirectory_success() throws ParseException, IOException { String nonExistentDirectory = PROJECT_DIRECTORY.resolve("some_non_existent_dir/").toString(); Path expectedRelativeOutputDirectoryPath = Paths.get(nonExistentDirectory) .resolve(ArgsParser.DEFAULT_REPORT_NAME); String input = DEFAULT_MANDATORY_ARGS + String.format("-output %s", nonExistentDirectory); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ConfigCliArguments); Assert.assertTrue(Files.isSameFile( expectedRelativeOutputDirectoryPath, cliArguments.getOutputFilePath())); }
@Test public void parse_validGitRepoLocations_repoConfigurationListCorrectSize() throws ParseException, IOException { String input = String.format("-repos \"%s\" %s", TEST_REPO_REPOSENSE, TEST_REPO_DELTA); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof LocationsCliArguments); List<RepoConfiguration> repoConfigs = RepoSense.getRepoConfigurations((LocationsCliArguments) cliArguments); Assert.assertEquals(2, repoConfigs.size()); }
@Test public void formats_inAlphanumeric_success() throws ParseException { String formats = "java js css 7z"; String input = DEFAULT_MANDATORY_ARGS + String.format("-formats %s", formats); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ConfigCliArguments); List<Format> expectedFormats = Format.convertStringsToFormats(Arrays.asList("java", "js", "css", "7z")); Assert.assertEquals(expectedFormats, cliArguments.getFormats()); }
@Test public void parse_withoutIgnore_success() throws ParseException { String input = String.format("-repos \"%s\" %s", TEST_REPO_REPOSENSE, TEST_REPO_DELTA); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof LocationsCliArguments); Assert.assertFalse(((LocationsCliArguments) cliArguments).isStandaloneConfigIgnored()); }
@Test public void parse_repoLocationsOnly_success() throws ParseException { String input = String.format("-repos \"%s\" %s", TEST_REPO_REPOSENSE, TEST_REPO_DELTA); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof LocationsCliArguments); Assert.assertFalse(cliArguments.isAutomaticallyLaunching()); List<String> expectedLocations = Arrays.asList(TEST_REPO_REPOSENSE, TEST_REPO_DELTA); Assert.assertEquals(expectedLocations, ((LocationsCliArguments) cliArguments).getLocations()); }
@Test public void parse_viewOnlyWithoutArgs_returnsConfigCliArguments() throws ParseException { String input = "-view"; CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ConfigCliArguments); Assert.assertEquals(PROJECT_DIRECTORY.toString(), ( (ConfigCliArguments) cliArguments).getConfigFolderPath().toString()); Assert.assertTrue(cliArguments.isAutomaticallyLaunching()); }
@Test public void parse_viewOnly_success() throws ParseException, IOException { String input = String.format("-view %s", OUTPUT_DIRECTORY_ABSOLUTE); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ViewCliArguments); Assert.assertTrue(Files.isSameFile( OUTPUT_DIRECTORY_ABSOLUTE, ((ViewCliArguments) cliArguments).getReportDirectoryPath())); }
@Test public void parse_repoLocationsAndViewWithArgs_returnsViewCliArguments() throws ParseException, IOException { String input = String.format("-repos \"%s\" %s -view %s", TEST_REPO_REPOSENSE, TEST_REPO_DELTA, OUTPUT_DIRECTORY_ABSOLUTE); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ViewCliArguments); Assert.assertTrue(Files.isSameFile( OUTPUT_DIRECTORY_ABSOLUTE, ((ViewCliArguments) cliArguments).getReportDirectoryPath())); }
@Test public void parse_configFolderAndViewWithArgs_returnsViewCliArguments() throws ParseException, IOException { String input = String.format("-config %s -view %s", CONFIG_FOLDER_ABSOLUTE, OUTPUT_DIRECTORY_ABSOLUTE); CliArguments cliArguments = ArgsParser.parse(translateCommandline(input)); Assert.assertTrue(cliArguments instanceof ViewCliArguments); Assert.assertTrue(Files.isSameFile( OUTPUT_DIRECTORY_ABSOLUTE, ((ViewCliArguments) cliArguments).getReportDirectoryPath())); }