Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UntilPrompt #3

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/reposense/wizard/BasicWizard.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/reposense/wizard/OptionalUntilPrompt.java
Original file line number Diff line number Diff line change
@@ -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()};
}
}
23 changes: 23 additions & 0 deletions src/main/java/reposense/wizard/UntilPrompt.java
Original file line number Diff line number Diff line change
@@ -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[] {};
}
}
51 changes: 51 additions & 0 deletions src/test/java/reposense/wizard/WizardRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

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";

@Test
public void buildInput_repoOnly_success() {
WizardRunner wizardRunner = new WizardRunner(new BasicWizard());
String input = new WizardInputBuilder()
.addNoFlag()
.addNoFlag()
.addNoFlag()
.add(REPO_LINK)
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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)
Expand All @@ -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();
Expand All @@ -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();
Expand Down