diff --git a/.gitignore b/.gitignore index e4513a852c..06c819e36b 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,7 @@ src/main/resources/docs/ *.iml bin/ -/text-ui-test/ACTUAL.TXT +/text-ui-test/EXPECTED.TXT text-ui-test/EXPECTED-UNIX.TXT data \ No newline at end of file diff --git a/src/main/java/seedu/duke/Duke.java b/src/main/java/seedu/duke/Duke.java index b3d0d5eecc..af34aa533c 100644 --- a/src/main/java/seedu/duke/Duke.java +++ b/src/main/java/seedu/duke/Duke.java @@ -59,10 +59,6 @@ private void start(String[] launchArgs) { ui = new TextUi(); exerciseLogStorage = ExerciseLogStorage.initializeStorage(dirPath, exerciseLogFilePath); exerciseLogStorage.checkForLogTextFile(exerciseLog); - goalStorage = GoalStorage.initializeGoalStorage(dirPath, goalFilePath); - goalStorage.restoreGoalRecord(); - achmStorage = AchmStorage.initializeGoalStorage(dirPath, achmFilePath); - achmStorage.restoreGoalRecord(); ui.showWelcomeMessage(VERSION, "storage.getPath()"); } catch (Exception e) { // TODO: change to specific storage exceptions later ui.showInitFailedMessage(); diff --git a/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java b/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java index 5d699e869e..8b24ee7c3d 100644 --- a/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/AchieveGoalCommand.java @@ -28,8 +28,6 @@ public CommandResult execute() { } catch (Exception e) { feedbackToUser = "Something went wrong, please try again."; } - return new CommandResult(feedbackToUser); } - } diff --git a/src/main/java/seedu/duke/commands/goal/AchievementCommand.java b/src/main/java/seedu/duke/commands/goal/AchievementCommand.java index 7b2e75cea9..5d4a45b629 100644 --- a/src/main/java/seedu/duke/commands/goal/AchievementCommand.java +++ b/src/main/java/seedu/duke/commands/goal/AchievementCommand.java @@ -30,6 +30,4 @@ public CommandResult execute() { return new CommandResult(feedbackToUser); } - - } diff --git a/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java b/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java index 30a39c98c9..02e2f08f60 100644 --- a/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/DeleteGoalCommand.java @@ -40,6 +40,4 @@ public CommandResult execute() { return new CommandResult(feedbackToUser); } - - } diff --git a/src/main/java/seedu/duke/commands/goal/GoalCommand.java b/src/main/java/seedu/duke/commands/goal/GoalCommand.java index 18c14ec83e..34105c2350 100644 --- a/src/main/java/seedu/duke/commands/goal/GoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/GoalCommand.java @@ -41,10 +41,6 @@ public CommandResult execute() { feedbackToUser = "Something went wrong, please try again."; } - - - return new CommandResult(feedbackToUser); } - } diff --git a/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java b/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java index 485b9bc938..cc3038f6da 100644 --- a/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java +++ b/src/main/java/seedu/duke/commands/goal/ViewGoalCommand.java @@ -30,5 +30,4 @@ public CommandResult execute() { return new CommandResult(feedbackToUser); } - } diff --git a/src/main/java/seedu/duke/data/Date.java b/src/main/java/seedu/duke/data/Date.java index b472dc1626..cc2fda6e59 100644 --- a/src/main/java/seedu/duke/data/Date.java +++ b/src/main/java/seedu/duke/data/Date.java @@ -6,8 +6,6 @@ import java.time.format.DateTimeFormatter; import java.util.Locale; -// import com.google.gson.annotations.SerializedName; - /** * Customized class for showing date and parsing supported string to date. */ @@ -29,22 +27,22 @@ public class Date { * @param NotAllowPast true for all goal related commands only * @throws IncorrectFormatException if failed to parse date string input */ - public Date(String rawData, Boolean NotAllowPast) throws IncorrectFormatException { - setRawData(rawData, NotAllowPast); + public Date(String rawData, Boolean notAllowPast) throws IncorrectFormatException { + setRawData(rawData, notAllowPast); } /** * The method is used to set up the date field of a Date object * It contains the actual implementation to parse date information from a string * @param rawData refers to a date string - * @param NotAllowPast if past is not allowed, for example for goal functions + * @param notAllowPast if past is not allowed, for example for goal functions * @throws IncorrectFormatException if failed to parse date string input */ - public void setRawData(String rawData, boolean NotAllowPast) throws IncorrectFormatException { + public void setRawData(String rawData, boolean notAllowPast) throws IncorrectFormatException { for (DateTimeFormatter formatter : formatters) { try { date = LocalDate.parse(rawData, formatter); - if (NotAllowPast) { + if (notAllowPast) { if (date.isBefore(LocalDate.now())) { throw new IncorrectFormatException("Target Deadline has passed! "); } diff --git a/src/main/java/seedu/duke/goal/GoalList.java b/src/main/java/seedu/duke/goal/GoalList.java index 99f5ca2144..da441cf996 100644 --- a/src/main/java/seedu/duke/goal/GoalList.java +++ b/src/main/java/seedu/duke/goal/GoalList.java @@ -32,11 +32,11 @@ public int getGoalCount() { /** * This method removes a goal object from the global field goals list by indexing * It also decrements goalCount by 1 - * @param cmd Raw user Command + * @param cmd Raw user command + * @return message of succeeding to delete goal and tell user the updated total number of goals * @throws IOException if failed to access output file * @throws NumberFormatException if index is invalid number * @throws IncorrectFormatException is user command is in incorrect format - * @return message of succeeding to delete goal and tell user the updated total number of goals */ public static String deleteGoal(String cmd) throws IncorrectFormatException, NumberFormatException, IOException { @@ -145,10 +145,10 @@ private static void verifyAchieveGoalInput(String cmd) throws IncorrectFormatExc * @param userCmd represents raw user input * @param target represents to target list to add new goal * @param storage represents the target storage to update goal data + * @return String about succeeding to create goal object * @throws IncorrectFormatException if user input is in wrong format * @throws NumberFormatException if the user does not input a valid number * @throws IOException if failed to access and update output file - * @return String about succeeding to create goal object */ public static String addGoal(String userCmd, GoalList target, GoalStorage storage) throws IncorrectFormatException, NumberFormatException, IOException { @@ -207,5 +207,4 @@ public String toString() { return "Consume " + this.calories + " kcal on " + this.date; } } - } diff --git a/src/main/java/seedu/duke/parser/Parser.java b/src/main/java/seedu/duke/parser/Parser.java index 3913cd5fdb..85212e97dc 100644 --- a/src/main/java/seedu/duke/parser/Parser.java +++ b/src/main/java/seedu/duke/parser/Parser.java @@ -11,8 +11,12 @@ import java.util.regex.Pattern; import seedu.duke.commands.Command; -import seedu.duke.commands.goal.*; import seedu.duke.commands.HelpCommand; +import seedu.duke.commands.goal.GoalCommand; +import seedu.duke.commands.goal.DeleteGoalCommand; +import seedu.duke.commands.goal.ViewGoalCommand; +import seedu.duke.commands.goal.AchievementCommand; +import seedu.duke.commands.goal.AchieveGoalCommand; import seedu.duke.commands.IncorrectCommand; import seedu.duke.commands.logcommands.LogCommand; import seedu.duke.commands.logcommands.DeleteLogCommand; @@ -136,5 +140,4 @@ public static class ParseException extends Exception { super(message); } } - } diff --git a/src/main/java/seedu/duke/storagefile/AchmStorage.java b/src/main/java/seedu/duke/storagefile/AchmStorage.java index b69bd3b4db..b08eda76b3 100644 --- a/src/main/java/seedu/duke/storagefile/AchmStorage.java +++ b/src/main/java/seedu/duke/storagefile/AchmStorage.java @@ -66,8 +66,4 @@ protected void textToGoalObject(String goalRecord) throws Exception { String restoredCommand = restoreOrigionalCommand(goalRecord); GoalList.addGoal(restoredCommand, Duke.achievedGoals, Duke.achmStorage); } - - - } - diff --git a/src/main/java/seedu/duke/storagefile/Storage.java b/src/main/java/seedu/duke/storagefile/Storage.java index 77de5222b0..00b3dce119 100644 --- a/src/main/java/seedu/duke/storagefile/Storage.java +++ b/src/main/java/seedu/duke/storagefile/Storage.java @@ -2,7 +2,6 @@ import java.io.File; import java.io.FileWriter; -import java.io.IOException; class Storage { diff --git a/src/main/java/seedu/duke/ui/TextUi.java b/src/main/java/seedu/duke/ui/TextUi.java index e84151e54a..a7a037a94b 100644 --- a/src/main/java/seedu/duke/ui/TextUi.java +++ b/src/main/java/seedu/duke/ui/TextUi.java @@ -12,10 +12,10 @@ import java.util.Optional; import java.util.Scanner; -import seedu.duke.Duke; import seedu.duke.commands.CommandResult; import seedu.duke.goal.GoalList; import seedu.duke.data.Printable; +import seedu.duke.Duke; /** * Text UI of the application. diff --git a/src/test/java/seedu/duke/parser/ParserTest.java b/src/test/java/seedu/duke/parser/ParserTest.java index 10b28d7cd6..f75885ed8c 100644 --- a/src/test/java/seedu/duke/parser/ParserTest.java +++ b/src/test/java/seedu/duke/parser/ParserTest.java @@ -1,6 +1,7 @@ package seedu.duke.parser; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.duke.common.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import org.junit.jupiter.api.BeforeEach; @@ -26,15 +27,8 @@ public void parse_emptyInput_returnsIncorrect() throws Exception { parseAndAssertIncorrectWithMessage(resultMessage, emptyInputs); } - @Test - public void parse_unknownCommandWord_returnsHelp() throws Exception { - final String input = "unknowncommandword arguments arguments"; - parseAndAssertCommandType(input, HelpCommand.class); - } - /* - * Tests for 0-argument commands - * ======================================================================= + * Tests for 0-argument commands ======================================================================= */ @Test @@ -50,16 +44,11 @@ public void parse_exitCommand_parsedCorrectly() throws Exception { } /* - * Utility methods - * ============================================================================= - * ======= + * Utility methods ==================================================================================== */ /** - * Asserts that parsing the given inputs will return IncorrectCommand with the - * given feedback message. - * - * @throws Exception + * Asserts that parsing the given inputs will return IncorrectCommand with the given feedback message. */ private void parseAndAssertIncorrectWithMessage(String feedbackMessage, String... inputs) throws Exception { for (String input : inputs) { @@ -67,4 +56,18 @@ private void parseAndAssertIncorrectWithMessage(String feedbackMessage, String.. assertEquals(result.feedbackToUser, feedbackMessage); } } + + /** + * Parses input and asserts the class/type of the returned command object. + * + * @param input to be parsed + * @param expectedCommandClass expected class of returned command + * @return the parsed command object + */ + private T parseAndAssertCommandType(String input, Class expectedCommandClass) + throws Exception { + final Command result = parser.parseCommand(input); + assertTrue(result.getClass().isAssignableFrom(expectedCommandClass)); + return (T) result; + } } diff --git a/text-ui-test/EXPECTED.TXT b/text-ui-test/EXPECTED.TXT deleted file mode 100644 index b38c0d774c..0000000000 --- a/text-ui-test/EXPECTED.TXT +++ /dev/null @@ -1,13 +0,0 @@ -|| =================================================== -|| =================================================== -|| Welcome to your FITNUS journey! -|| FitNUS - Version 1.0 -|| Launch command format: java seedu.duke.Duke [STORAGE_FILE_PATH] -|| Using storage file : storage.getPath() -|| =================================================== -|| Enter command: || [Command entered:exit] -|| Exiting FITNUS as requested ... -|| =================================================== -|| Good bye! -|| =================================================== -|| ===================================================