From 8b1b7b42c451ac3f76367f80277b0c6d99e655c1 Mon Sep 17 00:00:00 2001 From: sikai00 Date: Wed, 15 Mar 2023 18:37:25 +0800 Subject: [PATCH] Add UntilPrompt --- .../java/reposense/wizard/BasicWizard.java | 1 + .../reposense/wizard/OptionalUntilPrompt.java | 18 +++++++ .../java/reposense/wizard/UntilPrompt.java | 23 +++++++++ .../reposense/wizard/WizardRunnerTest.java | 51 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/main/java/reposense/wizard/OptionalUntilPrompt.java create mode 100644 src/main/java/reposense/wizard/UntilPrompt.java diff --git a/src/main/java/reposense/wizard/BasicWizard.java b/src/main/java/reposense/wizard/BasicWizard.java index a8cd7d3e5f..fd93529be2 100644 --- a/src/main/java/reposense/wizard/BasicWizard.java +++ b/src/main/java/reposense/wizard/BasicWizard.java @@ -6,6 +6,7 @@ public class BasicWizard extends Wizard { private static final Prompt[] INITIAL_PROMPTS = new Prompt[] { new OptionalSincePrompt(), + new OptionalUntilPrompt(), new OptionalViewPrompt(), new RepoPrompt() }; diff --git a/src/main/java/reposense/wizard/OptionalUntilPrompt.java b/src/main/java/reposense/wizard/OptionalUntilPrompt.java new file mode 100644 index 0000000000..4c3c298411 --- /dev/null +++ b/src/main/java/reposense/wizard/OptionalUntilPrompt.java @@ -0,0 +1,18 @@ +package reposense.wizard; + +/** + * Represents an Optional Prompt to get the untilDate flag. + */ +public class OptionalUntilPrompt extends OptionalPrompt { + private static final String DESCRIPTION = "Do you want to specify the end date for the period to be analyzed? " + + "The default is today"; + + public OptionalUntilPrompt() { + super(DESCRIPTION); + } + + @Override + public Prompt[] optionallyRun() { + return new Prompt[]{new UntilPrompt()}; + } +} diff --git a/src/main/java/reposense/wizard/UntilPrompt.java b/src/main/java/reposense/wizard/UntilPrompt.java new file mode 100644 index 0000000000..8dcad68117 --- /dev/null +++ b/src/main/java/reposense/wizard/UntilPrompt.java @@ -0,0 +1,23 @@ +package reposense.wizard; + +/** + * Represents a Prompt to get the untilDate flag. + */ +public class UntilPrompt extends Prompt { + private static final String DESCRIPTION = "Enter the end date for the period to be analyzed"; + private static final String FORMAT = "DD/MM/YYYY"; + + public UntilPrompt() { + super(DESCRIPTION, FORMAT); + } + + @Override + public InputBuilder addToInput(InputBuilder inputBuilder) { + return inputBuilder.addUntilDate(getResponse()); + } + + @Override + public Prompt[] run() { + return new Prompt[] {}; + } +} diff --git a/src/test/java/reposense/wizard/WizardRunnerTest.java b/src/test/java/reposense/wizard/WizardRunnerTest.java index 08761e548f..eab4968935 100644 --- a/src/test/java/reposense/wizard/WizardRunnerTest.java +++ b/src/test/java/reposense/wizard/WizardRunnerTest.java @@ -13,6 +13,7 @@ public class WizardRunnerTest { private static final String SINCE_DATE = "30/09/2022"; + private static final String UNTIL_DATE = "15/03/2023"; private static final String REPORT_PATH = "C:\\User\\RepoSense"; private static final String REPO_LINK = "https://github.com/reposense/RepoSense.git"; @@ -20,6 +21,7 @@ public class WizardRunnerTest { public void buildInput_repoOnly_success() { WizardRunner wizardRunner = new WizardRunner(new BasicWizard()); String input = new WizardInputBuilder() + .addNoFlag() .addNoFlag() .addNoFlag() .add(REPO_LINK) @@ -40,6 +42,50 @@ public void buildInput_sinceDateAndRepo_success() { .addYesFlag() .add(SINCE_DATE) .addNoFlag() + .addNoFlag() + .add(REPO_LINK) + .build(); + InputStream targetStream = new ByteArrayInputStream(input.getBytes()); + Scanner sc = new Scanner(targetStream); + wizardRunner.buildInput(sc); + + String expectedInput = new InputBuilder() + .addSinceDate(SINCE_DATE) + .addRepos(REPO_LINK) + .build(); + assertEquals(expectedInput, wizardRunner.getBuiltInput()); + } + + @Test + public void buildInput_untilDateAndRepo_success() { + WizardRunner wizardRunner = new WizardRunner(new BasicWizard()); + String input = new WizardInputBuilder() + .addNoFlag() + .addYesFlag() + .add(UNTIL_DATE) + .addNoFlag() + .add(REPO_LINK) + .build(); + InputStream targetStream = new ByteArrayInputStream(input.getBytes()); + Scanner sc = new Scanner(targetStream); + wizardRunner.buildInput(sc); + + String expectedInput = new InputBuilder() + .addUntilDate(UNTIL_DATE) + .addRepos(REPO_LINK) + .build(); + assertEquals(expectedInput, wizardRunner.getBuiltInput()); + } + + @Test + public void buildInput_sinceDateAndUntilDateAndRepo_success() { + WizardRunner wizardRunner = new WizardRunner(new BasicWizard()); + String input = new WizardInputBuilder() + .addYesFlag() + .add(SINCE_DATE) + .addYesFlag() + .add(UNTIL_DATE) + .addNoFlag() .add(REPO_LINK) .build(); InputStream targetStream = new ByteArrayInputStream(input.getBytes()); @@ -48,6 +94,7 @@ public void buildInput_sinceDateAndRepo_success() { String expectedInput = new InputBuilder() .addSinceDate(SINCE_DATE) + .addUntilDate(UNTIL_DATE) .addRepos(REPO_LINK) .build(); assertEquals(expectedInput, wizardRunner.getBuiltInput()); @@ -58,6 +105,7 @@ public void buildInput_viewAndRepo_success() { WizardRunner wizardRunner = new WizardRunner(new BasicWizard()); // Yes only for view flag String input = new WizardInputBuilder() + .addNoFlag() .addNoFlag() .addYesFlag() .add(REPORT_PATH) @@ -82,6 +130,8 @@ public void buildInput_allFlags_success() { .addYesFlag() .add(SINCE_DATE) .addYesFlag() + .add(UNTIL_DATE) + .addYesFlag() .add(REPORT_PATH) .add(REPO_LINK) .build(); @@ -91,6 +141,7 @@ public void buildInput_allFlags_success() { String expectedInput = new InputBuilder() .addSinceDate(SINCE_DATE) + .addUntilDate(UNTIL_DATE) .addView(Paths.get(REPORT_PATH)) .addRepos(REPO_LINK) .build();