From c67bcf29da2398e3a826860ccf869c339dd3b917 Mon Sep 17 00:00:00 2001 From: nseah21 Date: Sun, 11 Jun 2023 15:37:21 +0800 Subject: [PATCH 1/8] Remove date validation methods from TimeUtil --- src/main/java/reposense/util/TimeUtil.java | 29 ---------------------- 1 file changed, 29 deletions(-) diff --git a/src/main/java/reposense/util/TimeUtil.java b/src/main/java/reposense/util/TimeUtil.java index 96a71b7e17..83de42414c 100644 --- a/src/main/java/reposense/util/TimeUtil.java +++ b/src/main/java/reposense/util/TimeUtil.java @@ -9,7 +9,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import reposense.parser.ParseException; import reposense.parser.SinceDateArgumentType; import reposense.system.LogsManager; @@ -23,10 +22,6 @@ public class TimeUtil { // "uuuu" is used for year since "yyyy" does not work with ResolverStyle.STRICT private static final DateTimeFormatter CLI_ARGS_DATE_FORMAT = DateTimeFormatter.ofPattern("d/M/uuuu HH:mm:ss"); - private static final String MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE = - "\"Since Date\" cannot be later than \"Until Date\"."; - private static final String MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE = - "\"Since Date\" must not be later than today's date."; private static final String EARLIEST_VALID_DATE = "1970-01-01T00:00:00"; private static final String LATEST_VALID_DATE = "2099-12-31T23:59:59"; @@ -168,30 +163,6 @@ public static boolean isEqualToArbitraryFirstDateConverted(LocalDateTime dateTim return dateTime.equals(getArbitraryFirstCommitDateConverted(zoneId)); } - /** - * Verifies that {@code sinceDate} is earlier than {@code untilDate}. - * - * @throws ParseException if {@code sinceDate} supplied is later than {@code untilDate}. - */ - public static void verifyDatesRangeIsCorrect(LocalDateTime sinceDate, LocalDateTime untilDate) - throws ParseException { - if (sinceDate.compareTo(untilDate) > 0) { - throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE); - } - } - - /** - * Verifies that {@code sinceDate} is no later than the date of report generation, given by {@code currentDate}. - * - * @throws ParseException if {@code sinceDate} supplied is later than date of report generation. - */ - public static void verifySinceDateIsValid(LocalDateTime sinceDate, LocalDateTime currentDate) - throws ParseException { - if (sinceDate.compareTo(currentDate) > 0) { - throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE); - } - } - /** * Extracts the first substring of {@code date} string that matches the {@code DATE_FORMAT_REGEX}. */ From 444a7c1f6bb60d385e68ece50a5b815cfbeb3de4 Mon Sep 17 00:00:00 2001 From: nseah21 Date: Sun, 11 Jun 2023 15:53:57 +0800 Subject: [PATCH 2/8] Add date validation checks to ArgsParser --- src/main/java/reposense/parser/ArgsParser.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 68e27c9c57..44bef7dea9 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -80,6 +80,10 @@ public class ArgsParser { private static final String MESSAGE_INVALID_CONFIG_JSON = "%s Ignoring the report config provided."; private static final String MESSAGE_SINCE_D1_WITH_PERIOD = "You may be using --since d1 with the --period flag. " + "This may result in an incorrect date range being analysed."; + private static final String MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE = + "\"Since Date\" cannot be later than \"Until Date\"."; + private static final String MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE = + "\"Since Date\" must not be later than today's date."; private static final Path EMPTY_PATH = Paths.get(""); private static final Path DEFAULT_CONFIG_PATH = Paths.get(System.getProperty("user.dir") + File.separator + "config" + File.separator); @@ -420,8 +424,13 @@ private static void addAnalysisDatesToBuilder(CliArguments.Builder builder, Name ? untilDate : currentDate; - TimeUtil.verifySinceDateIsValid(sinceDate, currentDate); - TimeUtil.verifyDatesRangeIsCorrect(sinceDate, untilDate); + if (sinceDate.compareTo(untilDate) > 0) { + throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE); + } + + if (sinceDate.compareTo(currentDate) > 0) { + throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE); + } builder.sinceDate(sinceDate) .isSinceDateProvided(isSinceDateProvided) From 0843d872ec91701b1ce41dd1fd4cbd201ea9ead1 Mon Sep 17 00:00:00 2001 From: nseah21 Date: Mon, 12 Jun 2023 00:20:58 +0800 Subject: [PATCH 3/8] Reduce scope of try-catch block for parse method --- .../java/reposense/parser/ArgsParser.java | 129 +++++++++--------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 44bef7dea9..9130b8a329 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -262,76 +262,77 @@ private static ArgumentParser getArgumentParser() { * @throws ParseException if the given string arguments fails to parse to a {@link CliArguments} object. */ public static CliArguments parse(String[] args) throws HelpScreenException, ParseException { - try { - ArgumentParser parser = getArgumentParser(); - Namespace results = parser.parseArgs(args); - - Path configFolderPath = results.get(CONFIG_FLAGS[0]); - Path reportFolderPath = results.get(VIEW_FLAGS[0]); - Path outputFolderPath = results.get(OUTPUT_FLAGS[0]); - ZoneId zoneId = results.get(TIMEZONE_FLAGS[0]); - Path assetsFolderPath = results.get(ASSETS_FLAGS[0]); - List locations = results.get(REPO_FLAGS[0]); - List formats = FileType.convertFormatStringsToFileTypes(results.get(FORMAT_FLAGS[0])); - boolean isStandaloneConfigIgnored = results.get(IGNORE_CONFIG_FLAGS[0]); - boolean isFileSizeLimitIgnored = results.get(IGNORE_SIZELIMIT_FLAGS[0]); - boolean shouldIncludeLastModifiedDate = results.get(LAST_MODIFIED_DATE_FLAGS[0]); - boolean shouldPerformShallowCloning = results.get(SHALLOW_CLONING_FLAGS[0]); - boolean shouldFindPreviousAuthors = results.get(FIND_PREVIOUS_AUTHORS_FLAGS[0]); - boolean isTestMode = results.get(TEST_MODE_FLAG[0]); - int numCloningThreads = results.get(CLONING_THREADS_FLAG[0]); - int numAnalysisThreads = results.get(ANALYSIS_THREADS_FLAG[0]); - - CliArguments.Builder cliArgumentsBuilder = new CliArguments.Builder() - .configFolderPath(configFolderPath) - .reportDirectoryPath(reportFolderPath) - .outputFilePath(outputFolderPath) - .zoneId(zoneId) - .assetsFilePath(assetsFolderPath) - .locations(locations) - .formats(formats) - .isStandaloneConfigIgnored(isStandaloneConfigIgnored) - .isFileSizeLimitIgnored(isFileSizeLimitIgnored) - .isLastModifiedDateIncluded(shouldIncludeLastModifiedDate) - .isShallowCloningPerformed(shouldPerformShallowCloning) - .isFindingPreviousAuthorsPerformed(shouldFindPreviousAuthors) - .numCloningThreads(numCloningThreads) - .numAnalysisThreads(numAnalysisThreads) - .isTestMode(isTestMode); - - LogsManager.setLogFolderLocation(outputFolderPath); - - if (locations == null && configFolderPath.equals(DEFAULT_CONFIG_PATH)) { - logger.info(MESSAGE_USING_DEFAULT_CONFIG_PATH); - } - - addReportConfigToBuilder(cliArgumentsBuilder, results); - addAnalysisDatesToBuilder(cliArgumentsBuilder, results); - - boolean isViewModeOnly = reportFolderPath != null - && !reportFolderPath.equals(EMPTY_PATH) - && configFolderPath.equals(DEFAULT_CONFIG_PATH) - && locations == null; - cliArgumentsBuilder.isViewModeOnly(isViewModeOnly); - - boolean isAutomaticallyLaunching = reportFolderPath != null; - if (isAutomaticallyLaunching && !reportFolderPath.equals(EMPTY_PATH) && !isViewModeOnly) { - logger.info(String.format("Ignoring argument '%s' for --view.", reportFolderPath.toString())); - } - cliArgumentsBuilder.isAutomaticallyLaunching(isAutomaticallyLaunching); - - - boolean shouldPerformFreshCloning = isTestMode - ? results.get(FRESH_CLONING_FLAG[0]) - : DEFAULT_SHOULD_FRESH_CLONE; - cliArgumentsBuilder.isFreshClonePerformed(shouldPerformFreshCloning); + ArgumentParser parser = getArgumentParser(); + Namespace results; - return cliArgumentsBuilder.build(); + try { + results = parser.parseArgs(args); } catch (HelpScreenException hse) { throw hse; } catch (ArgumentParserException ape) { throw new ParseException(getArgumentParser().formatUsage() + ape.getMessage() + "\n"); } + + Path configFolderPath = results.get(CONFIG_FLAGS[0]); + Path reportFolderPath = results.get(VIEW_FLAGS[0]); + Path outputFolderPath = results.get(OUTPUT_FLAGS[0]); + ZoneId zoneId = results.get(TIMEZONE_FLAGS[0]); + Path assetsFolderPath = results.get(ASSETS_FLAGS[0]); + List locations = results.get(REPO_FLAGS[0]); + List formats = FileType.convertFormatStringsToFileTypes(results.get(FORMAT_FLAGS[0])); + boolean isStandaloneConfigIgnored = results.get(IGNORE_CONFIG_FLAGS[0]); + boolean isFileSizeLimitIgnored = results.get(IGNORE_SIZELIMIT_FLAGS[0]); + boolean shouldIncludeLastModifiedDate = results.get(LAST_MODIFIED_DATE_FLAGS[0]); + boolean shouldPerformShallowCloning = results.get(SHALLOW_CLONING_FLAGS[0]); + boolean shouldFindPreviousAuthors = results.get(FIND_PREVIOUS_AUTHORS_FLAGS[0]); + boolean isTestMode = results.get(TEST_MODE_FLAG[0]); + int numCloningThreads = results.get(CLONING_THREADS_FLAG[0]); + int numAnalysisThreads = results.get(ANALYSIS_THREADS_FLAG[0]); + + CliArguments.Builder cliArgumentsBuilder = new CliArguments.Builder() + .configFolderPath(configFolderPath) + .reportDirectoryPath(reportFolderPath) + .outputFilePath(outputFolderPath) + .zoneId(zoneId) + .assetsFilePath(assetsFolderPath) + .locations(locations) + .formats(formats) + .isStandaloneConfigIgnored(isStandaloneConfigIgnored) + .isFileSizeLimitIgnored(isFileSizeLimitIgnored) + .isLastModifiedDateIncluded(shouldIncludeLastModifiedDate) + .isShallowCloningPerformed(shouldPerformShallowCloning) + .isFindingPreviousAuthorsPerformed(shouldFindPreviousAuthors) + .numCloningThreads(numCloningThreads) + .numAnalysisThreads(numAnalysisThreads) + .isTestMode(isTestMode); + + LogsManager.setLogFolderLocation(outputFolderPath); + + if (locations == null && configFolderPath.equals(DEFAULT_CONFIG_PATH)) { + logger.info(MESSAGE_USING_DEFAULT_CONFIG_PATH); + } + + addReportConfigToBuilder(cliArgumentsBuilder, results); + addAnalysisDatesToBuilder(cliArgumentsBuilder, results); + + boolean isViewModeOnly = reportFolderPath != null + && !reportFolderPath.equals(EMPTY_PATH) + && configFolderPath.equals(DEFAULT_CONFIG_PATH) + && locations == null; + cliArgumentsBuilder.isViewModeOnly(isViewModeOnly); + + boolean isAutomaticallyLaunching = reportFolderPath != null; + if (isAutomaticallyLaunching && !reportFolderPath.equals(EMPTY_PATH) && !isViewModeOnly) { + logger.info(String.format("Ignoring argument '%s' for --view.", reportFolderPath.toString())); + } + cliArgumentsBuilder.isAutomaticallyLaunching(isAutomaticallyLaunching); + + boolean shouldPerformFreshCloning = isTestMode + ? results.get(FRESH_CLONING_FLAG[0]) + : DEFAULT_SHOULD_FRESH_CLONE; + cliArgumentsBuilder.isFreshClonePerformed(shouldPerformFreshCloning); + + return cliArgumentsBuilder.build(); } /** From 31a6f94f0c248c92a9b0096b3a849acaa43b320c Mon Sep 17 00:00:00 2001 From: nseah21 Date: Sat, 23 Dec 2023 06:58:51 +0800 Subject: [PATCH 4/8] Revert "Reduce scope of try-catch block for parse method" This reverts commit 0843d872ec91701b1ce41dd1fd4cbd201ea9ead1. --- .../java/reposense/parser/ArgsParser.java | 129 +++++++++--------- 1 file changed, 64 insertions(+), 65 deletions(-) diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 9130b8a329..44bef7dea9 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -262,77 +262,76 @@ private static ArgumentParser getArgumentParser() { * @throws ParseException if the given string arguments fails to parse to a {@link CliArguments} object. */ public static CliArguments parse(String[] args) throws HelpScreenException, ParseException { - ArgumentParser parser = getArgumentParser(); - Namespace results; - try { - results = parser.parseArgs(args); + ArgumentParser parser = getArgumentParser(); + Namespace results = parser.parseArgs(args); + + Path configFolderPath = results.get(CONFIG_FLAGS[0]); + Path reportFolderPath = results.get(VIEW_FLAGS[0]); + Path outputFolderPath = results.get(OUTPUT_FLAGS[0]); + ZoneId zoneId = results.get(TIMEZONE_FLAGS[0]); + Path assetsFolderPath = results.get(ASSETS_FLAGS[0]); + List locations = results.get(REPO_FLAGS[0]); + List formats = FileType.convertFormatStringsToFileTypes(results.get(FORMAT_FLAGS[0])); + boolean isStandaloneConfigIgnored = results.get(IGNORE_CONFIG_FLAGS[0]); + boolean isFileSizeLimitIgnored = results.get(IGNORE_SIZELIMIT_FLAGS[0]); + boolean shouldIncludeLastModifiedDate = results.get(LAST_MODIFIED_DATE_FLAGS[0]); + boolean shouldPerformShallowCloning = results.get(SHALLOW_CLONING_FLAGS[0]); + boolean shouldFindPreviousAuthors = results.get(FIND_PREVIOUS_AUTHORS_FLAGS[0]); + boolean isTestMode = results.get(TEST_MODE_FLAG[0]); + int numCloningThreads = results.get(CLONING_THREADS_FLAG[0]); + int numAnalysisThreads = results.get(ANALYSIS_THREADS_FLAG[0]); + + CliArguments.Builder cliArgumentsBuilder = new CliArguments.Builder() + .configFolderPath(configFolderPath) + .reportDirectoryPath(reportFolderPath) + .outputFilePath(outputFolderPath) + .zoneId(zoneId) + .assetsFilePath(assetsFolderPath) + .locations(locations) + .formats(formats) + .isStandaloneConfigIgnored(isStandaloneConfigIgnored) + .isFileSizeLimitIgnored(isFileSizeLimitIgnored) + .isLastModifiedDateIncluded(shouldIncludeLastModifiedDate) + .isShallowCloningPerformed(shouldPerformShallowCloning) + .isFindingPreviousAuthorsPerformed(shouldFindPreviousAuthors) + .numCloningThreads(numCloningThreads) + .numAnalysisThreads(numAnalysisThreads) + .isTestMode(isTestMode); + + LogsManager.setLogFolderLocation(outputFolderPath); + + if (locations == null && configFolderPath.equals(DEFAULT_CONFIG_PATH)) { + logger.info(MESSAGE_USING_DEFAULT_CONFIG_PATH); + } + + addReportConfigToBuilder(cliArgumentsBuilder, results); + addAnalysisDatesToBuilder(cliArgumentsBuilder, results); + + boolean isViewModeOnly = reportFolderPath != null + && !reportFolderPath.equals(EMPTY_PATH) + && configFolderPath.equals(DEFAULT_CONFIG_PATH) + && locations == null; + cliArgumentsBuilder.isViewModeOnly(isViewModeOnly); + + boolean isAutomaticallyLaunching = reportFolderPath != null; + if (isAutomaticallyLaunching && !reportFolderPath.equals(EMPTY_PATH) && !isViewModeOnly) { + logger.info(String.format("Ignoring argument '%s' for --view.", reportFolderPath.toString())); + } + cliArgumentsBuilder.isAutomaticallyLaunching(isAutomaticallyLaunching); + + + boolean shouldPerformFreshCloning = isTestMode + ? results.get(FRESH_CLONING_FLAG[0]) + : DEFAULT_SHOULD_FRESH_CLONE; + cliArgumentsBuilder.isFreshClonePerformed(shouldPerformFreshCloning); + + return cliArgumentsBuilder.build(); } catch (HelpScreenException hse) { throw hse; } catch (ArgumentParserException ape) { throw new ParseException(getArgumentParser().formatUsage() + ape.getMessage() + "\n"); } - - Path configFolderPath = results.get(CONFIG_FLAGS[0]); - Path reportFolderPath = results.get(VIEW_FLAGS[0]); - Path outputFolderPath = results.get(OUTPUT_FLAGS[0]); - ZoneId zoneId = results.get(TIMEZONE_FLAGS[0]); - Path assetsFolderPath = results.get(ASSETS_FLAGS[0]); - List locations = results.get(REPO_FLAGS[0]); - List formats = FileType.convertFormatStringsToFileTypes(results.get(FORMAT_FLAGS[0])); - boolean isStandaloneConfigIgnored = results.get(IGNORE_CONFIG_FLAGS[0]); - boolean isFileSizeLimitIgnored = results.get(IGNORE_SIZELIMIT_FLAGS[0]); - boolean shouldIncludeLastModifiedDate = results.get(LAST_MODIFIED_DATE_FLAGS[0]); - boolean shouldPerformShallowCloning = results.get(SHALLOW_CLONING_FLAGS[0]); - boolean shouldFindPreviousAuthors = results.get(FIND_PREVIOUS_AUTHORS_FLAGS[0]); - boolean isTestMode = results.get(TEST_MODE_FLAG[0]); - int numCloningThreads = results.get(CLONING_THREADS_FLAG[0]); - int numAnalysisThreads = results.get(ANALYSIS_THREADS_FLAG[0]); - - CliArguments.Builder cliArgumentsBuilder = new CliArguments.Builder() - .configFolderPath(configFolderPath) - .reportDirectoryPath(reportFolderPath) - .outputFilePath(outputFolderPath) - .zoneId(zoneId) - .assetsFilePath(assetsFolderPath) - .locations(locations) - .formats(formats) - .isStandaloneConfigIgnored(isStandaloneConfigIgnored) - .isFileSizeLimitIgnored(isFileSizeLimitIgnored) - .isLastModifiedDateIncluded(shouldIncludeLastModifiedDate) - .isShallowCloningPerformed(shouldPerformShallowCloning) - .isFindingPreviousAuthorsPerformed(shouldFindPreviousAuthors) - .numCloningThreads(numCloningThreads) - .numAnalysisThreads(numAnalysisThreads) - .isTestMode(isTestMode); - - LogsManager.setLogFolderLocation(outputFolderPath); - - if (locations == null && configFolderPath.equals(DEFAULT_CONFIG_PATH)) { - logger.info(MESSAGE_USING_DEFAULT_CONFIG_PATH); - } - - addReportConfigToBuilder(cliArgumentsBuilder, results); - addAnalysisDatesToBuilder(cliArgumentsBuilder, results); - - boolean isViewModeOnly = reportFolderPath != null - && !reportFolderPath.equals(EMPTY_PATH) - && configFolderPath.equals(DEFAULT_CONFIG_PATH) - && locations == null; - cliArgumentsBuilder.isViewModeOnly(isViewModeOnly); - - boolean isAutomaticallyLaunching = reportFolderPath != null; - if (isAutomaticallyLaunching && !reportFolderPath.equals(EMPTY_PATH) && !isViewModeOnly) { - logger.info(String.format("Ignoring argument '%s' for --view.", reportFolderPath.toString())); - } - cliArgumentsBuilder.isAutomaticallyLaunching(isAutomaticallyLaunching); - - boolean shouldPerformFreshCloning = isTestMode - ? results.get(FRESH_CLONING_FLAG[0]) - : DEFAULT_SHOULD_FRESH_CLONE; - cliArgumentsBuilder.isFreshClonePerformed(shouldPerformFreshCloning); - - return cliArgumentsBuilder.build(); } /** From 6d76aff4c6bda250db31d9250ba82ba6d54fb5cb Mon Sep 17 00:00:00 2001 From: nseah21 Date: Sun, 24 Dec 2023 06:19:19 +0800 Subject: [PATCH 5/8] Update tests for ArgParser --- src/test/java/reposense/parser/ArgsParserTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/reposense/parser/ArgsParserTest.java b/src/test/java/reposense/parser/ArgsParserTest.java index 11fa3a5714..317417a252 100644 --- a/src/test/java/reposense/parser/ArgsParserTest.java +++ b/src/test/java/reposense/parser/ArgsParserTest.java @@ -11,6 +11,7 @@ import java.time.LocalDateTime; import java.time.Month; import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; @@ -606,6 +607,18 @@ public void sinceDate_laterThanUntilDate_throwsParseException() { Assertions.assertThrows(ParseException.class, () -> ArgsParser.parse(translateCommandline(input))); } + @Test + public void sinceDate_laterThanCurrentDate_throwsParseException() { + LocalDateTime tomorrowDateTime = LocalDateTime.now() + .plusDays(1L); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + String tomorrow = tomorrowDateTime.format(formatter); + + String input = DEFAULT_INPUT_BUILDER.addSinceDate(tomorrow) + .build(); + Assertions.assertThrows(ParseException.class, () -> ArgsParser.parse(translateCommandline(input))); + } + @Test public void period_withBothSinceDateAndUntilDate_throwsParseException() { String input = DEFAULT_INPUT_BUILDER.addPeriod("18d") From a1f0e175b7f34d9726ea1c7939ce3c538e36f8e1 Mon Sep 17 00:00:00 2001 From: nseah21 Date: Sun, 24 Dec 2023 07:08:10 +0800 Subject: [PATCH 6/8] Add valid untilDate precondition to test case --- src/test/java/reposense/parser/ArgsParserTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/reposense/parser/ArgsParserTest.java b/src/test/java/reposense/parser/ArgsParserTest.java index 317417a252..74f2f19a7e 100644 --- a/src/test/java/reposense/parser/ArgsParserTest.java +++ b/src/test/java/reposense/parser/ArgsParserTest.java @@ -611,10 +611,15 @@ public void sinceDate_laterThanUntilDate_throwsParseException() { public void sinceDate_laterThanCurrentDate_throwsParseException() { LocalDateTime tomorrowDateTime = LocalDateTime.now() .plusDays(1L); + LocalDateTime dayAfterDateTime = LocalDateTime.now() + .plusDays(2L); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); String tomorrow = tomorrowDateTime.format(formatter); + String dayAfter = dayAfterDateTime.format(formatter); String input = DEFAULT_INPUT_BUILDER.addSinceDate(tomorrow) + .addUntilDate(dayAfter) .build(); Assertions.assertThrows(ParseException.class, () -> ArgsParser.parse(translateCommandline(input))); } From b29e1024f7daa622ca67f3c26189ae7e8f1f9db4 Mon Sep 17 00:00:00 2001 From: nseah21 Date: Tue, 26 Dec 2023 07:40:51 +0800 Subject: [PATCH 7/8] Re-order sinceDate comparison checks in ArgsParser --- src/main/java/reposense/parser/ArgsParser.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/reposense/parser/ArgsParser.java b/src/main/java/reposense/parser/ArgsParser.java index 60dacabd6c..ff6ea7ae95 100644 --- a/src/main/java/reposense/parser/ArgsParser.java +++ b/src/main/java/reposense/parser/ArgsParser.java @@ -424,14 +424,14 @@ private static void addAnalysisDatesToBuilder(CliArguments.Builder builder, Name ? untilDate : currentDate; - if (sinceDate.compareTo(untilDate) > 0) { - throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE); - } - if (sinceDate.compareTo(currentDate) > 0) { throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_TODAY_DATE); } + if (sinceDate.compareTo(untilDate) > 0) { + throw new ParseException(MESSAGE_SINCE_DATE_LATER_THAN_UNTIL_DATE); + } + builder.sinceDate(sinceDate) .isSinceDateProvided(isSinceDateProvided) .untilDate(untilDate) From 3f377609295c1db1c5b17c0e949b88066041b57e Mon Sep 17 00:00:00 2001 From: nseah21 Date: Tue, 26 Dec 2023 07:43:48 +0800 Subject: [PATCH 8/8] Modify tests for ArgParser --- src/test/java/reposense/parser/ArgsParserTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/test/java/reposense/parser/ArgsParserTest.java b/src/test/java/reposense/parser/ArgsParserTest.java index 74f2f19a7e..1ed90dbbc9 100644 --- a/src/test/java/reposense/parser/ArgsParserTest.java +++ b/src/test/java/reposense/parser/ArgsParserTest.java @@ -609,6 +609,19 @@ public void sinceDate_laterThanUntilDate_throwsParseException() { @Test public void sinceDate_laterThanCurrentDate_throwsParseException() { + LocalDateTime tomorrowDateTime = LocalDateTime.now() + .plusDays(1L); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); + String tomorrow = tomorrowDateTime.format(formatter); + + + String input = DEFAULT_INPUT_BUILDER.addSinceDate(tomorrow) + .build(); + Assertions.assertThrows(ParseException.class, () -> ArgsParser.parse(translateCommandline(input))); + } + + @Test + public void sinceDate_beforeUntilDateAndLaterThanCurrentDate_throwsParseException() { LocalDateTime tomorrowDateTime = LocalDateTime.now() .plusDays(1L); LocalDateTime dayAfterDateTime = LocalDateTime.now()