From 7d5b20dd3c815c7ae0b9a6c0d3b97d7b1cbe62ee Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 12:39:06 +0800 Subject: [PATCH 01/49] Add SugTestUtil --- .../com/notably/logic/SuggestionTestUtil.java | 145 ++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 src/test/java/com/notably/logic/SuggestionTestUtil.java diff --git a/src/test/java/com/notably/logic/SuggestionTestUtil.java b/src/test/java/com/notably/logic/SuggestionTestUtil.java new file mode 100644 index 00000000000..0e1bc972654 --- /dev/null +++ b/src/test/java/com/notably/logic/SuggestionTestUtil.java @@ -0,0 +1,145 @@ +package com.notably.logic; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.jupiter.api.BeforeAll; + +import com.notably.commons.path.AbsolutePath; +import com.notably.commons.path.exceptions.InvalidPathException; +import com.notably.model.Model; +import com.notably.model.ModelManager; +import com.notably.model.block.Block; +import com.notably.model.block.BlockImpl; +import com.notably.model.block.BlockModel; +import com.notably.model.block.BlockModelImpl; +import com.notably.model.block.Title; +import com.notably.model.suggestion.SuggestionItem; +import com.notably.model.suggestion.SuggestionItemImpl; +import com.notably.model.suggestion.SuggestionModel; +import com.notably.model.suggestion.SuggestionModelImpl; +import com.notably.model.viewstate.ViewStateModel; +import com.notably.model.viewstate.ViewStateModelImpl; + +/** + * Contains helper methods for testing suggestion feature. + */ +public class SuggestionTestUtil { + private static AbsolutePath toCs2103; + private static AbsolutePath toCs3230; + private static AbsolutePath toCs2103Week1; + private static AbsolutePath toCs2103Week2; + private static AbsolutePath toCs2103Week3; + private static AbsolutePath toCs2103Week1Lecture; + private static Model model; + + @BeforeAll + public static void setUp() throws InvalidPathException { + // Set up paths + toCs2103 = AbsolutePath.fromString("/CS2103"); + toCs3230 = AbsolutePath.fromString("/CS3230"); + toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); + toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); + toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); + toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); + + // Set up model + BlockModel blockModel = new BlockModelImpl(); + SuggestionModel suggestionModel = new SuggestionModelImpl(); + ViewStateModel viewStateModel = new ViewStateModelImpl(); + model = new ModelManager(blockModel, suggestionModel, viewStateModel); + + // Add test data to model + Block cs2103 = new BlockImpl(new Title("CS2103")); + Block cs3230 = new BlockImpl(new Title("CS3230")); + model.addBlockToCurrentPath(cs2103); + model.addBlockToCurrentPath(cs3230); + + Block week1 = new BlockImpl(new Title("Week1")); + Block week2 = new BlockImpl(new Title("Week2")); + Block week3 = new BlockImpl(new Title("Week3")); + model.setCurrentlyOpenBlock(toCs2103); + model.addBlockToCurrentPath(week1); + model.addBlockToCurrentPath(week2); + model.addBlockToCurrentPath(week3); + + Block lecture = new BlockImpl(new Title("Lecture")); + model.setCurrentlyOpenBlock(toCs2103Week1); + model.addBlockToCurrentPath(lecture); + } + + public static AbsolutePath getToCs2103() { + return toCs2103; + } + + public static Model getModel() { + return model; + } + + public static List getExpectedSuggestionsToCs2103() { + SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); + SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); + SuggestionItem cs2103Week1Lecture = new + SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), null); + SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), + null); + SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), + null); + + List expectedSuggestions = new ArrayList<>(); + expectedSuggestions.add(cs2103); + expectedSuggestions.add(cs2103Week1); + expectedSuggestions.add(cs2103Week2); + expectedSuggestions.add(cs2103Week3); + expectedSuggestions.add(cs2103Week1Lecture); + + return expectedSuggestions; + } + + public static List getExpectedInputsToCs2103(String commandWord, boolean hasPrefixTitle) { + List expectedInputs = new ArrayList<>(); + String prefix = ""; + + if (hasPrefixTitle) { + prefix = "-t "; + } + + expectedInputs.add(commandWord + " " + prefix + toCs2103.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + toCs2103Week1.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + toCs2103Week2.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + toCs2103Week3.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + toCs2103Week1Lecture.getStringRepresentation()); + + return expectedInputs; + } + + /** + * Checks the correctness of the suggestions. + * @param expectedSuggestions The expected suggestions list. + * @param suggestions The actual suggestions list. + */ + public static void testSuggestions(List expectedSuggestions, List suggestions) { + for (int i = 0; i < expectedSuggestions.size(); i++) { + SuggestionItem suggestion = suggestions.get(i); + SuggestionItem expectedSuggestion = expectedSuggestions.get(i); + assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); + } + } + + /** + * Checks the correctness of the input stored in CommandInputModel for each suggestion. + * @param expectedInputs The expected list of inputs. + * @param suggestions The actual suggestions list. + */ + public static void testInputs(List expectedInputs, List suggestions) { + for (int i = 0; i < expectedInputs.size(); i++) { + SuggestionItem suggestionItem = suggestions.get(i); + String expectedInput = expectedInputs.get(i); + suggestionItem.getAction().run(); + String input = model.getInput(); + assertEquals(expectedInput, input); + } + } +} From 35f8c111129c3a15d80691ad1806af668aebc88a Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 12:39:59 +0800 Subject: [PATCH 02/49] Change isEmpty to isBlank --- .../logic/commands/suggestion/DeleteSuggestionCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java index 06a5a767f30..0e608310b11 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java @@ -33,7 +33,7 @@ public void execute(Model model) { // Nullity check Objects.requireNonNull(model); - if (!oldTitle.isEmpty()) { + if (!oldTitle.isBlank()) { // Set suggestions List possiblePaths = getPossiblePaths(path, model); List suggestions = getSuggestions(possiblePaths, model); From 10cf657f3f9bcd9a24fcfab925c63b0031aae5a4 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 12:40:23 +0800 Subject: [PATCH 03/49] Clean up DeleteSugCmdTest --- .../DeleteSuggestionCommandTest.java | 180 +++++------------- 1 file changed, 50 insertions(+), 130 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index 4872def4afe..759c1512e56 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -1,77 +1,36 @@ package com.notably.logic.commands.suggestion; import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.commons.path.exceptions.InvalidPathException; +import com.notably.logic.SuggestionTestUtil; import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Title; import com.notably.model.suggestion.SuggestionItem; -import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; public class DeleteSuggestionCommandTest { - private static AbsolutePath toRoot; private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; private static Model model; private static final String COMMAND_WORD = "delete"; @BeforeAll - public static void setUp() throws InvalidPathException { - // Set up paths - toRoot = AbsolutePath.fromString("/"); - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - - // Set up model - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - - // Add test data to model - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230")); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2")); - Block week3 = new BlockImpl(new Title("Week3")); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture")); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); + public static void setUpTree() { + SuggestionTestUtil.setUp(); + toCs2103 = SuggestionTestUtil.getToCs2103(); + model = SuggestionTestUtil.getModel(); + } + + @AfterEach + public void clearSuggestions() { + model.clearSuggestions(); } @Test @@ -81,105 +40,66 @@ public void constructor_nullPath_throwsNullPointerException() { @Test public void constructor_nullTitle_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new DeleteSuggestionCommand(toCs2103, null)); + assertThrows(NullPointerException.class, () -> new DeleteSuggestionCommand(toCs2103, + null)); } @Test public void execute_nullModel_throwsNullPointerException() { - DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toRoot, - toRoot.getStringRepresentation()); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, + toCs2103.getStringRepresentation()); assertThrows(NullPointerException.class, () -> deleteSuggestionCommand.execute(null)); } + @Test + public void execute_blankOldTitle_generatesEmptySuggestion() { + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, " "); + deleteSuggestionCommand.execute(model); + + assertTrue(model.getSuggestions().size() == 0); + } + @Test public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - DeleteSuggestionCommand deleteSuggestionCommand = - new DeleteSuggestionCommand(toCs2103, toCs2103.getStringRepresentation()); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, + toCs2103.getStringRepresentation()); deleteSuggestionCommand.execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); - List suggestions = model.getSuggestions(); - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103(COMMAND_WORD, true); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions); } @Test public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly() { model.setInput(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - DeleteSuggestionCommand deleteSuggestionCommand = - new DeleteSuggestionCommand(toCs2103, toCs2103.getStringRepresentation()); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, + toCs2103.getStringRepresentation()); deleteSuggestionCommand.execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); - List suggestions = model.getSuggestions(); - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103(COMMAND_WORD, false); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions); } } From 865bb4e4c33469d59d1498881e5b6d3613318f2c Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 12:44:52 +0800 Subject: [PATCH 04/49] Remove @BeforeAll in setUp method in SugTestUtil --- src/test/java/com/notably/logic/SuggestionTestUtil.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/com/notably/logic/SuggestionTestUtil.java b/src/test/java/com/notably/logic/SuggestionTestUtil.java index 0e1bc972654..0e275fe41bb 100644 --- a/src/test/java/com/notably/logic/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/SuggestionTestUtil.java @@ -5,8 +5,6 @@ import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.BeforeAll; - import com.notably.commons.path.AbsolutePath; import com.notably.commons.path.exceptions.InvalidPathException; import com.notably.model.Model; @@ -35,7 +33,6 @@ public class SuggestionTestUtil { private static AbsolutePath toCs2103Week1Lecture; private static Model model; - @BeforeAll public static void setUp() throws InvalidPathException { // Set up paths toCs2103 = AbsolutePath.fromString("/CS2103"); From 6dad3109d837869df997cda4b6c57d09697e9022 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 13:17:34 +0800 Subject: [PATCH 05/49] Abstract out methods --- .../com/notably/logic/SuggestionTestUtil.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/notably/logic/SuggestionTestUtil.java b/src/test/java/com/notably/logic/SuggestionTestUtil.java index 0e275fe41bb..beab86c016d 100644 --- a/src/test/java/com/notably/logic/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/SuggestionTestUtil.java @@ -35,20 +35,35 @@ public class SuggestionTestUtil { public static void setUp() throws InvalidPathException { // Set up paths + setUpPaths(); + + // Set up model + setUpModel(); + + // Add test data to model + addTestDataToModel(); + } + + public static void setUpPaths() { toCs2103 = AbsolutePath.fromString("/CS2103"); toCs3230 = AbsolutePath.fromString("/CS3230"); toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); + } - // Set up model + public static void setUpModel() { BlockModel blockModel = new BlockModelImpl(); SuggestionModel suggestionModel = new SuggestionModelImpl(); ViewStateModel viewStateModel = new ViewStateModelImpl(); model = new ModelManager(blockModel, suggestionModel, viewStateModel); + } - // Add test data to model + /** + * Adds the test data to the model. + */ + public static void addTestDataToModel() { Block cs2103 = new BlockImpl(new Title("CS2103")); Block cs3230 = new BlockImpl(new Title("CS3230")); model.addBlockToCurrentPath(cs2103); From 1b4ad2903df60f9b11c0062277e84af0d1da7a73 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 16:49:44 +0800 Subject: [PATCH 06/49] Use TypicalBlockModel in SugTestUtil --- .../com/notably/logic/SuggestionTestUtil.java | 157 ------------------ .../logic/suggestion/SuggestionTestUtil.java | 109 ++++++++++++ 2 files changed, 109 insertions(+), 157 deletions(-) delete mode 100644 src/test/java/com/notably/logic/SuggestionTestUtil.java create mode 100644 src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java diff --git a/src/test/java/com/notably/logic/SuggestionTestUtil.java b/src/test/java/com/notably/logic/SuggestionTestUtil.java deleted file mode 100644 index beab86c016d..00000000000 --- a/src/test/java/com/notably/logic/SuggestionTestUtil.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.notably.logic; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import com.notably.commons.path.AbsolutePath; -import com.notably.commons.path.exceptions.InvalidPathException; -import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Title; -import com.notably.model.suggestion.SuggestionItem; -import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; - -/** - * Contains helper methods for testing suggestion feature. - */ -public class SuggestionTestUtil { - private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; - private static Model model; - - public static void setUp() throws InvalidPathException { - // Set up paths - setUpPaths(); - - // Set up model - setUpModel(); - - // Add test data to model - addTestDataToModel(); - } - - public static void setUpPaths() { - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - } - - public static void setUpModel() { - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - } - - /** - * Adds the test data to the model. - */ - public static void addTestDataToModel() { - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230")); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2")); - Block week3 = new BlockImpl(new Title("Week3")); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture")); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); - } - - public static AbsolutePath getToCs2103() { - return toCs2103; - } - - public static Model getModel() { - return model; - } - - public static List getExpectedSuggestionsToCs2103() { - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new - SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), - null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), - null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); - - return expectedSuggestions; - } - - public static List getExpectedInputsToCs2103(String commandWord, boolean hasPrefixTitle) { - List expectedInputs = new ArrayList<>(); - String prefix = ""; - - if (hasPrefixTitle) { - prefix = "-t "; - } - - expectedInputs.add(commandWord + " " + prefix + toCs2103.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + toCs2103Week1Lecture.getStringRepresentation()); - - return expectedInputs; - } - - /** - * Checks the correctness of the suggestions. - * @param expectedSuggestions The expected suggestions list. - * @param suggestions The actual suggestions list. - */ - public static void testSuggestions(List expectedSuggestions, List suggestions) { - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - } - - /** - * Checks the correctness of the input stored in CommandInputModel for each suggestion. - * @param expectedInputs The expected list of inputs. - * @param suggestions The actual suggestions list. - */ - public static void testInputs(List expectedInputs, List suggestions) { - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } - } -} diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java new file mode 100644 index 00000000000..d588d4e2202 --- /dev/null +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -0,0 +1,109 @@ +package com.notably.logic.suggestion; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import com.notably.commons.path.AbsolutePath; +import com.notably.model.Model; +import com.notably.model.ModelManager; +import com.notably.model.block.BlockModel; +import com.notably.model.suggestion.SuggestionItem; +import com.notably.model.suggestion.SuggestionItemImpl; +import com.notably.model.suggestion.SuggestionModel; +import com.notably.model.suggestion.SuggestionModelImpl; +import com.notably.model.viewstate.ViewStateModel; +import com.notably.model.viewstate.ViewStateModelImpl; +import com.notably.testutil.TypicalBlockModel; + +/** + * Contains helper methods for testing suggestion feature. + */ +public class SuggestionTestUtil { + private static Model model; + + public static Model getModel() { + BlockModel blockModel = TypicalBlockModel.getTypicalBlockModel(); + SuggestionModel suggestionModel = new SuggestionModelImpl(); + ViewStateModel viewStateModel = new ViewStateModelImpl(); + model = new ModelManager(blockModel, suggestionModel, viewStateModel); + + return model; + } + + public static AbsolutePath getToCs2103t() { + return TypicalBlockModel.PATH_TO_CS2103T; + } + + public static List getExpectedSuggestionsToCs2103t() { + SuggestionItem cs2103t = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation(), null); + SuggestionItem cs2103tLect = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T_LECTURES.getStringRepresentation(), null); + SuggestionItem cs2103tTut = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T_TUTORIALS.getStringRepresentation(), null); + SuggestionItem cs2103tTut1 = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), null); + SuggestionItem cs2103tTut2 = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), null); + + List expectedSuggestions = new ArrayList<>(); + expectedSuggestions.add(cs2103t); + expectedSuggestions.add(cs2103tLect); + expectedSuggestions.add(cs2103tTut); + expectedSuggestions.add(cs2103tTut1); + expectedSuggestions.add(cs2103tTut2); + + return expectedSuggestions; + } + + public static List getExpectedInputsToCs2103t(String commandWord, boolean hasPrefixTitle) { + List expectedInputs = new ArrayList<>(); + String prefix = ""; + + if (hasPrefixTitle) { + prefix = "-t "; + } + + expectedInputs.add(commandWord + " " + prefix + TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + + TypicalBlockModel.PATH_TO_CS2103T_LECTURES.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + + TypicalBlockModel.PATH_TO_CS2103T_TUTORIALS.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation()); + expectedInputs.add(commandWord + " " + prefix + + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation()); + + return expectedInputs; + } + + /** + * Checks the correctness of the suggestions. + * @param expectedSuggestions The expected suggestions list. + * @param suggestions The actual suggestions list. + */ + public static void testSuggestions(List expectedSuggestions, List suggestions) { + for (int i = 0; i < expectedSuggestions.size(); i++) { + SuggestionItem suggestion = suggestions.get(i); + SuggestionItem expectedSuggestion = expectedSuggestions.get(i); + assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); + } + } + + /** + * Checks the correctness of the input stored in CommandInputModel for each suggestion. + * @param expectedInputs The expected list of inputs. + * @param suggestions The actual suggestions list. + */ + public static void testInputs(List expectedInputs, List suggestions) { + for (int i = 0; i < expectedInputs.size(); i++) { + SuggestionItem suggestionItem = suggestions.get(i); + String expectedInput = expectedInputs.get(i); + suggestionItem.getAction().run(); + String input = model.getInput(); + assertEquals(expectedInput, input); + } + } +} From fd343debcee269b27908addb52f99bd4fb1a2802 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 16:50:23 +0800 Subject: [PATCH 07/49] Update DeleteSugCmdTest --- .../DeleteSuggestionCommandTest.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index 759c1512e56..fc9eadc1627 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -11,20 +11,19 @@ import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.logic.SuggestionTestUtil; +import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; import com.notably.model.suggestion.SuggestionItem; public class DeleteSuggestionCommandTest { - private static AbsolutePath toCs2103; + private static AbsolutePath toCs2103t; private static Model model; private static final String COMMAND_WORD = "delete"; @BeforeAll public static void setUpTree() { - SuggestionTestUtil.setUp(); - toCs2103 = SuggestionTestUtil.getToCs2103(); + toCs2103t = SuggestionTestUtil.getToCs2103t(); model = SuggestionTestUtil.getModel(); } @@ -40,20 +39,20 @@ public void constructor_nullPath_throwsNullPointerException() { @Test public void constructor_nullTitle_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new DeleteSuggestionCommand(toCs2103, + assertThrows(NullPointerException.class, () -> new DeleteSuggestionCommand(toCs2103t, null)); } @Test public void execute_nullModel_throwsNullPointerException() { - DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, - toCs2103.getStringRepresentation()); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, + toCs2103t.getStringRepresentation()); assertThrows(NullPointerException.class, () -> deleteSuggestionCommand.execute(null)); } @Test public void execute_blankOldTitle_generatesEmptySuggestion() { - DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, " "); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, " "); deleteSuggestionCommand.execute(model); assertTrue(model.getSuggestions().size() == 0); @@ -61,21 +60,21 @@ public void execute_blankOldTitle_generatesEmptySuggestion() { @Test public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, - toCs2103.getStringRepresentation()); + model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103t.getStringRepresentation()); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, + toCs2103t.getStringRepresentation()); deleteSuggestionCommand.execute(model); List suggestions = model.getSuggestions(); // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103(); + List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103(COMMAND_WORD, true); + List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, true); // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions); @@ -83,21 +82,21 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { @Test public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103, - toCs2103.getStringRepresentation()); + model.setInput(COMMAND_WORD + " " + toCs2103t.getStringRepresentation()); + DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, + toCs2103t.getStringRepresentation()); deleteSuggestionCommand.execute(model); List suggestions = model.getSuggestions(); // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103(); + List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103(COMMAND_WORD, false); + List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, false); // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions); From 9068ad8e9b7dd5f54368170e61fae1e8f926f5f0 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 17:11:08 +0800 Subject: [PATCH 08/49] Change isEmpty to isBlank in OpenSugCmd --- .../logic/commands/suggestion/OpenSuggestionCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java index ee5299cc3de..8427d1a0aed 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java @@ -33,7 +33,7 @@ public void execute(Model model) { // Nullity check Objects.requireNonNull(model); - if (!oldTitle.isEmpty()) { + if (!oldTitle.isBlank()) { // Set suggestions List possiblePaths = getPossiblePaths(path, model); List suggestions = getSuggestions(possiblePaths, model); From f32be537e1dab31ed65a672dc8c94e035f4d48f0 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 17:11:25 +0800 Subject: [PATCH 09/49] Update OpenSugCmdTest --- .../suggestion/OpenSuggestionCommandTest.java | 186 +++++------------- 1 file changed, 53 insertions(+), 133 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index c1dbe573e9e..7a286bacb79 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -1,77 +1,36 @@ package com.notably.logic.commands.suggestion; import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.commons.path.exceptions.InvalidPathException; +import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Title; import com.notably.model.suggestion.SuggestionItem; -import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; public class OpenSuggestionCommandTest { - private static AbsolutePath toRoot; - private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; + private static AbsolutePath toCs2103t; private static Model model; private static final String COMMAND_WORD = "open"; @BeforeAll - public static void setUp() throws InvalidPathException { - // Set up paths - toRoot = AbsolutePath.fromString("/"); - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - - // Set up model - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - - // Add test data to model - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230")); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2")); - Block week3 = new BlockImpl(new Title("Week3")); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture")); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); + public static void setUpTree() { + toCs2103t = SuggestionTestUtil.getToCs2103t(); + model = SuggestionTestUtil.getModel(); + } + + @AfterEach + public void clearSuggestions() { + model.clearSuggestions(); + System.out.println("inside clear sug"); } @Test @@ -81,105 +40,66 @@ public void constructor_nullPath_throwsNullPointerException() { @Test public void constructor_nullTitle_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new OpenSuggestionCommand(toCs2103, null)); + assertThrows(NullPointerException.class, () -> new OpenSuggestionCommand(toCs2103t, + null)); } @Test public void execute_nullModel_throwsNullPointerException() { - OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toRoot, - toRoot.getStringRepresentation()); + OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, + toCs2103t.getStringRepresentation()); assertThrows(NullPointerException.class, () -> openSuggestionCommand.execute(null)); } @Test - public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - OpenSuggestionCommand openSuggestionCommand = - new OpenSuggestionCommand(toCs2103, toCs2103.getStringRepresentation()); + public void execute_blankOldTitle_generatesEmptySuggestion() { + OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, " "); openSuggestionCommand.execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + assertTrue(model.getSuggestions().size() == 0); + } + + @Test + public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { + model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103t.getStringRepresentation()); + OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, + toCs2103t.getStringRepresentation()); + openSuggestionCommand.execute(model); List suggestions = model.getSuggestions(); - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, true); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions); } @Test public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - OpenSuggestionCommand openSuggestionCommand = - new OpenSuggestionCommand(toCs2103, toCs2103.getStringRepresentation()); + model.setInput(COMMAND_WORD + " " + toCs2103t.getStringRepresentation()); + OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, + toCs2103t.getStringRepresentation()); openSuggestionCommand.execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); - List suggestions = model.getSuggestions(); - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, false); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions); } } From 688eecef5b6c103cd95b15c06157549d39755c9d Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 17:15:42 +0800 Subject: [PATCH 10/49] Rename setUpTree method to setUp --- .../logic/commands/suggestion/DeleteSuggestionCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index fc9eadc1627..6586957c133 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -22,7 +22,7 @@ public class DeleteSuggestionCommandTest { private static final String COMMAND_WORD = "delete"; @BeforeAll - public static void setUpTree() { + public static void setUp() { toCs2103t = SuggestionTestUtil.getToCs2103t(); model = SuggestionTestUtil.getModel(); } From 05d1b0f6b9f8aa9cddf2ab51319bb473e3c1f500 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 18:30:35 +0800 Subject: [PATCH 11/49] Fix bug in SearchSugCmd --- .../logic/commands/suggestion/SearchSuggestionCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java index 322d10b10ee..143f64860fc 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java @@ -69,7 +69,8 @@ private List traverseTree(Model model) { and setting action to open that particular block when the user chooses that suggestion. */ String bodyLowerCase = blockBody.toLowerCase(); if (bodyLowerCase.contains(keyword.toLowerCase())) { - String[] blockBodies = bodyLowerCase.split(keyword, -1); + String[] blockBodies = bodyLowerCase.split(keyword.toLowerCase(), -1); + int frequency = blockBodies.length - 1; String displayText = absolutePath.getStringRepresentation(); Runnable action = () -> { From 5edc1fd1ae024a450842d37a9262fae3bd489e3e Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 18:30:48 +0800 Subject: [PATCH 12/49] Update SearchSugCmdTest --- .../SearchSuggestionCommandTest.java | 90 +++++-------------- 1 file changed, 21 insertions(+), 69 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java index f7773c01255..f18717a8e44 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java @@ -10,76 +10,24 @@ import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.commons.path.exceptions.InvalidPathException; +import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Body; -import com.notably.model.block.Title; import com.notably.model.suggestion.SuggestionItem; import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; +import com.notably.testutil.TypicalBlockModel; public class SearchSuggestionCommandTest { - private static AbsolutePath toRoot; - private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; private static Model model; - private static Body toCs2103Week1LectureBody = new Body("Week 1 is ezpz. I am falling asleep."); - private static Body toCs2103Week2Body = new Body("I was wrong. This mod is so time consuming"); - private static Body toCs2103Week3Body = new Body("Will I fail this mod?"); - private static Body toCs3230Body = new Body("I confirm fail this mod. Fail lah fail lah."); private static final String COMMAND_WORD = "search"; @BeforeAll - public static void setUp() throws InvalidPathException { - // Set up paths - toRoot = AbsolutePath.fromString("/"); - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - - // Set up model - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - - // Add test data to model - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230"), toCs3230Body); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2"), toCs2103Week2Body); - Block week3 = new BlockImpl(new Title("Week3"), toCs2103Week3Body); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture"), toCs2103Week1LectureBody); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); + public static void setUp() { + model = SuggestionTestUtil.getModel(); } @Test - public void constructor_nullPath_throwsNullPointerException() { + public void constructor_nullKeyword_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> new SearchSuggestionCommand(null)); } @@ -90,20 +38,23 @@ public void execute_nullModel_throwsNullPointerException() { } @Test - public void execute_generateResponseCorrectly() { - SearchSuggestionCommand searchSuggestionCommand = new SearchSuggestionCommand("fail"); + public void execute_generatesResponseCorrectly() { + SearchSuggestionCommand searchSuggestionCommand = new SearchSuggestionCommand("fALsE"); searchSuggestionCommand.execute(model); + List suggestions = model.getSuggestions(); + // Expected suggestions List expectedSuggestions = new ArrayList<>(); - SuggestionItem suggestionItem = new SuggestionItemImpl(toCs3230.getStringRepresentation(), 3, - null); - SuggestionItem suggestionItem1 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), 1, - null); - expectedSuggestions.add(suggestionItem); - expectedSuggestions.add(suggestionItem1); - - List suggestions = model.getSuggestions(); + SuggestionItem cs2103tTut1 = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), 1, null); + SuggestionItem cs2103tTut2 = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), 2, null); + SuggestionItem cs2106Tut1 = new SuggestionItemImpl( + TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1.getStringRepresentation(), 1, null); + expectedSuggestions.add(cs2103tTut1); + expectedSuggestions.add(cs2103tTut2); + expectedSuggestions.add(cs2106Tut1); // Test displayText and frequency for (int i = 0; i < expectedSuggestions.size(); i++) { @@ -115,8 +66,9 @@ public void execute_generateResponseCorrectly() { // Expected currently open paths List expectedCurrentlyOpenPaths = new ArrayList<>(); - expectedCurrentlyOpenPaths.add(toCs3230); - expectedCurrentlyOpenPaths.add(toCs2103Week3); + expectedCurrentlyOpenPaths.add(TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1); + expectedCurrentlyOpenPaths.add(TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2); + expectedCurrentlyOpenPaths.add(TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1); // Test Runnable action and check currentlyOpenPath for (int i = 0; i < expectedCurrentlyOpenPaths.size(); i++) { From 2c450d53786154ecdf8d3f4198097cf4827a021e Mon Sep 17 00:00:00 2001 From: johannagwan Date: Mon, 6 Apr 2020 18:33:35 +0800 Subject: [PATCH 13/49] Remove COMMAND_WORD from SearchSugCmdTest --- .../logic/commands/suggestion/SearchSuggestionCommandTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java index f18717a8e44..b7562d56006 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java @@ -19,8 +19,6 @@ public class SearchSuggestionCommandTest { private static Model model; - private static final String COMMAND_WORD = "search"; - @BeforeAll public static void setUp() { model = SuggestionTestUtil.getModel(); From 93efbdb81ebe1d36c55bff4cf3c9edf9b34c60e2 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Wed, 8 Apr 2020 21:29:00 +0800 Subject: [PATCH 14/49] Fix typo --- .../logic/commands/suggestion/OpenSuggestionCommandTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index 7a286bacb79..71e3ddf7c92 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -22,7 +22,7 @@ public class OpenSuggestionCommandTest { private static final String COMMAND_WORD = "open"; @BeforeAll - public static void setUpTree() { + public static void setUp() { toCs2103t = SuggestionTestUtil.getToCs2103t(); model = SuggestionTestUtil.getModel(); } @@ -30,7 +30,6 @@ public static void setUpTree() { @AfterEach public void clearSuggestions() { model.clearSuggestions(); - System.out.println("inside clear sug"); } @Test From 60a5acd0baa02e1f741e821b21e92d68cd247c1b Mon Sep 17 00:00:00 2001 From: johannagwan Date: Wed, 8 Apr 2020 22:26:29 +0800 Subject: [PATCH 15/49] Update Delete and Open Sug Cmd test --- .../DeleteSuggestionCommandTest.java | 18 ++++--- .../suggestion/OpenSuggestionCommandTest.java | 18 ++++--- .../SuggestionCommandParserTestUtil.java | 20 ------- .../logic/suggestion/SuggestionTestUtil.java | 53 +++++++------------ 4 files changed, 40 insertions(+), 69 deletions(-) delete mode 100644 src/test/java/com/notably/logic/parser/suggestion/SuggestionCommandParserTestUtil.java diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index 6586957c133..475d211e238 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -60,7 +60,8 @@ public void execute_blankOldTitle_generatesEmptySuggestion() { @Test public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103t.getStringRepresentation()); + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + model.setInput(userInputWithoutPath + toCs2103t.getStringRepresentation()); DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, toCs2103t.getStringRepresentation()); deleteSuggestionCommand.execute(model); @@ -68,21 +69,22 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List suggestions = model.getSuggestions(); // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, true); + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions); + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + toCs2103t.getStringRepresentation()); + String userInputWithoutPath = COMMAND_WORD + " "; + model.setInput(userInputWithoutPath + toCs2103t.getStringRepresentation()); DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, toCs2103t.getStringRepresentation()); deleteSuggestionCommand.execute(model); @@ -90,15 +92,15 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List suggestions = model.getSuggestions(); // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, false); + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions); + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } } diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index 71e3ddf7c92..5175c496b37 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -60,7 +60,8 @@ public void execute_blankOldTitle_generatesEmptySuggestion() { @Test public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103t.getStringRepresentation()); + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + model.setInput(userInputWithoutPath + toCs2103t.getStringRepresentation()); OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, toCs2103t.getStringRepresentation()); openSuggestionCommand.execute(model); @@ -68,21 +69,22 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List suggestions = model.getSuggestions(); // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, true); + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions); + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly() { - model.setInput(COMMAND_WORD + " " + toCs2103t.getStringRepresentation()); + String userInputWithoutPath = COMMAND_WORD + " "; + model.setInput(userInputWithoutPath + toCs2103t.getStringRepresentation()); OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, toCs2103t.getStringRepresentation()); openSuggestionCommand.execute(model); @@ -90,15 +92,15 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List suggestions = model.getSuggestions(); // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSuggestionsToCs2103t(); + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsToCs2103t(COMMAND_WORD, false); + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions); + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/SuggestionCommandParserTestUtil.java b/src/test/java/com/notably/logic/parser/suggestion/SuggestionCommandParserTestUtil.java deleted file mode 100644 index e13bb6fec7b..00000000000 --- a/src/test/java/com/notably/logic/parser/suggestion/SuggestionCommandParserTestUtil.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.notably.logic.parser.suggestion; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import com.notably.logic.parser.exceptions.ParseException; - -/** - * Contains helper methods for testing suggestion command parsers. - */ -public class SuggestionCommandParserTestUtil { - /** - * Asserts that the parsing of {@code userInput} by {@code parser} is unsuccessful and the error message - * equals to {@code expectedMessage}. - */ - public static void assertParseFailure(SuggestionCommandParser parser, String userInput, String expectedMessage) { - ParseException exception = assertThrows(ParseException.class, () -> parser.parse(userInput)); - assertEquals(expectedMessage, exception.getMessage()); - } -} diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index d588d4e2202..8473e3d6ebb 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import com.notably.commons.path.AbsolutePath; import com.notably.model.Model; @@ -21,13 +22,11 @@ * Contains helper methods for testing suggestion feature. */ public class SuggestionTestUtil { - private static Model model; - public static Model getModel() { BlockModel blockModel = TypicalBlockModel.getTypicalBlockModel(); SuggestionModel suggestionModel = new SuggestionModelImpl(); ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); + Model model = new ModelManager(blockModel, suggestionModel, viewStateModel); return model; } @@ -36,44 +35,35 @@ public static AbsolutePath getToCs2103t() { return TypicalBlockModel.PATH_TO_CS2103T; } - public static List getExpectedSuggestionsToCs2103t() { + public static List getExpectedSugForCs2103tPathInput() { SuggestionItem cs2103t = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation(), null); + TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation(), () -> {}); SuggestionItem cs2103tLect = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T_LECTURES.getStringRepresentation(), null); + TypicalBlockModel.PATH_TO_CS2103T_LECTURES.getStringRepresentation(), () -> {}); SuggestionItem cs2103tTut = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T_TUTORIALS.getStringRepresentation(), null); + TypicalBlockModel.PATH_TO_CS2103T_TUTORIALS.getStringRepresentation(), () -> {}); SuggestionItem cs2103tTut1 = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), null); + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), () -> {}); SuggestionItem cs2103tTut2 = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), null); + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), () -> {}); - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103t); - expectedSuggestions.add(cs2103tLect); - expectedSuggestions.add(cs2103tTut); - expectedSuggestions.add(cs2103tTut1); - expectedSuggestions.add(cs2103tTut2); + List expectedSuggestions; + SuggestionItem[] items = new SuggestionItem[]{cs2103t, cs2103tLect, cs2103tTut, cs2103tTut1, cs2103tTut2}; + expectedSuggestions = List.of(items); return expectedSuggestions; } - public static List getExpectedInputsToCs2103t(String commandWord, boolean hasPrefixTitle) { + public static List getExpectedInputsForCs2103tPathInput(String userInputWithoutPath) { List expectedInputs = new ArrayList<>(); - String prefix = ""; - - if (hasPrefixTitle) { - prefix = "-t "; - } - expectedInputs.add(commandWord + " " + prefix + TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix - + TypicalBlockModel.PATH_TO_CS2103T_LECTURES.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + expectedInputs.add(userInputWithoutPath + TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation()); + expectedInputs.add(userInputWithoutPath + TypicalBlockModel.PATH_TO_CS2103T_LECTURES.getStringRepresentation()); + expectedInputs.add(userInputWithoutPath + TypicalBlockModel.PATH_TO_CS2103T_TUTORIALS.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + expectedInputs.add(userInputWithoutPath + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation()); - expectedInputs.add(commandWord + " " + prefix + expectedInputs.add(userInputWithoutPath + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation()); return expectedInputs; @@ -85,11 +75,8 @@ public static List getExpectedInputsToCs2103t(String commandWord, boolea * @param suggestions The actual suggestions list. */ public static void testSuggestions(List expectedSuggestions, List suggestions) { - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } + assertEquals(expectedSuggestions.stream().map(s -> s.getProperty("displayText")).collect(Collectors.toList()), + suggestions.stream().map(s -> s.getProperty("displayText")).collect(Collectors.toList())); } /** @@ -97,7 +84,7 @@ public static void testSuggestions(List expectedSuggestions, Lis * @param expectedInputs The expected list of inputs. * @param suggestions The actual suggestions list. */ - public static void testInputs(List expectedInputs, List suggestions) { + public static void testInputs(List expectedInputs, List suggestions, Model model) { for (int i = 0; i < expectedInputs.size(); i++) { SuggestionItem suggestionItem = suggestions.get(i); String expectedInput = expectedInputs.get(i); From b156a155bee9d465a58ac0ca8112f6c5e92f509c Mon Sep 17 00:00:00 2001 From: johannagwan Date: Wed, 8 Apr 2020 23:33:18 +0800 Subject: [PATCH 16/49] Fix typo in response msg From 960faabcb566766a29faeba7aa6a6f1a8c423a26 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Wed, 8 Apr 2020 23:41:10 +0800 Subject: [PATCH 17/49] Update test cases --- .../DeleteSuggestionCommandParserTest.java | 310 +++++------------- .../OpenSuggestionCommandParserTest.java | 42 +-- .../logic/suggestion/SuggestionTestUtil.java | 9 + 3 files changed, 120 insertions(+), 241 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index e258d736d5c..ec5729fb78c 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -16,30 +16,15 @@ import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.correction.AbsolutePathCorrectionEngine; import com.notably.logic.correction.CorrectionEngine; +import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Title; import com.notably.model.suggestion.SuggestionItem; import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; public class DeleteSuggestionCommandParserTest { - private static AbsolutePath toRoot; - private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; - private static Model model; + private static AbsolutePath toCs2103t; private static DeleteSuggestionCommandParser deleteSuggestionCommandParser; + private static Model model; private static final String COMMAND_WORD = "delete"; private static final String RESPONSE_MESSAGE = "Delete a note"; @@ -51,39 +36,9 @@ public class DeleteSuggestionCommandParserTest { @BeforeAll public static void setUp() { - // Set up paths - toRoot = AbsolutePath.fromString("/"); - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - - // Set up model - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - - // Add test data to model - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230")); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2")); - Block week3 = new BlockImpl(new Title("Week3")); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture")); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); - + model = SuggestionTestUtil.getModel(); + toCs2103t = SuggestionTestUtil.getToCs2103t(); + // initialize parser CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); @@ -92,220 +47,135 @@ public static void setUp() { @Test public void parse_correctAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { - String arg = " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation(); - model.setInput(COMMAND_WORD + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); + String arg = userInput.replace(COMMAND_WORD, ""); - commandCorrectPath.get().execute(model); + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"/CS2103\""), - model.responseTextProperty().getValue()); + command.get().execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), + model.responseTextProperty().getValue()); - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } + // Test display text + SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test public void parse_correctAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String arg = toCs2103.getStringRepresentation(); - model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + String userInputWithoutPath = COMMAND_WORD + " "; + String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); + String arg = userInput.replace(COMMAND_WORD, ""); - commandCorrectPath.get().execute(model); + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, arg)), - model.responseTextProperty().getValue()); + command.get().execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), + model.responseTextProperty().getValue()); - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } + // Test display text + SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test public void parse_correctedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { - String arg = " " + PREFIX_TITLE + " /CS2104"; - model.setInput(COMMAND_WORD + arg); - Optional commandCorrectedPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectedPath.get() instanceof DeleteSuggestionCommand); + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); - commandCorrectedPath.get().execute(model); + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"/CS2104\""), - model.responseTextProperty().getValue()); + command.get().execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } + // Test display text + SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test public void parse_correctedAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String arg = "/CS2104"; - model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); - commandCorrectPath.get().execute(model); + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), - model.responseTextProperty().getValue()); + command.get().execute(model); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } + // Test display text + SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } + /* @Test public void parse_correctRelativePathWithPrefix_returnsDeleteSuggestionCommand() { String arg = " -t Lecture"; model.setInput(COMMAND_WORD + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lecture\""), model.responseTextProperty().getValue()); @@ -343,10 +213,10 @@ public void parse_correctRelativePathWithPrefix_returnsDeleteSuggestionCommand() public void parse_correctRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { String arg = "Lecture"; model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), model.responseTextProperty().getValue()); @@ -384,10 +254,10 @@ public void parse_correctRelativePathWithoutPrefix_returnsDeleteSuggestionComman public void parse_correctedRelativePathWithPrefix_returnsDeleteSuggestionCommand() { String arg = " " + PREFIX_TITLE + " Lectre"; model.setInput(COMMAND_WORD + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lectre\""), model.responseTextProperty().getValue()); @@ -425,10 +295,10 @@ public void parse_correctedRelativePathWithPrefix_returnsDeleteSuggestionCommand public void parse_correctedRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { String arg = "Lectre"; model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = deleteSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof DeleteSuggestionCommand); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), model.responseTextProperty().getValue()); @@ -460,5 +330,5 @@ public void parse_correctedRelativePathWithoutPrefix_returnsDeleteSuggestionComm String input = model.getInput(); assertEquals(expectedInput, input); } - } + }*/ } diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index 8c4d3603e5c..824954655f9 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -94,10 +94,10 @@ public static void setUp() { public void parse_correctAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { String arg = " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation(); model.setInput(COMMAND_WORD + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103.getStringRepresentation())), model.responseTextProperty().getValue()); @@ -146,10 +146,10 @@ public void parse_correctAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { public void parse_correctAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { String arg = toCs2103.getStringRepresentation(); model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), model.responseTextProperty().getValue()); @@ -250,10 +250,10 @@ public void parse_correctedAbsolutePathWithPrefix_returnsOpenSuggestionCommand() public void parse_correctedAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { String arg = "/CS2104"; model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), model.responseTextProperty().getValue()); @@ -302,10 +302,10 @@ public void parse_correctedAbsolutePathWithoutPrefix_returnsOpenSuggestionComman public void parse_correctRelativePathWithPrefix_returnsOpenSuggestionCommand() { String arg = " -t Lecture"; model.setInput(COMMAND_WORD + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lecture\""), model.responseTextProperty().getValue()); @@ -343,10 +343,10 @@ public void parse_correctRelativePathWithPrefix_returnsOpenSuggestionCommand() { public void parse_correctRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { String arg = "Lecture"; model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), model.responseTextProperty().getValue()); @@ -384,10 +384,10 @@ public void parse_correctRelativePathWithoutPrefix_returnsOpenSuggestionCommand( public void parse_correctedRelativePathWithPrefix_returnsOpenSuggestionCommand() { String arg = " " + PREFIX_TITLE + " Lectre"; model.setInput(COMMAND_WORD + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lectre\""), model.responseTextProperty().getValue()); @@ -425,10 +425,10 @@ public void parse_correctedRelativePathWithPrefix_returnsOpenSuggestionCommand() public void parse_correctedRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { String arg = "Lectre"; model.setInput(COMMAND_WORD + " " + arg); - Optional commandCorrectPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectPath.get() instanceof OpenSuggestionCommand); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectPath.get().execute(model); + command.get().execute(model); assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), model.responseTextProperty().getValue()); diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 8473e3d6ebb..e38635baac7 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -93,4 +93,13 @@ public static void testInputs(List expectedInputs, List assertEquals(expectedInput, input); } } + + public static void testDisplayTexts(List expectedSuggestions, List suggestions, + Model model) { + for (int i = 0; i < expectedSuggestions.size(); i++) { + SuggestionItem suggestion = suggestions.get(i); + SuggestionItem expectedSuggestion = expectedSuggestions.get(i); + assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); + } + } } From c0c66ce41ad4dfd3487f16165ab3a1ff79bd3c1a Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 01:40:59 +0800 Subject: [PATCH 18/49] Fix checkstyle --- .../DeleteSuggestionCommandParserTest.java | 4 +--- .../logic/suggestion/SuggestionTestUtil.java | 24 +++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index ec5729fb78c..022a4e4d470 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -19,7 +18,6 @@ import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; import com.notably.model.suggestion.SuggestionItem; -import com.notably.model.suggestion.SuggestionItemImpl; public class DeleteSuggestionCommandParserTest { private static AbsolutePath toCs2103t; @@ -38,7 +36,7 @@ public class DeleteSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); toCs2103t = SuggestionTestUtil.getToCs2103t(); - + // initialize parser CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index e38635baac7..160cc5627ff 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -71,8 +71,9 @@ public static List getExpectedInputsForCs2103tPathInput(String userInput /** * Checks the correctness of the suggestions. + * * @param expectedSuggestions The expected suggestions list. - * @param suggestions The actual suggestions list. + * @param suggestions The actual list of suggestions. */ public static void testSuggestions(List expectedSuggestions, List suggestions) { assertEquals(expectedSuggestions.stream().map(s -> s.getProperty("displayText")).collect(Collectors.toList()), @@ -81,8 +82,10 @@ public static void testSuggestions(List expectedSuggestions, Lis /** * Checks the correctness of the input stored in CommandInputModel for each suggestion. + * * @param expectedInputs The expected list of inputs. - * @param suggestions The actual suggestions list. + * @param suggestions The actual list of suggestions. + * @param model The app's model. */ public static void testInputs(List expectedInputs, List suggestions, Model model) { for (int i = 0; i < expectedInputs.size(); i++) { @@ -94,12 +97,19 @@ public static void testInputs(List expectedInputs, List } } + /** + * Checks the correctness of the display text of a suggestion. + * + * @param expectedSuggestions The expected list of suggestions. + * @param suggestions The actual list of suggestions. + * @param model The app's model. + */ public static void testDisplayTexts(List expectedSuggestions, List suggestions, Model model) { - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } + for (int i = 0; i < expectedSuggestions.size(); i++) { + SuggestionItem suggestion = suggestions.get(i); + SuggestionItem expectedSuggestion = expectedSuggestions.get(i); + assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); + } } } From 9ae61a7ece9ae4d13524818a28b947d09f7f0db9 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:18:19 +0800 Subject: [PATCH 19/49] Modify RESPONSE_MESSAGE_CANNOT_DELETE_NOTE From 595f1fc67ae6f55a182c75109c66fc7aa5076c90 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:18:38 +0800 Subject: [PATCH 20/49] Update DeleteSugCmdParserTest --- .../DeleteSuggestionCommandParserTest.java | 267 +++++++++--------- .../logic/suggestion/SuggestionTestUtil.java | 3 + 2 files changed, 138 insertions(+), 132 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 022a4e4d470..947fb42d0b1 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -24,6 +24,7 @@ public class DeleteSuggestionCommandParserTest { private static DeleteSuggestionCommandParser deleteSuggestionCommandParser; private static Model model; + private static final String RELATIVE_PATH_TO_CS2103T = "CS2103T"; private static final String COMMAND_WORD = "delete"; private static final String RESPONSE_MESSAGE = "Delete a note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; @@ -44,7 +45,7 @@ public static void setUp() { } @Test - public void parse_correctAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { + public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); String arg = userInput.replace(COMMAND_WORD, ""); @@ -61,10 +62,11 @@ public void parse_correctAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // Test display text - SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); @@ -74,10 +76,10 @@ public void parse_correctAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() } @Test - public void parse_correctAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = COMMAND_WORD + " "; + public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele "; String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = userInput.replace("dele", ""); model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -91,10 +93,11 @@ public void parse_correctAbsolutePathWithoutPrefix_returnsDeleteSuggestionComman // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // Test display text - SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); @@ -104,10 +107,9 @@ public void parse_correctAbsolutePathWithoutPrefix_returnsDeleteSuggestionComman } @Test - public void parse_correctedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { + public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; - String path = "/Y2S2/CS2104"; - String userInput = userInputWithoutPath + path; + String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; String arg = userInput.replace(COMMAND_WORD, ""); model.setInput(userInput); @@ -116,16 +118,17 @@ public void parse_correctedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // Test display text - SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); @@ -135,11 +138,10 @@ public void parse_correctedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand } @Test - public void parse_correctedAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = COMMAND_WORD + " "; - String path = "/Y2S2/CS2104"; - String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); + public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele "; + String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String arg = userInput.replace("dele", ""); model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -147,16 +149,17 @@ public void parse_correctedAbsolutePathWithoutPrefix_returnsDeleteSuggestionComm command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // Test display text - SuggestionTestUtil.testDisplayTexts(expectedSuggestions, suggestions, model); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); @@ -165,168 +168,168 @@ public void parse_correctedAbsolutePathWithoutPrefix_returnsDeleteSuggestionComm SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } - /* @Test - public void parse_correctRelativePathWithPrefix_returnsDeleteSuggestionCommand() { - String arg = " -t Lecture"; - model.setInput(COMMAND_WORD + arg); + public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace("dele", ""); + + model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof DeleteSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lecture\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String arg = "Lecture"; - model.setInput(COMMAND_WORD + " " + arg); + public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof DeleteSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctedRelativePathWithPrefix_returnsDeleteSuggestionCommand() { - String arg = " " + PREFIX_TITLE + " Lectre"; - model.setInput(COMMAND_WORD + arg); + public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; + String path = "CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace("dele", ""); + + model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof DeleteSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lectre\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctedRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String arg = "Lectre"; - model.setInput(COMMAND_WORD + " " + arg); + public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof DeleteSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } - }*/ + @Test + public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "dele"; + String path = ""; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + } + + @Test + public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { + String path = "random"; + String userInput = COMMAND_WORD + " " + path; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + } + + @Test + public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { + String path = "!!!"; + String userInput = "dele " + path; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), + model.responseTextProperty().getValue()); + } } diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 160cc5627ff..7e9135706d9 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -96,6 +96,7 @@ public static void testInputs(List expectedInputs, List assertEquals(expectedInput, input); } } +<<<<<<< HEAD /** * Checks the correctness of the display text of a suggestion. @@ -112,4 +113,6 @@ public static void testDisplayTexts(List expectedSuggestions, Li assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); } } +======= +>>>>>>> 098b188c... Update DeleteSugCmdParserTest } From 63ebf2b2d0db97905df7fd3ba1eb168765e2121b Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:32:39 +0800 Subject: [PATCH 21/49] Update OpenSugCmdParserTest --- .../DeleteSuggestionCommandParser.java | 4 + .../DeleteSuggestionCommandParserTest.java | 2 +- .../OpenSuggestionCommandParserTest.java | 513 +++++++----------- 3 files changed, 197 insertions(+), 322 deletions(-) diff --git a/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java b/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java index 268537506b9..45842876331 100644 --- a/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java +++ b/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java @@ -23,7 +23,11 @@ public class DeleteSuggestionCommandParser implements SuggestionCommandParser>>>>>> 84b9cf35... Update OpenSugCmdParserTest private Model model; private CorrectionEngine pathCorrectionEngine; diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 947fb42d0b1..bafff9e53c0 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -329,7 +329,7 @@ public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(path); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), + assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, path)), model.responseTextProperty().getValue()); } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index 824954655f9..a08805b2ff9 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -16,73 +15,28 @@ import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.correction.AbsolutePathCorrectionEngine; import com.notably.logic.correction.CorrectionEngine; +import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Title; import com.notably.model.suggestion.SuggestionItem; -import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; public class OpenSuggestionCommandParserTest { - private static AbsolutePath toRoot; - private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; - private static Model model; + private static AbsolutePath toCs2103t; private static OpenSuggestionCommandParser openSuggestionCommandParser; + private static Model model; + private static final String RELATIVE_PATH_TO_CS2103T = "CS2103T"; private static final String COMMAND_WORD = "open"; private static final String RESPONSE_MESSAGE = "Open a note"; + private static final String RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; + private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "\"%s\" is an invalid path"; private static final int CORRECTION_THRESHOLD = 2; private static final boolean USE_FORWARD_MATCHING = true; - private static final String RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; - @BeforeAll public static void setUp() { - // Set up paths - toRoot = AbsolutePath.fromString("/"); - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - - // Set up model - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - - // Add test data to model - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230")); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2")); - Block week3 = new BlockImpl(new Title("Week3")); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture")); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); + model = SuggestionTestUtil.getModel(); + toCs2103t = SuggestionTestUtil.getToCs2103t(); // initialize parser CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, @@ -91,374 +45,291 @@ public static void setUp() { } @Test - public void parse_correctAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { - String arg = " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation(); - model.setInput(COMMAND_WORD + arg); + public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103.getStringRepresentation())), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), model.responseTextProperty().getValue()); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { - String arg = toCs2103.getStringRepresentation(); - model.setInput(COMMAND_WORD + " " + arg); + public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = "op "; + String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); + String arg = userInput.replace("op", ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), model.responseTextProperty().getValue()); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctedAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { - String arg = " " + PREFIX_TITLE + " /CS2104"; - model.setInput(COMMAND_WORD + arg); - Optional commandCorrectedPath = openSuggestionCommandParser.parse(arg); - assertTrue(commandCorrectedPath.get() instanceof OpenSuggestionCommand); + public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof OpenSuggestionCommand); - commandCorrectedPath.get().execute(model); + command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"/CS2104\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctedAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { - String arg = "/CS2104"; - model.setInput(COMMAND_WORD + " " + arg); + public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = "op "; + String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String arg = userInput.replace("op", ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); - // Expected result - SuggestionItem cs2103 = new SuggestionItemImpl(toCs2103.getStringRepresentation(), null); - SuggestionItem cs2103Week1 = new SuggestionItemImpl(toCs2103Week1.getStringRepresentation(), null); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - SuggestionItem cs2103Week2 = new SuggestionItemImpl(toCs2103Week2.getStringRepresentation(), null); - SuggestionItem cs2103Week3 = new SuggestionItemImpl(toCs2103Week3.getStringRepresentation(), null); - - List expectedSuggestions = new ArrayList<>(); - expectedSuggestions.add(cs2103); - expectedSuggestions.add(cs2103Week1); - expectedSuggestions.add(cs2103Week2); - expectedSuggestions.add(cs2103Week3); - expectedSuggestions.add(cs2103Week1Lecture); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + // Actual suggestions List suggestions = model.getSuggestions(); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week2.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week3.getStringRepresentation()); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctRelativePathWithPrefix_returnsOpenSuggestionCommand() { - String arg = " -t Lecture"; - model.setInput(COMMAND_WORD + arg); + public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = "op " + PREFIX_TITLE + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace("op", ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lecture\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { - String arg = "Lecture"; - model.setInput(COMMAND_WORD + " " + arg); + public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctedRelativePathWithPrefix_returnsOpenSuggestionCommand() { - String arg = " " + PREFIX_TITLE + " Lectre"; - model.setInput(COMMAND_WORD + arg); + public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = "op " + PREFIX_TITLE + " "; + String path = "CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace("op", ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"Lectre\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + PREFIX_TITLE + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @Test - public void parse_correctedRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { - String arg = "Lectre"; - model.setInput(COMMAND_WORD + " " + arg); + public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); assertTrue(command.get() instanceof OpenSuggestionCommand); command.get().execute(model); - assertEquals(Optional.of(RESPONSE_MESSAGE + " titled \"" + arg + "\""), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - //Expected result - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - List expectedSuggestions = new ArrayList<>(); + // Actual suggestions + List suggestions = model.getSuggestions(); - expectedSuggestions.add(cs2103Week1Lecture); + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - List suggestions = model.getSuggestions(); + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // check display text - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add(COMMAND_WORD + " " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "op"; + String path = ""; + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + } + + @Test + public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { + String path = "random"; + String userInput = COMMAND_WORD + " " + path; + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + } + + @Test + public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { + String path = "!!!"; + String userInput = "op " + path; + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), + model.responseTextProperty().getValue()); } } From 0d4e86701396502e4e6107ed92b149405f2970ee Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:41:59 +0800 Subject: [PATCH 22/49] Remove ParseException from NewSugCmdParser --- .../NewSuggestionCommandParser.java | 2 - .../EditSuggestionCommandParserTest.java | 335 ++++++++++++++++++ 2 files changed, 335 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java diff --git a/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java b/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java index 84d79c173c5..5657fa2cd5c 100644 --- a/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java +++ b/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java @@ -9,7 +9,6 @@ import com.notably.logic.parser.ArgumentMultimap; import com.notably.logic.parser.ArgumentTokenizer; import com.notably.logic.parser.ParserUtil; -import com.notably.logic.parser.exceptions.ParseException; import com.notably.model.Model; import com.notably.model.block.Title; @@ -36,7 +35,6 @@ public NewSuggestionCommandParser(Model model) { * Parses input and displays the appropriate response text. * @param userInput . * @return List of command to execute. - * @throws ParseException when input is invalid. */ public Optional parse(String userInput) { ArgumentMultimap argMultimap = diff --git a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java new file mode 100644 index 00000000000..9323a41342d --- /dev/null +++ b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java @@ -0,0 +1,335 @@ +package com.notably.logic.parser.suggestion; + +import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.notably.commons.path.AbsolutePath; +import com.notably.logic.commands.suggestion.DeleteSuggestionCommand; +import com.notably.logic.commands.suggestion.SuggestionCommand; +import com.notably.logic.correction.AbsolutePathCorrectionEngine; +import com.notably.logic.correction.CorrectionEngine; +import com.notably.logic.suggestion.SuggestionTestUtil; +import com.notably.model.Model; +import com.notably.model.suggestion.SuggestionItem; + +public class DeleteSuggestionCommandParserTest { + private static AbsolutePath toCs2103t; + private static DeleteSuggestionCommandParser deleteSuggestionCommandParser; + private static Model model; + + private static final String RELATIVE_PATH_TO_CS2103T = "CS2103T"; + private static final String COMMAND_WORD = "delete"; + private static final String RESPONSE_MESSAGE = "Delete a note"; + private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; + private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "\"%s\" is an invalid path"; + + private static final int CORRECTION_THRESHOLD = 2; + private static final boolean USE_FORWARD_MATCHING = true; + + @BeforeAll + public static void setUp() { + model = SuggestionTestUtil.getModel(); + toCs2103t = SuggestionTestUtil.getToCs2103t(); + + // initialize parser + CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, + CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); + deleteSuggestionCommandParser = new DeleteSuggestionCommandParser(model, pathCorrectionEngine); + } + + @Test + public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele "; + String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); + String arg = userInput.replace("dele", ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; + String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele "; + String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String arg = userInput.replace("dele", ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace("dele", ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "/Y2S2/CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; + String path = "CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace("dele", ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { + String userInputWithoutPath = COMMAND_WORD + " "; + String path = "CS2104"; + String userInput = userInputWithoutPath + path; + String arg = userInput.replace(COMMAND_WORD, ""); + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(arg); + assertTrue(command.get() instanceof DeleteSuggestionCommand); + + command.get().execute(model); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Actual suggestions + List suggestions = model.getSuggestions(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Expected inputs + List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); + + // Test inputs + SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + } + + @Test + public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "dele"; + String path = ""; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + } + + @Test + public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { + String path = "random"; + String userInput = COMMAND_WORD + " " + path; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + } + + @Test + public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { + String path = "!!!"; + String userInput = "dele " + path; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), + model.responseTextProperty().getValue()); + } +} From 05376046a5dfd56561ce25fde98664a14d3f03d0 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:42:12 +0800 Subject: [PATCH 23/49] Add EditSugCmdParserTest --- .../EditSuggestionCommandParserTest.java | 309 +----------------- 1 file changed, 7 insertions(+), 302 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java index 9323a41342d..4e4a66310e4 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java @@ -1,37 +1,23 @@ package com.notably.logic.parser.suggestion; -import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.logic.commands.suggestion.DeleteSuggestionCommand; import com.notably.logic.commands.suggestion.SuggestionCommand; -import com.notably.logic.correction.AbsolutePathCorrectionEngine; -import com.notably.logic.correction.CorrectionEngine; import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; -import com.notably.model.suggestion.SuggestionItem; -public class DeleteSuggestionCommandParserTest { +public class EditSuggestionCommandParserTest { private static AbsolutePath toCs2103t; - private static DeleteSuggestionCommandParser deleteSuggestionCommandParser; + private static EditSuggestionCommandParser editSuggestionCommandParser; private static Model model; - private static final String RELATIVE_PATH_TO_CS2103T = "CS2103T"; - private static final String COMMAND_WORD = "delete"; - private static final String RESPONSE_MESSAGE = "Delete a note"; - private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; - private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "\"%s\" is an invalid path"; - - private static final int CORRECTION_THRESHOLD = 2; - private static final boolean USE_FORWARD_MATCHING = true; + private static final String RESPONSE_MESSAGE = "Edit this note"; @BeforeAll public static void setUp() { @@ -39,297 +25,16 @@ public static void setUp() { toCs2103t = SuggestionTestUtil.getToCs2103t(); // initialize parser - CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, - CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); - deleteSuggestionCommandParser = new DeleteSuggestionCommandParser(model, pathCorrectionEngine); - } - - @Test - public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; - String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace(COMMAND_WORD, ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = "dele "; - String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace("dele", ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; - String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; - String arg = userInput.replace(COMMAND_WORD, ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = "dele "; - String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; - String arg = userInput.replace("dele", ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; - String path = "/Y2S2/CS2104"; - String userInput = userInputWithoutPath + path; - String arg = userInput.replace("dele", ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = COMMAND_WORD + " "; - String path = "/Y2S2/CS2104"; - String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + editSuggestionCommandParser = new EditSuggestionCommandParser(model); } @Test - public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; - String path = "CS2104"; - String userInput = userInputWithoutPath + path; - String arg = userInput.replace("dele", ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + public void parse() { + String arg = ""; - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = COMMAND_WORD + " "; - String path = "CS2104"; - String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); - - command.get().execute(model); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - // Expected suggestions - List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions - List suggestions = model.getSuggestions(); - - // Test suggestions - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - - // Expected inputs - List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); - } - - @Test - public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { - String userInput = "dele"; - String path = ""; - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(path); + Optional command = editSuggestionCommandParser.parse(arg); assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); } - - @Test - public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { - String path = "random"; - String userInput = COMMAND_WORD + " " + path; - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(path); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - } - - @Test - public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { - String path = "!!!"; - String userInput = "dele " + path; - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(path); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), - model.responseTextProperty().getValue()); - } } From 2ce7ee8fb876c0ad3fbe0826cbd4fe800438f54e Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:46:57 +0800 Subject: [PATCH 24/49] Update EditSugCmdParserTest --- .../parser/suggestion/EditSuggestionCommandParserTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java index 4e4a66310e4..dfec9d24117 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java @@ -7,13 +7,11 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import com.notably.commons.path.AbsolutePath; import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; public class EditSuggestionCommandParserTest { - private static AbsolutePath toCs2103t; private static EditSuggestionCommandParser editSuggestionCommandParser; private static Model model; @@ -22,7 +20,6 @@ public class EditSuggestionCommandParserTest { @BeforeAll public static void setUp() { model = SuggestionTestUtil.getModel(); - toCs2103t = SuggestionTestUtil.getToCs2103t(); // initialize parser editSuggestionCommandParser = new EditSuggestionCommandParser(model); From 6a7dd465f55bb2efd740c2b4b5ef9576669b8f40 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:52:24 +0800 Subject: [PATCH 25/49] Add ErrorSugCmdParserTest --- .../ErrorSuggestionCommandParserTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java diff --git a/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java new file mode 100644 index 00000000000..9ff71661e27 --- /dev/null +++ b/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java @@ -0,0 +1,38 @@ +package com.notably.logic.parser.suggestion; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.notably.logic.commands.suggestion.SuggestionCommand; +import com.notably.logic.suggestion.SuggestionTestUtil; +import com.notably.model.Model; + +public class ErrorSuggestionCommandParserTest { + private static ErrorSuggestionCommandParser errorSuggestionCommandParser; + private static Model model; + + private static final String ERROR_MESSAGE = "\"%s\" is an invalid command format. " + + "To see the list of available commands, type: help"; + + @BeforeAll + public static void setUp() { + model = SuggestionTestUtil.getModel(); + + // initialize parser + errorSuggestionCommandParser = new ErrorSuggestionCommandParser(model); + } + + @Test + public void parse() { + String arg = "opensesame"; + + Optional command = errorSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(String.format(ERROR_MESSAGE, arg)), + model.responseTextProperty().getValue()); + } +} From 3deeb70ea7c07c371c453e480e410fba6fece937 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:54:29 +0800 Subject: [PATCH 26/49] Add ExitSugCmdParserTest --- .../ExitSuggestionCommandParserTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java diff --git a/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java new file mode 100644 index 00000000000..7e854d682f6 --- /dev/null +++ b/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java @@ -0,0 +1,37 @@ +package com.notably.logic.parser.suggestion; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.notably.logic.commands.suggestion.SuggestionCommand; +import com.notably.logic.suggestion.SuggestionTestUtil; +import com.notably.model.Model; + +public class ExitSuggestionCommandParserTest { + private static ExitSuggestionCommandParser exitSuggestionCommandParser; + private static Model model; + + private static final String RESPONSE_MESSAGE = "Exit the application"; + + @BeforeAll + public static void setUp() { + model = SuggestionTestUtil.getModel(); + + // initialize parser + exitSuggestionCommandParser = new ExitSuggestionCommandParser(model); + } + + @Test + public void parse() { + String arg = ""; + + Optional command = exitSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + } +} From 83b7d2284a4411247e8de3e2d3e36b5e34558b8e Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 03:56:02 +0800 Subject: [PATCH 27/49] Add HelpSugCmdParserTest --- .../HelpSuggestionCommandParserTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java diff --git a/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java new file mode 100644 index 00000000000..00a28cb64bf --- /dev/null +++ b/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java @@ -0,0 +1,37 @@ +package com.notably.logic.parser.suggestion; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.notably.logic.commands.suggestion.SuggestionCommand; +import com.notably.logic.suggestion.SuggestionTestUtil; +import com.notably.model.Model; + +public class HelpSuggestionCommandParserTest { + private static HelpSuggestionCommandParser helpSuggestionCommandParser; + private static Model model; + + private static final String RESPONSE_MESSAGE = "Display a list of available commands"; + + @BeforeAll + public static void setUp() { + model = SuggestionTestUtil.getModel(); + + // initialize parser + helpSuggestionCommandParser = new HelpSuggestionCommandParser(model); + } + + @Test + public void parse() { + String arg = ""; + + Optional command = helpSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + } +} From fd6c20896182964e4d726485a4114ae3c40926fc Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 04:28:03 +0800 Subject: [PATCH 28/49] Add checking for optional empty --- .../DeleteSuggestionCommandParserTest.java | 6 +++ .../NewSuggestionCommandParserTest.java | 37 +++++++++++++++++++ .../OpenSuggestionCommandParserTest.java | 6 +++ 3 files changed, 49 insertions(+) create mode 100644 src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index bafff9e53c0..515af1217e8 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -2,6 +2,7 @@ import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; @@ -306,6 +307,8 @@ public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); } @Test @@ -319,6 +322,7 @@ public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); + assertFalse(command.isPresent()); } @Test @@ -331,5 +335,7 @@ public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, path)), model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java new file mode 100644 index 00000000000..dfec9d24117 --- /dev/null +++ b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java @@ -0,0 +1,37 @@ +package com.notably.logic.parser.suggestion; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import com.notably.logic.commands.suggestion.SuggestionCommand; +import com.notably.logic.suggestion.SuggestionTestUtil; +import com.notably.model.Model; + +public class EditSuggestionCommandParserTest { + private static EditSuggestionCommandParser editSuggestionCommandParser; + private static Model model; + + private static final String RESPONSE_MESSAGE = "Edit this note"; + + @BeforeAll + public static void setUp() { + model = SuggestionTestUtil.getModel(); + + // initialize parser + editSuggestionCommandParser = new EditSuggestionCommandParser(model); + } + + @Test + public void parse() { + String arg = ""; + + Optional command = editSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + } +} diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index a08805b2ff9..d7dafef3f1c 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -2,6 +2,7 @@ import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; @@ -306,6 +307,8 @@ public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); } @Test @@ -319,6 +322,7 @@ public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); + assertFalse(command.isPresent()); } @Test @@ -331,5 +335,7 @@ public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); } } From 30e812d342e1d056d061c4688b84c849f2a38da3 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 04:51:11 +0800 Subject: [PATCH 29/49] Update SugEngineImplTest --- .../suggestion/SuggestionEngineImplTest.java | 212 +----------------- 1 file changed, 5 insertions(+), 207 deletions(-) diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java index 84382b31997..859c9fe9df5 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java @@ -3,74 +3,21 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.util.ArrayList; -import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import com.notably.commons.path.AbsolutePath; import com.notably.commons.path.exceptions.InvalidPathException; import com.notably.model.Model; -import com.notably.model.ModelManager; -import com.notably.model.block.Block; -import com.notably.model.block.BlockImpl; -import com.notably.model.block.BlockModel; -import com.notably.model.block.BlockModelImpl; -import com.notably.model.block.Title; -import com.notably.model.suggestion.SuggestionItem; -import com.notably.model.suggestion.SuggestionItemImpl; -import com.notably.model.suggestion.SuggestionModel; -import com.notably.model.suggestion.SuggestionModelImpl; -import com.notably.model.viewstate.ViewStateModel; -import com.notably.model.viewstate.ViewStateModelImpl; public class SuggestionEngineImplTest { - private static AbsolutePath toRoot; - private static AbsolutePath toCs2103; - private static AbsolutePath toCs3230; - private static AbsolutePath toCs2103Week1; - private static AbsolutePath toCs2103Week2; - private static AbsolutePath toCs2103Week3; - private static AbsolutePath toCs2103Week1Lecture; private static Model model; private static SuggestionEngine suggestionEngine; @BeforeAll public static void setUp() throws InvalidPathException { - // Set up paths - toRoot = AbsolutePath.fromString("/"); - toCs2103 = AbsolutePath.fromString("/CS2103"); - toCs3230 = AbsolutePath.fromString("/CS3230"); - toCs2103Week1 = AbsolutePath.fromString("/CS2103/Week1"); - toCs2103Week2 = AbsolutePath.fromString("/CS2103/Week2"); - toCs2103Week3 = AbsolutePath.fromString("/CS2103/Week3"); - toCs2103Week1Lecture = AbsolutePath.fromString("/CS2103/Week1/Lecture"); - - // Set up model - BlockModel blockModel = new BlockModelImpl(); - SuggestionModel suggestionModel = new SuggestionModelImpl(); - ViewStateModel viewStateModel = new ViewStateModelImpl(); - model = new ModelManager(blockModel, suggestionModel, viewStateModel); - - // Add test data to model - Block cs2103 = new BlockImpl(new Title("CS2103")); - Block cs3230 = new BlockImpl(new Title("CS3230")); - model.addBlockToCurrentPath(cs2103); - model.addBlockToCurrentPath(cs3230); - - Block week1 = new BlockImpl(new Title("Week1")); - Block week2 = new BlockImpl(new Title("Week2")); - Block week3 = new BlockImpl(new Title("Week3")); - model.setCurrentlyOpenBlock(toCs2103); - model.addBlockToCurrentPath(week1); - model.addBlockToCurrentPath(week2); - model.addBlockToCurrentPath(week3); - - Block lecture = new BlockImpl(new Title("Lecture")); - model.setCurrentlyOpenBlock(toCs2103Week1); - model.addBlockToCurrentPath(lecture); + model = SuggestionTestUtil.getModel(); // Set up SuggestionEngine suggestionEngine = new SuggestionEngineImpl(model); @@ -88,157 +35,8 @@ public void suggest_inputLengthTooShort_suggestionsAndResponseTextCleared() { } @Test - public void suggest_correctDeleteCommandValidArgs_returnsDeleteSuggestionCommand() { - String title = "Lecture"; - model.setInput("delete -t " + title); - - // Test response text - String expectedResponseText = "Delete a note titled \"" + title + "\""; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - - // Expected result - List expectedSuggestions = new ArrayList<>(); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - expectedSuggestions.add(cs2103Week1Lecture); - - List suggestions = model.getSuggestions(); - - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add("delete -t " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } - - } - - @Test - public void suggest_correctDeleteCommandInvalidArgs_returnsErrorSuggestionCommand() { - String title = "CS2222"; - model.setInput("delete " + title); - - // Expected result - String expectedResponseText = "Delete a note titled \"" + title + "\""; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - } - - @Test - public void suggest_correctedDeleteCommandValidArgs_returnsDeleteSuggestionCommand() { - String title = "Lecture"; - model.setInput("dele -t " + title); - - // Test response text - String expectedResponseText = "Delete a note titled \"" + title + "\""; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - - // Expected result - List expectedSuggestions = new ArrayList<>(); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - expectedSuggestions.add(cs2103Week1Lecture); - - List suggestions = model.getSuggestions(); - - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add("dele -t " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } - - } - - @Test - public void suggest_correctedDeleteCommandInvalidArgs_returnsErrorSuggestionCommand() { - String title = "CS2222"; - model.setInput("dele -t " + title); - - // Expected result - String expectedResponseText = "Delete a note titled \"" + title + "\""; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - } - - @Test - public void suggest_correctedOpenCommandValidArgs_returnsOpenSuggestionCommand() { - String title = "Lecture"; - model.setInput("oen -t " + title); - - // Test response text - String expectedResponseText = "Open a note titled \"" + title + "\""; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - - // Expected result - List expectedSuggestions = new ArrayList<>(); - SuggestionItem cs2103Week1Lecture = new SuggestionItemImpl(toCs2103Week1Lecture.getStringRepresentation(), - null); - expectedSuggestions.add(cs2103Week1Lecture); - - List suggestions = model.getSuggestions(); - - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - - List expectedInputs = new ArrayList<>(); - expectedInputs.add("oen -t " + toCs2103Week1Lecture.getStringRepresentation()); - - for (int i = 0; i < expectedInputs.size(); i++) { - SuggestionItem suggestionItem = suggestions.get(i); - String expectedInput = expectedInputs.get(i); - suggestionItem.getAction().run(); - String input = model.getInput(); - assertEquals(expectedInput, input); - } - - } - - @Test - public void suggest_correctedOpenCommandInvalidArgs_returnsErrorSuggestionCommand() { - String title = "CS2222"; - model.setInput("opn -t " + title); - - // Expected result - String expectedResponseText = "Open a note titled \"" + title + "\""; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - } - - @Test - public void suggest_correctedNewCommand_returnsNewSuggestionCommand() { - String responseText = "Create a new note titled \"%s\"."; - String title = "NewNote"; - model.setInput("nw -t " + title); - - // Expected result - String expectedResponseText = String.format(responseText, title); - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); - } - - @Test - public void suggest_correctedEditCommand_returnsEditSuggestionCommand() { - model.setInput("edt -t NewNote -b lorem ipsum"); + public void suggest_correctedEditCommand() { + model.setInput("edt"); // Expected result String expectedResponseText = "Edit this note"; @@ -246,7 +44,7 @@ public void suggest_correctedEditCommand_returnsEditSuggestionCommand() { } @Test - public void suggest_correctedHelpCommand_returnsHelpSuggestionCommand() { + public void suggest_correctedHelpCommand() { model.setInput("hAlp"); // Expected result @@ -255,7 +53,7 @@ public void suggest_correctedHelpCommand_returnsHelpSuggestionCommand() { } @Test - public void suggest_correctedExitCommand_returnsExitSuggestionCommand() { + public void suggest_correctedExitCommand() { model.setInput("ex"); // Expected result From 45fac9eeddd9d95a5ec7096136e0317abb349155 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 05:01:20 +0800 Subject: [PATCH 30/49] Add NewSugCmdParserTest --- .../NewSuggestionCommandParserTest.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java index dfec9d24117..6df1d8ee624 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java @@ -1,37 +1,38 @@ package com.notably.logic.parser.suggestion; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.Optional; - import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; -public class EditSuggestionCommandParserTest { - private static EditSuggestionCommandParser editSuggestionCommandParser; +public class NewSuggestionCommandParserTest { + private static NewSuggestionCommandParser newSuggestionCommandParser; private static Model model; - private static final String RESPONSE_MESSAGE = "Edit this note"; + private static final String RESPONSE_MESSAGE = "Create a new note"; + private static final String RESPONSE_MESSAGE_WITH_TITLE = "Create a new note titled \"%s\"."; + private static final String RESPONSE_MESSAGE_WITH_TITLE_AND_OPEN = "Create a new note titled \"%s\" and open it."; + private static final String ERROR_MESSAGE = "\"%s\" is an invalid command format. " + + "The correct format is \"new -t TITLE [-b BODY] [-o]\""; + private static final String ERROR_MESSAGE_INVALID_TITLE = "Title \"%s\" is invalid. " + + "Titles should only contain alphanumeric characters"; @BeforeAll public static void setUp() { model = SuggestionTestUtil.getModel(); // initialize parser - editSuggestionCommandParser = new EditSuggestionCommandParser(model); + newSuggestionCommandParser = new NewSuggestionCommandParser(model); } + /* @Test public void parse() { String arg = ""; - Optional command = editSuggestionCommandParser.parse(arg); + Optional command = newSuggestionCommandParser.parse(arg); assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); - } + }*/ } From 841a02a492a44b83e45d8ab5cb26857cf53629e0 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 21:12:59 +0800 Subject: [PATCH 31/49] Change test case for invalid path --- .../parser/suggestion/DeleteSuggestionCommandParserTest.java | 2 +- .../parser/suggestion/OpenSuggestionCommandParserTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 515af1217e8..7484441d257 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -327,7 +327,7 @@ public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { @Test public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { - String path = "!!!"; + String path = "-"; String userInput = "dele " + path; model.setInput(userInput); diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index d7dafef3f1c..e9909c758dd 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -327,7 +327,7 @@ public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { @Test public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { - String path = "!!!"; + String path = "-"; String userInput = "op " + path; model.setInput(userInput); From fbc9de3d45f436e7fb42f7db5526766ffdbdbb39 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Thu, 9 Apr 2020 22:47:54 +0800 Subject: [PATCH 32/49] Fix response text in test cases --- .../DeleteSuggestionCommandParser.java | 4 ---- .../DeleteSuggestionCommandParserTest.java | 2 +- .../OpenSuggestionCommandParserTest.java | 2 +- .../logic/suggestion/SuggestionTestUtil.java | 19 ------------------- 4 files changed, 2 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java b/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java index 45842876331..268537506b9 100644 --- a/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java +++ b/src/main/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParser.java @@ -23,11 +23,7 @@ public class DeleteSuggestionCommandParser implements SuggestionCommandParser>>>>>> 84b9cf35... Update OpenSugCmdParserTest private Model model; private CorrectionEngine pathCorrectionEngine; diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 7484441d257..7d509b0f137 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -29,7 +29,7 @@ public class DeleteSuggestionCommandParserTest { private static final String COMMAND_WORD = "delete"; private static final String RESPONSE_MESSAGE = "Delete a note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; - private static final String ERROR_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\". Invalid path."; + private static final String ERROR_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\" as it is an invalid path"; private static final int CORRECTION_THRESHOLD = 2; private static final boolean USE_FORWARD_MATCHING = true; diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index e9909c758dd..3e78c756de1 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -29,7 +29,7 @@ public class OpenSuggestionCommandParserTest { private static final String COMMAND_WORD = "open"; private static final String RESPONSE_MESSAGE = "Open a note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; - private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "\"%s\" is an invalid path"; + private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "Cannot open \"%s\" as it is an invalid path"; private static final int CORRECTION_THRESHOLD = 2; private static final boolean USE_FORWARD_MATCHING = true; diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 7e9135706d9..1a6eb92eab5 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -96,23 +96,4 @@ public static void testInputs(List expectedInputs, List assertEquals(expectedInput, input); } } -<<<<<<< HEAD - - /** - * Checks the correctness of the display text of a suggestion. - * - * @param expectedSuggestions The expected list of suggestions. - * @param suggestions The actual list of suggestions. - * @param model The app's model. - */ - public static void testDisplayTexts(List expectedSuggestions, List suggestions, - Model model) { - for (int i = 0; i < expectedSuggestions.size(); i++) { - SuggestionItem suggestion = suggestions.get(i); - SuggestionItem expectedSuggestion = expectedSuggestions.get(i); - assertEquals(expectedSuggestion.getProperty("displayText"), suggestion.getProperty("displayText")); - } - } -======= ->>>>>>> 098b188c... Update DeleteSugCmdParserTest } From b529e04dc1bc3e5af2aa2a7b3b734bf7c48377eb Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 00:26:13 +0800 Subject: [PATCH 33/49] Add test cases for open and delete sug cmd parser --- .../DeleteSuggestionCommandParserTest.java | 50 +++++++++++++++-- .../OpenSuggestionCommandParserTest.java | 54 ++++++++++++++++--- 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 7d509b0f137..39707af2ccd 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -45,6 +45,34 @@ public static void setUp() { deleteSuggestionCommandParser = new DeleteSuggestionCommandParser(model, pathCorrectionEngine); } + @Test + public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "dele"; + String path = ""; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); + } + + @Test + public void parse_correctCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "delete"; + String path = ""; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); + } + @Test public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; @@ -298,14 +326,14 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg } @Test - public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { - String userInput = "dele"; - String path = ""; + public void parse_correctCmdInvalidPath_returnsOptionalEmpty() { + String path = "-"; + String userInput = COMMAND_WORD + " " + path; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(path); - assertEquals(Optional.of(RESPONSE_MESSAGE), + assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, path)), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); @@ -338,4 +366,18 @@ public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { assertFalse(command.isPresent()); } + + @Test + public void parse_correctedCmdUncorrectedPath_returnsOptionalEmpty() { + String path = "random"; + String userInput = "dele " + path; + + model.setInput(userInput); + Optional command = deleteSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); + } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index 3e78c756de1..b1279a6b85a 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -29,7 +29,7 @@ public class OpenSuggestionCommandParserTest { private static final String COMMAND_WORD = "open"; private static final String RESPONSE_MESSAGE = "Open a note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; - private static final String RESPONSE_MESSAGE_CANNOT_DELETE_NOTE = "Cannot open \"%s\" as it is an invalid path"; + private static final String ERROR_MESSAGE_CANNOT_OPEN_NOTE = "Cannot open \"%s\" as it is an invalid path"; private static final int CORRECTION_THRESHOLD = 2; private static final boolean USE_FORWARD_MATCHING = true; @@ -45,6 +45,34 @@ public static void setUp() { openSuggestionCommandParser = new OpenSuggestionCommandParser(model, pathCorrectionEngine); } + @Test + public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "op"; + String path = ""; + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); + } + + @Test + public void parse_correctCmdWithoutPath_returnsOptionalEmpty() { + String userInput = "open"; + String path = ""; + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(RESPONSE_MESSAGE), + model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); + } + @Test public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; @@ -298,14 +326,14 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges } @Test - public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { - String userInput = "op"; - String path = ""; + public void parse_correctCmdInvalidPath_returnsOptionalEmpty() { + String path = "-"; + String userInput = COMMAND_WORD + " " + path; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(path); - assertEquals(Optional.of(RESPONSE_MESSAGE), + assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_OPEN_NOTE, path)), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); @@ -333,7 +361,21 @@ public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(path); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_CANNOT_DELETE_NOTE, path)), + assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_OPEN_NOTE, path)), + model.responseTextProperty().getValue()); + + assertFalse(command.isPresent()); + } + + @Test + public void parse_correctedCmdUncorrectedPath_returnsOptionalEmpty() { + String path = "random"; + String userInput = "op " + path; + + model.setInput(userInput); + Optional command = openSuggestionCommandParser.parse(path); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); From c4b15ea1fb3fa33dd056bc5030efae458242b1eb Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 01:02:46 +0800 Subject: [PATCH 34/49] Remove redundant test cases in Open and Delete sug cmd parser test --- .../DeleteSuggestionCommandParserTest.java | 32 ++----------------- .../NewSuggestionCommandParserTest.java | 8 ++--- .../OpenSuggestionCommandParserTest.java | 32 ++----------------- 3 files changed, 8 insertions(+), 64 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 39707af2ccd..39a0844e0ff 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -326,7 +326,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg } @Test - public void parse_correctCmdInvalidPath_returnsOptionalEmpty() { + public void parse_invalidPath_returnsOptionalEmpty() { String path = "-"; String userInput = COMMAND_WORD + " " + path; @@ -340,7 +340,7 @@ public void parse_correctCmdInvalidPath_returnsOptionalEmpty() { } @Test - public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { + public void parse_uncorrectedPath_returnsOptionalEmpty() { String path = "random"; String userInput = COMMAND_WORD + " " + path; @@ -352,32 +352,4 @@ public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { assertFalse(command.isPresent()); } - - @Test - public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { - String path = "-"; - String userInput = "dele " + path; - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(path); - - assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, path)), - model.responseTextProperty().getValue()); - - assertFalse(command.isPresent()); - } - - @Test - public void parse_correctedCmdUncorrectedPath_returnsOptionalEmpty() { - String path = "random"; - String userInput = "dele " + path; - - model.setInput(userInput); - Optional command = deleteSuggestionCommandParser.parse(path); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - assertFalse(command.isPresent()); - } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java index 6df1d8ee624..522229254d2 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java @@ -12,10 +12,10 @@ public class NewSuggestionCommandParserTest { private static final String RESPONSE_MESSAGE = "Create a new note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Create a new note titled \"%s\"."; private static final String RESPONSE_MESSAGE_WITH_TITLE_AND_OPEN = "Create a new note titled \"%s\" and open it."; - private static final String ERROR_MESSAGE = "\"%s\" is an invalid command format. " - + "The correct format is \"new -t TITLE [-b BODY] [-o]\""; + private static final String ERROR_MESSAGE_INVALID_COMMAND = "\"%s\" is an invalid creation format. " + + "The correct format is \"new -t TITLE [-o]\""; private static final String ERROR_MESSAGE_INVALID_TITLE = "Title \"%s\" is invalid. " - + "Titles should only contain alphanumeric characters"; + + "Titles should only contain alphanumeric characters and symbols except - and /"; @BeforeAll public static void setUp() { @@ -27,7 +27,7 @@ public static void setUp() { /* @Test - public void parse() { + public void parse_() { String arg = ""; Optional command = newSuggestionCommandParser.parse(arg); diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index b1279a6b85a..df953af6ac7 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -326,7 +326,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges } @Test - public void parse_correctCmdInvalidPath_returnsOptionalEmpty() { + public void parse_invalidPath_returnsOptionalEmpty() { String path = "-"; String userInput = COMMAND_WORD + " " + path; @@ -340,7 +340,7 @@ public void parse_correctCmdInvalidPath_returnsOptionalEmpty() { } @Test - public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { + public void parse_uncorrectedPath_returnsOptionalEmpty() { String path = "random"; String userInput = COMMAND_WORD + " " + path; @@ -352,32 +352,4 @@ public void parse_correctCmdUncorrectedPath_returnsOptionalEmpty() { assertFalse(command.isPresent()); } - - @Test - public void parse_correctedCmdInvalidPath_returnsOptionalEmpty() { - String path = "-"; - String userInput = "op " + path; - - model.setInput(userInput); - Optional command = openSuggestionCommandParser.parse(path); - - assertEquals(Optional.of(String.format(ERROR_MESSAGE_CANNOT_OPEN_NOTE, path)), - model.responseTextProperty().getValue()); - - assertFalse(command.isPresent()); - } - - @Test - public void parse_correctedCmdUncorrectedPath_returnsOptionalEmpty() { - String path = "random"; - String userInput = "op " + path; - - model.setInput(userInput); - Optional command = openSuggestionCommandParser.parse(path); - - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), - model.responseTextProperty().getValue()); - - assertFalse(command.isPresent()); - } } From 4912a7bff6532af051ef110ef74c1df550af62a2 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 01:52:44 +0800 Subject: [PATCH 35/49] Add test cases for NewSugCmdParser --- .../NewSuggestionCommandParserTest.java | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java index 522229254d2..d254518a2be 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java @@ -1,7 +1,15 @@ package com.notably.logic.parser.suggestion; +import static com.notably.logic.parser.CliSyntax.PREFIX_JUMP; +import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Optional; + import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.suggestion.SuggestionTestUtil; import com.notably.model.Model; @@ -25,14 +33,58 @@ public static void setUp() { newSuggestionCommandParser = new NewSuggestionCommandParser(model); } - /* @Test - public void parse_() { + public void parse_emptyArg() { String arg = ""; Optional command = newSuggestionCommandParser.parse(arg); - assertEquals(Optional.of(RESPONSE_MESSAGE), + assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); + } + + @Test + public void parse_prefixTitleValidTitleNoPrefixJump() { + String title = "Aa123!@#$%^&*()"; + String arg = " " + PREFIX_TITLE + " " + title; + + Optional command = newSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, title)), + model.responseTextProperty().getValue()); + } + + @Test + public void parse_prefixTitleValidTitlePrefixJump() { + String title = "Aa123!@#$%^&*()"; + String arg = " " + PREFIX_TITLE + " " + title + " " + PREFIX_JUMP; + + Optional command = newSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE_AND_OPEN, title)), model.responseTextProperty().getValue()); - }*/ + } + + @Test + public void parse_prefixTitleInvalidTitle() { + String title = "aA-"; + String arg = " " + PREFIX_TITLE + " " + title + " " + PREFIX_JUMP; + + Optional command = newSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(String.format(ERROR_MESSAGE_INVALID_TITLE, title)), + model.responseTextProperty().getValue()); + } + + @Test + public void parse_noPrefixTitleValidTitle() { + String title = "Aa123!@#$%^&*()"; + String arg = " " + title + " " + PREFIX_JUMP; + String userInput = "nw" + arg; + model.setInput(userInput); + + Optional command = newSuggestionCommandParser.parse(arg); + + assertEquals(Optional.of(String.format(ERROR_MESSAGE_INVALID_COMMAND, userInput)), + model.responseTextProperty().getValue()); + } } From 697070f39198d9d2e2204a173842e7b52d4bfa75 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 02:25:25 +0800 Subject: [PATCH 36/49] Add test case for error sug cmd parser --- .../suggestion/SuggestionEngineImplTest.java | 45 +++++++++++++------ 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java index 859c9fe9df5..29f7c227405 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java @@ -5,6 +5,7 @@ import java.util.Optional; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -15,6 +16,12 @@ public class SuggestionEngineImplTest { private static Model model; private static SuggestionEngine suggestionEngine; + private static final String EDIT_RESPONSE_TEXT = "Edit this note"; + private static final String ERROR_RESPONSE_TEXT = "\"%s\" is an invalid command format. " + + "To see the list of available commands, type: help"; + private static final String EXIT_RESPONSE_TEXT = "Exit the application"; + private static final String HELP_RESPONSE_TEXT = "Display a list of available commands"; + @BeforeAll public static void setUp() throws InvalidPathException { model = SuggestionTestUtil.getModel(); @@ -23,41 +30,51 @@ public static void setUp() throws InvalidPathException { suggestionEngine = new SuggestionEngineImpl(model); } + @AfterEach + public void clearResponseText() { + model.clearResponseText(); + } + @Test public void suggest_inputLengthTooShort_suggestionsAndResponseTextCleared() { - model.setInput(""); + suggestionEngine.suggest(""); assertTrue(model.getSuggestions().isEmpty()); assertTrue(model.responseTextProperty().getValue().isEmpty()); - model.setInput("o"); + suggestionEngine.suggest("o"); assertTrue(model.getSuggestions().isEmpty()); assertTrue(model.responseTextProperty().getValue().isEmpty()); } + + @Test public void suggest_correctedEditCommand() { - model.setInput("edt"); + suggestionEngine.suggest("edt"); - // Expected result - String expectedResponseText = "Edit this note"; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); + assertEquals(Optional.of(EDIT_RESPONSE_TEXT), model.responseTextProperty().getValue()); } @Test public void suggest_correctedHelpCommand() { - model.setInput("hAlp"); + suggestionEngine.suggest("hAlp"); - // Expected result - String expectedResponseText = "Display a list of available commands"; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); + assertEquals(Optional.of(HELP_RESPONSE_TEXT), model.responseTextProperty().getValue()); } @Test public void suggest_correctedExitCommand() { - model.setInput("ex"); + suggestionEngine.suggest("ex"); + + assertEquals(Optional.of(EXIT_RESPONSE_TEXT), model.responseTextProperty().getValue()); + } + + @Test + public void suggest_invalidCommand_displaysErrorMessage() { + String userInput = "randomCmd"; + suggestionEngine.suggest(userInput); - // Expected result - String expectedResponseText = "Exit the application"; - assertEquals(Optional.of(expectedResponseText), model.responseTextProperty().getValue()); + assertEquals(Optional.of(String.format(ERROR_RESPONSE_TEXT, userInput)), + model.responseTextProperty().getValue()); } } From 29b98c9aa1f3ac07b84968520b7ce4a20fea7d5b Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 03:25:25 +0800 Subject: [PATCH 37/49] Add test case for open in SugEngineImplTest --- .../suggestion/SuggestionEngineImplTest.java | 68 ++++++++++++++++--- .../logic/suggestion/SuggestionTestUtil.java | 9 +++ 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java index 29f7c227405..25ce49af461 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java @@ -3,40 +3,48 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import com.notably.commons.path.AbsolutePath; import com.notably.commons.path.exceptions.InvalidPathException; import com.notably.model.Model; +import com.notably.model.suggestion.SuggestionItem; public class SuggestionEngineImplTest { + private static AbsolutePath toCs2103t; private static Model model; private static SuggestionEngine suggestionEngine; - private static final String EDIT_RESPONSE_TEXT = "Edit this note"; - private static final String ERROR_RESPONSE_TEXT = "\"%s\" is an invalid command format. " + private static final String DELETE_RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; + private static final String OPEN_RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; + private static final String EDIT_RESPONSE_MESSAGE = "Edit this note"; + private static final String ERROR_RESPONSE_MESSAGE = "\"%s\" is an invalid command format. " + "To see the list of available commands, type: help"; - private static final String EXIT_RESPONSE_TEXT = "Exit the application"; - private static final String HELP_RESPONSE_TEXT = "Display a list of available commands"; + private static final String EXIT_RESPONSE_MESSAGE = "Exit the application"; + private static final String HELP_RESPONSE_MESSAGE = "Display a list of available commands"; @BeforeAll public static void setUp() throws InvalidPathException { model = SuggestionTestUtil.getModel(); + toCs2103t = SuggestionTestUtil.getToCs2103t(); // Set up SuggestionEngine suggestionEngine = new SuggestionEngineImpl(model); } @AfterEach - public void clearResponseText() { + public void clearResponseTextAndSuggestions() { model.clearResponseText(); + model.clearSuggestions(); } @Test - public void suggest_inputLengthTooShort_suggestionsAndResponseTextCleared() { + public void suggest_inputLengthTooShort_noResponseTextDisplayed() { suggestionEngine.suggest(""); assertTrue(model.getSuggestions().isEmpty()); assertTrue(model.responseTextProperty().getValue().isEmpty()); @@ -46,27 +54,67 @@ public void suggest_inputLengthTooShort_suggestionsAndResponseTextCleared() { assertTrue(model.responseTextProperty().getValue().isEmpty()); } + @Test + public void suggest_correctedDeleteCommand_generatesSuggestions() { + String userInputWithoutPath = "dele "; + String path = toCs2103t.getStringRepresentation(); + String userInput = userInputWithoutPath + path; + suggestionEngine.suggest(userInput); + model.setInput(userInput); + + List suggestions = model.getSuggestions(); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Test response text + assertEquals(Optional.of(String.format(DELETE_RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + } + @Test + public void suggest_correctedOpenCommand_generatesSuggestions() { + String userInputWithoutPath = "op "; + String path = toCs2103t.getStringRepresentation(); + String userInput = userInputWithoutPath + path; + suggestionEngine.suggest(userInput); + model.setInput(userInput); + + List suggestions = model.getSuggestions(); + + // Expected suggestions + List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); + + // Test suggestions + SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + + // Test response text + assertEquals(Optional.of(String.format(OPEN_RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + } @Test public void suggest_correctedEditCommand() { suggestionEngine.suggest("edt"); - assertEquals(Optional.of(EDIT_RESPONSE_TEXT), model.responseTextProperty().getValue()); + assertEquals(Optional.of(EDIT_RESPONSE_MESSAGE), model.responseTextProperty().getValue()); } @Test public void suggest_correctedHelpCommand() { suggestionEngine.suggest("hAlp"); - assertEquals(Optional.of(HELP_RESPONSE_TEXT), model.responseTextProperty().getValue()); + assertEquals(Optional.of(HELP_RESPONSE_MESSAGE), model.responseTextProperty().getValue()); } @Test public void suggest_correctedExitCommand() { suggestionEngine.suggest("ex"); - assertEquals(Optional.of(EXIT_RESPONSE_TEXT), model.responseTextProperty().getValue()); + assertEquals(Optional.of(EXIT_RESPONSE_MESSAGE), model.responseTextProperty().getValue()); } @Test @@ -74,7 +122,7 @@ public void suggest_invalidCommand_displaysErrorMessage() { String userInput = "randomCmd"; suggestionEngine.suggest(userInput); - assertEquals(Optional.of(String.format(ERROR_RESPONSE_TEXT, userInput)), + assertEquals(Optional.of(String.format(ERROR_RESPONSE_MESSAGE, userInput)), model.responseTextProperty().getValue()); } } diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 1a6eb92eab5..8350d6c2518 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -89,10 +89,19 @@ public static void testSuggestions(List expectedSuggestions, Lis */ public static void testInputs(List expectedInputs, List suggestions, Model model) { for (int i = 0; i < expectedInputs.size(); i++) { + System.out.println("length expectedInputs: " + expectedInputs.size()); + System.out.println("length suggestions: " + suggestions.size()); + + System.out.println("i: " + i); + SuggestionItem thirdSuggestionItem = suggestions.get(2); + System.out.println("3rd sug item: " + thirdSuggestionItem.getProperty("displayText")); + SuggestionItem suggestionItem = suggestions.get(i); + System.out.println(suggestionItem.getProperty("displayText")); String expectedInput = expectedInputs.get(i); suggestionItem.getAction().run(); String input = model.getInput(); + System.out.println("input: " + input); assertEquals(expectedInput, input); } } From 91826d3836fb44e3dbda151d78b0e28c83f18906 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 03:31:37 +0800 Subject: [PATCH 38/49] Add test case for new in SugEngineImplTest --- .../suggestion/SuggestionEngineImplTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java index 25ce49af461..48fec9322c2 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java @@ -1,5 +1,6 @@ package com.notably.logic.suggestion; +import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -22,6 +23,7 @@ public class SuggestionEngineImplTest { private static final String DELETE_RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; private static final String OPEN_RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; + private static final String NEW_RESPONSE_MESSAGE_WITH_TITLE = "Create a new note titled \"%s\"."; private static final String EDIT_RESPONSE_MESSAGE = "Edit this note"; private static final String ERROR_RESPONSE_MESSAGE = "\"%s\" is an invalid command format. " + "To see the list of available commands, type: help"; @@ -96,6 +98,19 @@ public void suggest_correctedOpenCommand_generatesSuggestions() { model.responseTextProperty().getValue()); } + @Test + public void suggest_correctedNewCommand() { + String userInputWithoutPath = "nw "; + String path = "Aa123!@#$%^&*()"; + String arg = " " + PREFIX_TITLE + " " + path; + String userInput = userInputWithoutPath + arg; + suggestionEngine.suggest(userInput); + + // Test response text + assertEquals(Optional.of(String.format(NEW_RESPONSE_MESSAGE_WITH_TITLE, path)), + model.responseTextProperty().getValue()); + } + @Test public void suggest_correctedEditCommand() { suggestionEngine.suggest("edt"); From c9d9a7f4168bb3fc116b9ac475fa8bf37378abdc Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 03:47:22 +0800 Subject: [PATCH 39/49] Update javadoc --- .../NewSuggestionCommandParser.java | 4 +- .../SearchSuggestionCommandParser.java | 78 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java diff --git a/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java b/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java index 5657fa2cd5c..9277889f953 100644 --- a/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java +++ b/src/main/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParser.java @@ -31,10 +31,12 @@ public class NewSuggestionCommandParser implements SuggestionCommandParser parse(String userInput) { ArgumentMultimap argMultimap = diff --git a/src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java b/src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java new file mode 100644 index 00000000000..268537506b9 --- /dev/null +++ b/src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java @@ -0,0 +1,78 @@ +package com.notably.logic.parser.suggestion; + +import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; + +import java.util.Optional; + +import com.notably.commons.path.AbsolutePath; +import com.notably.logic.commands.suggestion.DeleteSuggestionCommand; +import com.notably.logic.correction.CorrectionEngine; +import com.notably.logic.correction.CorrectionResult; +import com.notably.logic.correction.CorrectionStatus; +import com.notably.logic.parser.ArgumentMultimap; +import com.notably.logic.parser.ArgumentTokenizer; +import com.notably.logic.parser.ParserUtil; +import com.notably.logic.parser.exceptions.ParseException; +import com.notably.model.Model; + +/** + * Represents a Parser for DeleteSuggestionCommand. + */ +public class DeleteSuggestionCommandParser implements SuggestionCommandParser { + public static final String COMMAND_WORD = "delete"; + + private static final String RESPONSE_MESSAGE = "Delete a note"; + private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; + private static final String ERROR_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\" as it is an invalid path"; + + private Model model; + private CorrectionEngine pathCorrectionEngine; + + public DeleteSuggestionCommandParser(Model model, CorrectionEngine pathCorrectionEngine) { + this.model = model; + this.pathCorrectionEngine = pathCorrectionEngine; + } + + /** + * Parses user input in the context of the DeleteSuggestionCommand. + * + * @param userInput The user's input. + * @return An optional DeleteSuggestionCommand object with a corrected absolute path. + */ + @Override + public Optional parse(String userInput) { + ArgumentMultimap argMultimap = + ArgumentTokenizer.tokenize(userInput, PREFIX_TITLE); + + String title; + if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_TITLE) + || !argMultimap.getPreamble().isEmpty()) { + title = userInput.trim(); + } else { + title = argMultimap.getValue(PREFIX_TITLE).get(); + } + + if (title.isEmpty()) { + model.setResponseText(RESPONSE_MESSAGE); + return Optional.empty(); + } + + AbsolutePath uncorrectedPath; + try { + uncorrectedPath = ParserUtil.createAbsolutePath(title, model.getCurrentlyOpenPath()); + } catch (ParseException pe) { + model.setResponseText(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, title)); + return Optional.empty(); + } + + model.setResponseText(String.format(RESPONSE_MESSAGE_WITH_TITLE, title)); + + CorrectionResult correctionResult = pathCorrectionEngine.correct(uncorrectedPath); + if (correctionResult.getCorrectionStatus() == CorrectionStatus.FAILED) { + return Optional.empty(); + } + + // TODO: Pass in the list of corrected items and create suggestions based on that + return Optional.of(new DeleteSuggestionCommand(correctionResult.getCorrectedItems().get(0), title)); + } +} From ac292b7de35af28a034d6caf67f8f1382e5e4c5e Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 03:55:36 +0800 Subject: [PATCH 40/49] Remove SearchSugCmdParser --- .../SearchSuggestionCommandParser.java | 78 ------------------- 1 file changed, 78 deletions(-) delete mode 100644 src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java diff --git a/src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java b/src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java deleted file mode 100644 index 268537506b9..00000000000 --- a/src/main/java/com/notably/logic/parser/suggestion/SearchSuggestionCommandParser.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.notably.logic.parser.suggestion; - -import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; - -import java.util.Optional; - -import com.notably.commons.path.AbsolutePath; -import com.notably.logic.commands.suggestion.DeleteSuggestionCommand; -import com.notably.logic.correction.CorrectionEngine; -import com.notably.logic.correction.CorrectionResult; -import com.notably.logic.correction.CorrectionStatus; -import com.notably.logic.parser.ArgumentMultimap; -import com.notably.logic.parser.ArgumentTokenizer; -import com.notably.logic.parser.ParserUtil; -import com.notably.logic.parser.exceptions.ParseException; -import com.notably.model.Model; - -/** - * Represents a Parser for DeleteSuggestionCommand. - */ -public class DeleteSuggestionCommandParser implements SuggestionCommandParser { - public static final String COMMAND_WORD = "delete"; - - private static final String RESPONSE_MESSAGE = "Delete a note"; - private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; - private static final String ERROR_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\" as it is an invalid path"; - - private Model model; - private CorrectionEngine pathCorrectionEngine; - - public DeleteSuggestionCommandParser(Model model, CorrectionEngine pathCorrectionEngine) { - this.model = model; - this.pathCorrectionEngine = pathCorrectionEngine; - } - - /** - * Parses user input in the context of the DeleteSuggestionCommand. - * - * @param userInput The user's input. - * @return An optional DeleteSuggestionCommand object with a corrected absolute path. - */ - @Override - public Optional parse(String userInput) { - ArgumentMultimap argMultimap = - ArgumentTokenizer.tokenize(userInput, PREFIX_TITLE); - - String title; - if (!ParserUtil.arePrefixesPresent(argMultimap, PREFIX_TITLE) - || !argMultimap.getPreamble().isEmpty()) { - title = userInput.trim(); - } else { - title = argMultimap.getValue(PREFIX_TITLE).get(); - } - - if (title.isEmpty()) { - model.setResponseText(RESPONSE_MESSAGE); - return Optional.empty(); - } - - AbsolutePath uncorrectedPath; - try { - uncorrectedPath = ParserUtil.createAbsolutePath(title, model.getCurrentlyOpenPath()); - } catch (ParseException pe) { - model.setResponseText(String.format(ERROR_MESSAGE_CANNOT_DELETE_NOTE, title)); - return Optional.empty(); - } - - model.setResponseText(String.format(RESPONSE_MESSAGE_WITH_TITLE, title)); - - CorrectionResult correctionResult = pathCorrectionEngine.correct(uncorrectedPath); - if (correctionResult.getCorrectionStatus() == CorrectionStatus.FAILED) { - return Optional.empty(); - } - - // TODO: Pass in the list of corrected items and create suggestions based on that - return Optional.of(new DeleteSuggestionCommand(correctionResult.getCorrectedItems().get(0), title)); - } -} From ee98380532ec287c7c1af5613486734d549e484b Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 14:29:46 +0800 Subject: [PATCH 41/49] Remove redundant isEmpty check in execute method and add defensive oldTitle check in constructor --- .../suggestion/DeleteSuggestionCommand.java | 16 ++++++++++------ .../suggestion/OpenSuggestionCommand.java | 5 +++++ .../suggestion/DeleteSuggestionCommandTest.java | 8 ++------ .../suggestion/OpenSuggestionCommandTest.java | 8 ++------ .../logic/suggestion/SuggestionTestUtil.java | 9 --------- 5 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java index 0e608310b11..f7c77436867 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java @@ -24,6 +24,11 @@ public class DeleteSuggestionCommand implements SuggestionCommand { public DeleteSuggestionCommand(AbsolutePath path, String oldTitle) { Objects.requireNonNull(path); Objects.requireNonNull(oldTitle); + + if (oldTitle.isBlank()) { + throw new IllegalArgumentException("The old title must contain at least one element"); + } + this.path = path; this.oldTitle = oldTitle; } @@ -33,13 +38,12 @@ public void execute(Model model) { // Nullity check Objects.requireNonNull(model); - if (!oldTitle.isBlank()) { - // Set suggestions - List possiblePaths = getPossiblePaths(path, model); - List suggestions = getSuggestions(possiblePaths, model); + // Set suggestions + List possiblePaths = getPossiblePaths(path, model); + List suggestions = getSuggestions(possiblePaths, model); + + model.setSuggestions(suggestions); - model.setSuggestions(suggestions); - } } /** diff --git a/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java index 8427d1a0aed..e8045d44834 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java @@ -24,6 +24,11 @@ public class OpenSuggestionCommand implements SuggestionCommand { public OpenSuggestionCommand(AbsolutePath path, String oldTitle) { Objects.requireNonNull(path); Objects.requireNonNull(oldTitle); + + if (oldTitle.isBlank()) { + throw new IllegalArgumentException("The old title must contain at least one element"); + } + this.path = path; this.oldTitle = oldTitle; } diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index 475d211e238..0a4dd8835d7 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -2,7 +2,6 @@ import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; @@ -51,11 +50,8 @@ public void execute_nullModel_throwsNullPointerException() { } @Test - public void execute_blankOldTitle_generatesEmptySuggestion() { - DeleteSuggestionCommand deleteSuggestionCommand = new DeleteSuggestionCommand(toCs2103t, " "); - deleteSuggestionCommand.execute(model); - - assertTrue(model.getSuggestions().size() == 0); + public void execute_blankOldTitle_throwsIllegalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> new DeleteSuggestionCommand(toCs2103t, " ")); } @Test diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index 5175c496b37..d7f004de26e 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -2,7 +2,6 @@ import static com.notably.logic.parser.CliSyntax.PREFIX_TITLE; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; @@ -51,11 +50,8 @@ public void execute_nullModel_throwsNullPointerException() { } @Test - public void execute_blankOldTitle_generatesEmptySuggestion() { - OpenSuggestionCommand openSuggestionCommand = new OpenSuggestionCommand(toCs2103t, " "); - openSuggestionCommand.execute(model); - - assertTrue(model.getSuggestions().size() == 0); + public void execute_blankOldTitle_throwsIllegalArgumentException() { + assertThrows(IllegalArgumentException.class, () -> new OpenSuggestionCommand(toCs2103t, " ")); } @Test diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 8350d6c2518..1a6eb92eab5 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -89,19 +89,10 @@ public static void testSuggestions(List expectedSuggestions, Lis */ public static void testInputs(List expectedInputs, List suggestions, Model model) { for (int i = 0; i < expectedInputs.size(); i++) { - System.out.println("length expectedInputs: " + expectedInputs.size()); - System.out.println("length suggestions: " + suggestions.size()); - - System.out.println("i: " + i); - SuggestionItem thirdSuggestionItem = suggestions.get(2); - System.out.println("3rd sug item: " + thirdSuggestionItem.getProperty("displayText")); - SuggestionItem suggestionItem = suggestions.get(i); - System.out.println(suggestionItem.getProperty("displayText")); String expectedInput = expectedInputs.get(i); suggestionItem.getAction().run(); String input = model.getInput(); - System.out.println("input: " + input); assertEquals(expectedInput, input); } } From 05fb591e9c01808a50c24822ba7966784d7c3209 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 14:42:55 +0800 Subject: [PATCH 42/49] Add nullity checks in SuggestionItemImpl --- .../com/notably/model/suggestion/SuggestionItemImpl.java | 8 ++++++++ .../commands/suggestion/SearchSuggestionCommandTest.java | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/notably/model/suggestion/SuggestionItemImpl.java b/src/main/java/com/notably/model/suggestion/SuggestionItemImpl.java index 9eb42f0fb72..3a35e710d4f 100644 --- a/src/main/java/com/notably/model/suggestion/SuggestionItemImpl.java +++ b/src/main/java/com/notably/model/suggestion/SuggestionItemImpl.java @@ -1,6 +1,7 @@ package com.notably.model.suggestion; import java.util.HashMap; +import java.util.Objects; import java.util.Optional; /** @@ -11,6 +12,9 @@ public class SuggestionItemImpl implements SuggestionItem { private HashMap hmap; public SuggestionItemImpl(String displayText, Runnable action) { + Objects.requireNonNull(displayText); + Objects.requireNonNull(action); + this.action = action; hmap = new HashMap<>(); @@ -18,6 +22,10 @@ public SuggestionItemImpl(String displayText, Runnable action) { } public SuggestionItemImpl(String displayText, int frequency, Runnable action) { + Objects.requireNonNull(displayText); + Objects.requireNonNull(frequency); + Objects.requireNonNull(action); + this.action = action; hmap = new HashMap<>(); diff --git a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java index b7562d56006..a2abc14b13f 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java @@ -45,11 +45,11 @@ public void execute_generatesResponseCorrectly() { // Expected suggestions List expectedSuggestions = new ArrayList<>(); SuggestionItem cs2103tTut1 = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), 1, null); + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), 1, () -> {}); SuggestionItem cs2103tTut2 = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), 2, null); + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), 2, () -> {}); SuggestionItem cs2106Tut1 = new SuggestionItemImpl( - TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1.getStringRepresentation(), 1, null); + TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1.getStringRepresentation(), 1, () -> {}); expectedSuggestions.add(cs2103tTut1); expectedSuggestions.add(cs2103tTut2); expectedSuggestions.add(cs2106Tut1); From 7fe5286adfc3e1c7a6776dd5045d59da5008f108 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:11:44 +0800 Subject: [PATCH 43/49] Remove unnecessary inline comments --- .../suggestion/DeleteSuggestionCommand.java | 3 - .../suggestion/OpenSuggestionCommand.java | 10 +-- .../suggestion/SearchSuggestionCommand.java | 3 - .../DeleteSuggestionCommandTest.java | 8 --- .../suggestion/OpenSuggestionCommandTest.java | 8 --- .../DeleteSuggestionCommandParserTest.java | 71 +------------------ .../EditSuggestionCommandParserTest.java | 1 - .../ErrorSuggestionCommandParserTest.java | 1 - .../ExitSuggestionCommandParserTest.java | 1 - .../HelpSuggestionCommandParserTest.java | 1 - .../NewSuggestionCommandParserTest.java | 1 - .../OpenSuggestionCommandParserTest.java | 71 +------------------ .../suggestion/SuggestionEngineImplTest.java | 10 --- 13 files changed, 7 insertions(+), 182 deletions(-) diff --git a/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java index f7c77436867..427774c4aa4 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommand.java @@ -35,15 +35,12 @@ public DeleteSuggestionCommand(AbsolutePath path, String oldTitle) { @Override public void execute(Model model) { - // Nullity check Objects.requireNonNull(model); - // Set suggestions List possiblePaths = getPossiblePaths(path, model); List suggestions = getSuggestions(possiblePaths, model); model.setSuggestions(suggestions); - } /** diff --git a/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java index e8045d44834..503fbe3e2f1 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/OpenSuggestionCommand.java @@ -35,16 +35,12 @@ public OpenSuggestionCommand(AbsolutePath path, String oldTitle) { @Override public void execute(Model model) { - // Nullity check Objects.requireNonNull(model); - if (!oldTitle.isBlank()) { - // Set suggestions - List possiblePaths = getPossiblePaths(path, model); - List suggestions = getSuggestions(possiblePaths, model); + List possiblePaths = getPossiblePaths(path, model); + List suggestions = getSuggestions(possiblePaths, model); - model.setSuggestions(suggestions); - } + model.setSuggestions(suggestions); } /** diff --git a/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java b/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java index 143f64860fc..e08daf0ec4b 100644 --- a/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java +++ b/src/main/java/com/notably/logic/commands/suggestion/SearchSuggestionCommand.java @@ -29,12 +29,9 @@ public SearchSuggestionCommand(String keyword) { @Override public void execute(Model model) { - // Nullity check Objects.requireNonNull(model); - // Set suggestions List suggestions = traverseTree(model); - model.setSuggestions(suggestions); } diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index 0a4dd8835d7..7b3d5d6d700 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -64,16 +64,12 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List suggestions = model.getSuggestions(); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -87,16 +83,12 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List suggestions = model.getSuggestions(); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } } diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index d7f004de26e..ca83ec059c6 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -64,16 +64,12 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List suggestions = model.getSuggestions(); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -87,16 +83,12 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List suggestions = model.getSuggestions(); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 39a0844e0ff..b41ecdb79f8 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -39,7 +39,6 @@ public static void setUp() { model = SuggestionTestUtil.getModel(); toCs2103t = SuggestionTestUtil.getToCs2103t(); - // initialize parser CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); deleteSuggestionCommandParser = new DeleteSuggestionCommandParser(model, pathCorrectionEngine); @@ -53,8 +52,7 @@ public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(path); - assertEquals(Optional.of(RESPONSE_MESSAGE), - model.responseTextProperty().getValue()); + assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); } @@ -67,8 +65,7 @@ public void parse_correctCmdWithoutPath_returnsOptionalEmpty() { model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(path); - assertEquals(Optional.of(RESPONSE_MESSAGE), - model.responseTextProperty().getValue()); + assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); } @@ -88,19 +85,11 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestio assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -119,19 +108,11 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSugg assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -150,19 +131,11 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -181,19 +154,11 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSugg assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -213,19 +178,11 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSugge assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -245,19 +202,11 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSugg assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -277,19 +226,11 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSugge assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -309,19 +250,11 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } diff --git a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java index dfec9d24117..5aa60f3aed8 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/EditSuggestionCommandParserTest.java @@ -21,7 +21,6 @@ public class EditSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); - // initialize parser editSuggestionCommandParser = new EditSuggestionCommandParser(model); } diff --git a/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java index 9ff71661e27..f83bc3c9ad9 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/ErrorSuggestionCommandParserTest.java @@ -22,7 +22,6 @@ public class ErrorSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); - // initialize parser errorSuggestionCommandParser = new ErrorSuggestionCommandParser(model); } diff --git a/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java index 7e854d682f6..52eb3827ba1 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/ExitSuggestionCommandParserTest.java @@ -21,7 +21,6 @@ public class ExitSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); - // initialize parser exitSuggestionCommandParser = new ExitSuggestionCommandParser(model); } diff --git a/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java index 00a28cb64bf..6fc69c1a11d 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/HelpSuggestionCommandParserTest.java @@ -21,7 +21,6 @@ public class HelpSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); - // initialize parser helpSuggestionCommandParser = new HelpSuggestionCommandParser(model); } diff --git a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java index d254518a2be..84c3374b2ac 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/NewSuggestionCommandParserTest.java @@ -29,7 +29,6 @@ public class NewSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); - // initialize parser newSuggestionCommandParser = new NewSuggestionCommandParser(model); } diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index df953af6ac7..b490d0e6154 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -39,7 +39,6 @@ public static void setUp() { model = SuggestionTestUtil.getModel(); toCs2103t = SuggestionTestUtil.getToCs2103t(); - // initialize parser CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); openSuggestionCommandParser = new OpenSuggestionCommandParser(model, pathCorrectionEngine); @@ -53,8 +52,7 @@ public void parse_correctedCmdWithoutPath_returnsOptionalEmpty() { model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(path); - assertEquals(Optional.of(RESPONSE_MESSAGE), - model.responseTextProperty().getValue()); + assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); } @@ -67,8 +65,7 @@ public void parse_correctCmdWithoutPath_returnsOptionalEmpty() { model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(path); - assertEquals(Optional.of(RESPONSE_MESSAGE), - model.responseTextProperty().getValue()); + assertEquals(Optional.of(RESPONSE_MESSAGE), model.responseTextProperty().getValue()); assertFalse(command.isPresent()); } @@ -88,19 +85,11 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionC assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -119,19 +108,11 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSugges assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, toCs2103t.getStringRepresentation())), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -150,19 +131,11 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -181,19 +154,11 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSugges assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -213,19 +178,11 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsOpenSuggest assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -245,19 +202,11 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsOpenSugges assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -277,19 +226,11 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsOpenSuggest assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } @@ -309,19 +250,11 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Actual suggestions List suggestions = model.getSuggestions(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Expected inputs List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - - // Test inputs SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); } diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java index 48fec9322c2..a5a2fca8981 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java @@ -35,7 +35,6 @@ public static void setUp() throws InvalidPathException { model = SuggestionTestUtil.getModel(); toCs2103t = SuggestionTestUtil.getToCs2103t(); - // Set up SuggestionEngine suggestionEngine = new SuggestionEngineImpl(model); } @@ -66,13 +65,9 @@ public void suggest_correctedDeleteCommand_generatesSuggestions() { List suggestions = model.getSuggestions(); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Test response text assertEquals(Optional.of(String.format(DELETE_RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); } @@ -87,13 +82,9 @@ public void suggest_correctedOpenCommand_generatesSuggestions() { List suggestions = model.getSuggestions(); - // Expected suggestions List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - - // Test suggestions SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); - // Test response text assertEquals(Optional.of(String.format(OPEN_RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); } @@ -106,7 +97,6 @@ public void suggest_correctedNewCommand() { String userInput = userInputWithoutPath + arg; suggestionEngine.suggest(userInput); - // Test response text assertEquals(Optional.of(String.format(NEW_RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); } From 25357ae0313b368b5d6ee4012380f3097a1d7688 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:14:36 +0800 Subject: [PATCH 44/49] Rename testSuggestions to assertSuggestions in SugTestUtil --- .../suggestion/DeleteSuggestionCommandTest.java | 4 ++-- .../suggestion/OpenSuggestionCommandTest.java | 4 ++-- .../DeleteSuggestionCommandParserTest.java | 16 ++++++++-------- .../OpenSuggestionCommandParserTest.java | 16 ++++++++-------- .../suggestion/SuggestionEngineImplTest.java | 4 ++-- .../logic/suggestion/SuggestionTestUtil.java | 8 ++------ 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index 7b3d5d6d700..ec2420c3c4a 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -66,7 +66,7 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); @@ -85,7 +85,7 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index ca83ec059c6..0422ec1e2ca 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -66,7 +66,7 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); @@ -85,7 +85,7 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index b41ecdb79f8..b40d02f61bf 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -87,7 +87,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestio List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -110,7 +110,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSugg List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -133,7 +133,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -156,7 +156,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSugg List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -180,7 +180,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSugge List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -204,7 +204,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSugg List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -228,7 +228,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSugge List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -252,7 +252,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index b490d0e6154..e25f158ea05 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -87,7 +87,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionC List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -110,7 +110,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSugges List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -133,7 +133,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -156,7 +156,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSugges List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -180,7 +180,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsOpenSuggest List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -204,7 +204,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsOpenSugges List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -228,7 +228,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsOpenSuggest List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); @@ -252,7 +252,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); List suggestions = model.getSuggestions(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java index a5a2fca8981..95c516d8fda 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionEngineImplTest.java @@ -66,7 +66,7 @@ public void suggest_correctedDeleteCommand_generatesSuggestions() { List suggestions = model.getSuggestions(); List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); assertEquals(Optional.of(String.format(DELETE_RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); @@ -83,7 +83,7 @@ public void suggest_correctedOpenCommand_generatesSuggestions() { List suggestions = model.getSuggestions(); List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); - SuggestionTestUtil.testSuggestions(expectedSuggestions, suggestions); + SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); assertEquals(Optional.of(String.format(OPEN_RESPONSE_MESSAGE_WITH_TITLE, path)), model.responseTextProperty().getValue()); diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 1a6eb92eab5..d76051185df 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -47,11 +47,7 @@ public static List getExpectedSugForCs2103tPathInput() { SuggestionItem cs2103tTut2 = new SuggestionItemImpl( TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), () -> {}); - List expectedSuggestions; - SuggestionItem[] items = new SuggestionItem[]{cs2103t, cs2103tLect, cs2103tTut, cs2103tTut1, cs2103tTut2}; - expectedSuggestions = List.of(items); - - return expectedSuggestions; + return List.of(cs2103t, cs2103tLect, cs2103tTut, cs2103tTut1, cs2103tTut2); } public static List getExpectedInputsForCs2103tPathInput(String userInputWithoutPath) { @@ -75,7 +71,7 @@ public static List getExpectedInputsForCs2103tPathInput(String userInput * @param expectedSuggestions The expected suggestions list. * @param suggestions The actual list of suggestions. */ - public static void testSuggestions(List expectedSuggestions, List suggestions) { + public static void assertSuggestions(List expectedSuggestions, List suggestions) { assertEquals(expectedSuggestions.stream().map(s -> s.getProperty("displayText")).collect(Collectors.toList()), suggestions.stream().map(s -> s.getProperty("displayText")).collect(Collectors.toList())); } From 8e0266ddc4303b1106090b1783187560215ebaf3 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:15:13 +0800 Subject: [PATCH 45/49] Rename testInputs to assertInputs in SugTestUtil --- .../suggestion/DeleteSuggestionCommandTest.java | 4 ++-- .../suggestion/OpenSuggestionCommandTest.java | 4 ++-- .../DeleteSuggestionCommandParserTest.java | 16 ++++++++-------- .../OpenSuggestionCommandParserTest.java | 16 ++++++++-------- .../logic/suggestion/SuggestionTestUtil.java | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java index ec2420c3c4a..0c7bd995683 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/DeleteSuggestionCommandTest.java @@ -70,7 +70,7 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -89,6 +89,6 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } } diff --git a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java index 0422ec1e2ca..db9f1318715 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/OpenSuggestionCommandTest.java @@ -70,7 +70,7 @@ public void execute_correctAbsolutePathWithPrefix_generatesResponseCorrectly() { List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -89,6 +89,6 @@ public void execute_correctAbsolutePathWithoutPrefix_generatesResponseCorrectly( List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } } diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index b40d02f61bf..ea840b30223 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -90,7 +90,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestio SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -113,7 +113,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSugg SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -136,7 +136,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -159,7 +159,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSugg SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -183,7 +183,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSugge SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -207,7 +207,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSugg SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -231,7 +231,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSugge SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -255,7 +255,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index e25f158ea05..74ec1842336 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -90,7 +90,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionC SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -113,7 +113,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSugges SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -136,7 +136,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -159,7 +159,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSugges SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -183,7 +183,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsOpenSuggest SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -207,7 +207,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsOpenSugges SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -231,7 +231,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsOpenSuggest SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test @@ -255,7 +255,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges SuggestionTestUtil.assertSuggestions(expectedSuggestions, suggestions); List expectedInputs = SuggestionTestUtil.getExpectedInputsForCs2103tPathInput(userInputWithoutPath); - SuggestionTestUtil.testInputs(expectedInputs, suggestions, model); + SuggestionTestUtil.assertInputs(expectedInputs, suggestions, model); } @Test diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index d76051185df..8519025d553 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -83,7 +83,7 @@ public static void assertSuggestions(List expectedSuggestions, L * @param suggestions The actual list of suggestions. * @param model The app's model. */ - public static void testInputs(List expectedInputs, List suggestions, Model model) { + public static void assertInputs(List expectedInputs, List suggestions, Model model) { for (int i = 0; i < expectedInputs.size(); i++) { SuggestionItem suggestionItem = suggestions.get(i); String expectedInput = expectedInputs.get(i); From 31db4cbdbc0623d688ba871b4ee6adb0cedf1359 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:19:39 +0800 Subject: [PATCH 46/49] Simplify adding el to list method --- .../suggestion/SearchSuggestionCommandTest.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java index a2abc14b13f..52c838dfc4a 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java @@ -42,19 +42,14 @@ public void execute_generatesResponseCorrectly() { List suggestions = model.getSuggestions(); - // Expected suggestions - List expectedSuggestions = new ArrayList<>(); SuggestionItem cs2103tTut1 = new SuggestionItemImpl( TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1.getStringRepresentation(), 1, () -> {}); SuggestionItem cs2103tTut2 = new SuggestionItemImpl( TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2.getStringRepresentation(), 2, () -> {}); SuggestionItem cs2106Tut1 = new SuggestionItemImpl( TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1.getStringRepresentation(), 1, () -> {}); - expectedSuggestions.add(cs2103tTut1); - expectedSuggestions.add(cs2103tTut2); - expectedSuggestions.add(cs2106Tut1); + List expectedSuggestions = List.of(cs2103tTut1, cs2103tTut2, cs2106Tut1); - // Test displayText and frequency for (int i = 0; i < expectedSuggestions.size(); i++) { SuggestionItem suggestion = suggestions.get(i); SuggestionItem expectedSuggestion = expectedSuggestions.get(i); @@ -62,13 +57,9 @@ public void execute_generatesResponseCorrectly() { assertEquals(expectedSuggestion.getProperty("frequency"), suggestion.getProperty("frequency")); } - // Expected currently open paths - List expectedCurrentlyOpenPaths = new ArrayList<>(); - expectedCurrentlyOpenPaths.add(TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1); - expectedCurrentlyOpenPaths.add(TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2); - expectedCurrentlyOpenPaths.add(TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1); + List expectedCurrentlyOpenPaths = List.of(TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_1, + TypicalBlockModel.PATH_TO_CS2103T_TUTORIAL_2, TypicalBlockModel.PATH_TO_CS2106_TUTORIAL_1); - // Test Runnable action and check currentlyOpenPath for (int i = 0; i < expectedCurrentlyOpenPaths.size(); i++) { SuggestionItem suggestion = suggestions.get(i); suggestion.getAction().run(); From f5f85a8290fa1c03f40a4c161deb3cd1fee779f4 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:23:18 +0800 Subject: [PATCH 47/49] Change command checking to isPresent() --- .../DeleteSuggestionCommandParserTest.java | 16 ++++++++-------- .../OpenSuggestionCommandParserTest.java | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index ea840b30223..9034500c4d3 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -78,7 +78,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestio model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -101,7 +101,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSugg model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -124,7 +124,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -147,7 +147,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSugg model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -171,7 +171,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSugge model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -195,7 +195,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSugg model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -219,7 +219,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSugge model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -243,7 +243,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof DeleteSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index 74ec1842336..5d57120b65d 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -78,7 +78,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionC model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -101,7 +101,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSugges model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -124,7 +124,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -147,7 +147,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSugges model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -171,7 +171,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsOpenSuggest model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -195,7 +195,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsOpenSugges model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -219,7 +219,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsOpenSuggest model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); @@ -243,7 +243,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); - assertTrue(command.get() instanceof OpenSuggestionCommand); + assertTrue(command.isPresent()); command.get().execute(model); From f80cffd0da2308a6537539449964c7e1d96b8c9b Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:37:30 +0800 Subject: [PATCH 48/49] Move stringRelativePathToCs2103t to SugTestUtil --- .../suggestion/SearchSuggestionCommandTest.java | 1 - .../DeleteSuggestionCommandParserTest.java | 13 ++++++------- .../suggestion/OpenSuggestionCommandParserTest.java | 13 ++++++------- .../logic/suggestion/SuggestionTestUtil.java | 4 ++++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java index 52c838dfc4a..25c96781063 100644 --- a/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java +++ b/src/test/java/com/notably/logic/commands/suggestion/SearchSuggestionCommandTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import java.util.ArrayList; import java.util.List; import org.junit.jupiter.api.BeforeAll; diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index 9034500c4d3..fdab1a567c2 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.logic.commands.suggestion.DeleteSuggestionCommand; import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.correction.AbsolutePathCorrectionEngine; import com.notably.logic.correction.CorrectionEngine; @@ -22,15 +21,14 @@ public class DeleteSuggestionCommandParserTest { private static AbsolutePath toCs2103t; + private static String stringRelativePathToCs2103t; private static DeleteSuggestionCommandParser deleteSuggestionCommandParser; private static Model model; - private static final String RELATIVE_PATH_TO_CS2103T = "CS2103T"; private static final String COMMAND_WORD = "delete"; private static final String RESPONSE_MESSAGE = "Delete a note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Delete a note titled \"%s\""; private static final String ERROR_MESSAGE_CANNOT_DELETE_NOTE = "Cannot delete \"%s\" as it is an invalid path"; - private static final int CORRECTION_THRESHOLD = 2; private static final boolean USE_FORWARD_MATCHING = true; @@ -38,6 +36,7 @@ public class DeleteSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); toCs2103t = SuggestionTestUtil.getToCs2103t(); + stringRelativePathToCs2103t = SuggestionTestUtil.getStringRelativePathToCs2103t(); CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); @@ -119,7 +118,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSugg @Test public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; - String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String userInput = userInputWithoutPath + stringRelativePathToCs2103t; String arg = userInput.replace(COMMAND_WORD, ""); model.setInput(userInput); @@ -128,7 +127,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, stringRelativePathToCs2103t)), model.responseTextProperty().getValue()); List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); @@ -142,7 +141,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio @Test public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = "dele "; - String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String userInput = userInputWithoutPath + stringRelativePathToCs2103t; String arg = userInput.replace("dele", ""); model.setInput(userInput); @@ -151,7 +150,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSugg command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, stringRelativePathToCs2103t)), model.responseTextProperty().getValue()); List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index 5d57120b65d..72180bc2b52 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -12,7 +12,6 @@ import org.junit.jupiter.api.Test; import com.notably.commons.path.AbsolutePath; -import com.notably.logic.commands.suggestion.OpenSuggestionCommand; import com.notably.logic.commands.suggestion.SuggestionCommand; import com.notably.logic.correction.AbsolutePathCorrectionEngine; import com.notably.logic.correction.CorrectionEngine; @@ -22,15 +21,14 @@ public class OpenSuggestionCommandParserTest { private static AbsolutePath toCs2103t; + private static String stringRelativePathToCs2103t; private static OpenSuggestionCommandParser openSuggestionCommandParser; private static Model model; - private static final String RELATIVE_PATH_TO_CS2103T = "CS2103T"; private static final String COMMAND_WORD = "open"; private static final String RESPONSE_MESSAGE = "Open a note"; private static final String RESPONSE_MESSAGE_WITH_TITLE = "Open a note titled \"%s\""; private static final String ERROR_MESSAGE_CANNOT_OPEN_NOTE = "Cannot open \"%s\" as it is an invalid path"; - private static final int CORRECTION_THRESHOLD = 2; private static final boolean USE_FORWARD_MATCHING = true; @@ -38,6 +36,7 @@ public class OpenSuggestionCommandParserTest { public static void setUp() { model = SuggestionTestUtil.getModel(); toCs2103t = SuggestionTestUtil.getToCs2103t(); + stringRelativePathToCs2103t = SuggestionTestUtil.getStringRelativePathToCs2103t(); CorrectionEngine pathCorrectionEngine = new AbsolutePathCorrectionEngine(model, CORRECTION_THRESHOLD, USE_FORWARD_MATCHING); @@ -119,7 +118,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSugges @Test public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; - String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String userInput = userInputWithoutPath + stringRelativePathToCs2103t; String arg = userInput.replace(COMMAND_WORD, ""); model.setInput(userInput); @@ -128,7 +127,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, stringRelativePathToCs2103t)), model.responseTextProperty().getValue()); List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); @@ -142,7 +141,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC @Test public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = "op "; - String userInput = userInputWithoutPath + RELATIVE_PATH_TO_CS2103T; + String userInput = userInputWithoutPath + stringRelativePathToCs2103t; String arg = userInput.replace("op", ""); model.setInput(userInput); @@ -151,7 +150,7 @@ public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSugges command.get().execute(model); - assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, RELATIVE_PATH_TO_CS2103T)), + assertEquals(Optional.of(String.format(RESPONSE_MESSAGE_WITH_TITLE, stringRelativePathToCs2103t)), model.responseTextProperty().getValue()); List expectedSuggestions = SuggestionTestUtil.getExpectedSugForCs2103tPathInput(); diff --git a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java index 8519025d553..99645bf0c7f 100644 --- a/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java +++ b/src/test/java/com/notably/logic/suggestion/SuggestionTestUtil.java @@ -35,6 +35,10 @@ public static AbsolutePath getToCs2103t() { return TypicalBlockModel.PATH_TO_CS2103T; } + public static String getStringRelativePathToCs2103t() { + return "CS2103T"; + } + public static List getExpectedSugForCs2103tPathInput() { SuggestionItem cs2103t = new SuggestionItemImpl( TypicalBlockModel.PATH_TO_CS2103T.getStringRepresentation(), () -> {}); From 0a83716904839ab65403206e8ea0c7c64d70ce00 Mon Sep 17 00:00:00 2001 From: johannagwan Date: Fri, 10 Apr 2020 15:53:33 +0800 Subject: [PATCH 49/49] Remove replace and hard-code arg --- .../DeleteSuggestionCommandParserTest.java | 20 +++++++++---------- .../OpenSuggestionCommandParserTest.java | 16 +++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java index fdab1a567c2..a4d0f154fca 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/DeleteSuggestionCommandParserTest.java @@ -73,7 +73,7 @@ public void parse_correctCmdWithoutPath_returnsOptionalEmpty() { public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + PREFIX_TITLE + " " + toCs2103t.getStringRepresentation(); model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -94,9 +94,9 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsDeleteSuggestio @Test public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = "dele "; + String userInputWithoutPath = "dele"; String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace("dele", ""); + String arg = " " + toCs2103t.getStringRepresentation(); model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -119,7 +119,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsDeleteSugg public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; String userInput = userInputWithoutPath + stringRelativePathToCs2103t; - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + PREFIX_TITLE + " " + stringRelativePathToCs2103t; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -140,9 +140,9 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsDeleteSuggestio @Test public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsDeleteSuggestionCommand() { - String userInputWithoutPath = "dele "; + String userInputWithoutPath = "dele"; String userInput = userInputWithoutPath + stringRelativePathToCs2103t; - String arg = userInput.replace("dele", ""); + String arg = " " + stringRelativePathToCs2103t; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -166,7 +166,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsDeleteSugge String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; String path = "/Y2S2/CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace("dele", ""); + String arg = " " + PREFIX_TITLE + " " + path; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -190,7 +190,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsDeleteSugg String userInputWithoutPath = COMMAND_WORD + " "; String path = "/Y2S2/CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + path; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -214,7 +214,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsDeleteSugge String userInputWithoutPath = "dele " + PREFIX_TITLE + " "; String path = "CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace("dele", ""); + String arg = " " + PREFIX_TITLE + " " + path; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); @@ -238,7 +238,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsDeleteSugg String userInputWithoutPath = COMMAND_WORD + " "; String path = "CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + path; model.setInput(userInput); Optional command = deleteSuggestionCommandParser.parse(arg); diff --git a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java index 72180bc2b52..0791eb6eb7a 100644 --- a/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java +++ b/src/test/java/com/notably/logic/parser/suggestion/OpenSuggestionCommandParserTest.java @@ -73,7 +73,7 @@ public void parse_correctCmdWithoutPath_returnsOptionalEmpty() { public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + PREFIX_TITLE + " " + toCs2103t.getStringRepresentation(); model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -96,7 +96,7 @@ public void parse_correctCmdcorrectAbsolutePathWithPrefix_returnsOpenSuggestionC public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = "op "; String userInput = userInputWithoutPath + toCs2103t.getStringRepresentation(); - String arg = userInput.replace("op", ""); + String arg = " " + toCs2103t.getStringRepresentation(); model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -119,7 +119,7 @@ public void parse_correctedCmdcorrectAbsolutePathWithoutPrefix_returnsOpenSugges public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = COMMAND_WORD + " " + PREFIX_TITLE + " "; String userInput = userInputWithoutPath + stringRelativePathToCs2103t; - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + PREFIX_TITLE + " " + stringRelativePathToCs2103t; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -142,7 +142,7 @@ public void parse_correctCmdcorrectRelativePathWithPrefix_returnsOpenSuggestionC public void parse_correctedCmdcorrectRelativePathWithoutPrefix_returnsOpenSuggestionCommand() { String userInputWithoutPath = "op "; String userInput = userInputWithoutPath + stringRelativePathToCs2103t; - String arg = userInput.replace("op", ""); + String arg = " " + stringRelativePathToCs2103t; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -166,7 +166,7 @@ public void parse_correctedCmdcorrectedAbsolutePathWithPrefix_returnsOpenSuggest String userInputWithoutPath = "op " + PREFIX_TITLE + " "; String path = "/Y2S2/CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace("op", ""); + String arg = " " + PREFIX_TITLE + " " + path; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -190,7 +190,7 @@ public void parse_correctCmdcorrectedAbsolutePathWithoutPrefix_returnsOpenSugges String userInputWithoutPath = COMMAND_WORD + " "; String path = "/Y2S2/CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + path; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -214,7 +214,7 @@ public void parse_correctedCmdcorrectedRelativePathWithPrefix_returnsOpenSuggest String userInputWithoutPath = "op " + PREFIX_TITLE + " "; String path = "CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace("op", ""); + String arg = " " + PREFIX_TITLE + " " + path; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg); @@ -238,7 +238,7 @@ public void parse_correctCmdcorrectedRelativePathWithoutPrefix_returnsOpenSugges String userInputWithoutPath = COMMAND_WORD + " "; String path = "CS2104"; String userInput = userInputWithoutPath + path; - String arg = userInput.replace(COMMAND_WORD, ""); + String arg = " " + path; model.setInput(userInput); Optional command = openSuggestionCommandParser.parse(arg);