diff --git a/.gitignore b/.gitignore index 5e59b862ba4..6bfa7a95821 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,12 @@ src/main/resources/docs/ /config.json /preferences.json /*.log.* +/export # Test sandbox files src/test/data/sandbox/ +src/test/data/sandbox2/ +src/test/data/sandbox3/ # MacOS custom attributes files created by Finder .DS_Store diff --git a/.travis.yml b/.travis.yml index 924a42eb8da..0703c6f91fa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,17 @@ script: >- ./config/travis/run-checks.sh && ./gradlew clean checkstyleMain checkstyleTest test coverage coveralls asciidoctor +services: + - xvfb + +before_install: + - sudo apt update + - sudo apt install openjfx + - sudo apt-get install at-spi2-core + - chmod +x ./gradlew + +install: true + deploy: skip_cleanup: true provider: script diff --git a/build.gradle b/build.gradle index c8bed559f5f..f076ad2141d 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,11 @@ dependencies { String jUnitVersion = '5.4.0' String javaFxVersion = '11' + testCompile "org.testfx:testfx-core:4.0.16-alpha" + testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.1' + testCompile "org.testfx:testfx-junit5:4.0.16-alpha" + testCompile "org.testfx:openjfx-monocle:8u76-b04" // jdk-9+181 for Java 9, jdk-11+26 for Java 11 + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' diff --git a/docs/diagrams/ImportExportObjectDiagram.puml b/docs/diagrams/ImportExportObjectDiagram.puml index be473b3cc01..bfe99871002 100644 --- a/docs/diagrams/ImportExportObjectDiagram.puml +++ b/docs/diagrams/ImportExportObjectDiagram.puml @@ -16,7 +16,6 @@ object "__:ExportCommand__" as ExportCommand LoadCommand --> model StageCommand --> model -StageCommand --> model UnstageCommand --> model ExportCommand --> model ImportCommand --> model diff --git a/docs/images/ImportExportObjectDiagram.png b/docs/images/ImportExportObjectDiagram.png index 438973ae107..005ae1b2fe3 100644 Binary files a/docs/images/ImportExportObjectDiagram.png and b/docs/images/ImportExportObjectDiagram.png differ diff --git a/docs/images/livingonedge.jpg b/docs/images/livingonedge.jpg new file mode 100644 index 00000000000..2c6e655a6ea Binary files /dev/null and b/docs/images/livingonedge.jpg differ diff --git a/docs/images/livingonedge.png b/docs/images/livingonedge.png deleted file mode 100644 index 562891c12b4..00000000000 Binary files a/docs/images/livingonedge.png and /dev/null differ diff --git a/docs/team/livingonedge.adoc b/docs/team/livingonedge.adoc index e815e970e78..7ae768090fc 100644 --- a/docs/team/livingonedge.adoc +++ b/docs/team/livingonedge.adoc @@ -40,8 +40,10 @@ For example, support commands such as edit, delete and clear commands have to be ** Enhancements to existing features: *** Added preferences tab (Pull request https://github.com/AY1920S1-CS2103-T16-3/main/commit/9984517448d90e019e7d6d68fa16e59122319325[#105]) ** Documentation: -*** Update User Stories for Developer Guide https://github.com/AY1920S1-CS2103-T16-3/main/commit/791f7149f336ac4e4c13ecabe6a334b4de00230a[#31] +*** Updated User Stories for Developer Guide https://github.com/AY1920S1-CS2103-T16-3/main/commit/791f7149f336ac4e4c13ecabe6a334b4de00230a[#31] *** Major update to User Guide for v1.3 release: https://github.com/AY1920S1-CS2103-T16-3/main/commit/f0773ea9194ee7fa731bc3ce708e234c4642df78[#153] +** Tools: +*** Added support for TestFX [https://github.com/AY1920S1-CS2103-T16-3/main/pull/230[#230]] ** Community: *** PRs reviewed (trivial): https://github.com/AY1920S1-CS2103-T16-3/main/pull/68[#68], https://github.com/AY1920S1-CS2103-T16-3/main/pull/49[#49], diff --git a/src/main/java/seedu/weme/logic/commands/exportcommand/ExportCommand.java b/src/main/java/seedu/weme/logic/commands/exportcommand/ExportCommand.java index d2e6cc00d7c..78f102c26ec 100644 --- a/src/main/java/seedu/weme/logic/commands/exportcommand/ExportCommand.java +++ b/src/main/java/seedu/weme/logic/commands/exportcommand/ExportCommand.java @@ -1,6 +1,5 @@ package seedu.weme.logic.commands.exportcommand; -import static java.util.Objects.isNull; import static java.util.Objects.nonNull; import static java.util.Objects.requireNonNull; import static seedu.weme.logic.parser.util.CliSyntax.PREFIX_FILEPATH; @@ -8,6 +7,7 @@ import java.io.IOException; import java.nio.file.Path; import java.util.List; +import java.util.Optional; import seedu.weme.commons.util.FileUtil; import seedu.weme.logic.commands.Command; @@ -37,7 +37,7 @@ public class ExportCommand extends Command { "Invalid Default Export Path set. " + "Configure it in preferences.json and restart the application"; - private final DirectoryPath exportPath; + private final Optional exportPath; private boolean isApplicationPath; /** @@ -45,14 +45,14 @@ public class ExportCommand extends Command { */ public ExportCommand(DirectoryPath path) { requireNonNull(path); - exportPath = path; + exportPath = Optional.of(path); } /** * Creates an ExportCommand to export memes into the default directory path. */ public ExportCommand(boolean isApplicationPath) { - exportPath = null; + exportPath = Optional.empty(); this.isApplicationPath = isApplicationPath; } @@ -71,7 +71,7 @@ public CommandResult execute(Model model) throws CommandException { } public Path getExportPath(Model model) throws CommandException, IOException { - if (isNull(exportPath)) { + if (exportPath.isEmpty()) { assert nonNull(isApplicationPath) : "isApplicationExportPath is null"; if (isApplicationPath) { return FileUtil.getApplicationFolderPath(EXPORT_FOLDER_NAME); @@ -84,14 +84,15 @@ public Path getExportPath(Model model) throws CommandException, IOException { } } } - return exportPath.toPath(); + return exportPath.get().toPath(); } @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof ExportCommand // instanceof handles nulls - && exportPath.equals(((ExportCommand) other).exportPath)); + && exportPath.equals(((ExportCommand) other).exportPath)) + && isApplicationPath == ((ExportCommand) other).isApplicationPath; } } diff --git a/src/main/java/seedu/weme/model/ModelManager.java b/src/main/java/seedu/weme/model/ModelManager.java index 0341ce0bae9..40b2124a62b 100644 --- a/src/main/java/seedu/weme/model/ModelManager.java +++ b/src/main/java/seedu/weme/model/ModelManager.java @@ -524,6 +524,8 @@ public boolean equals(Object obj) { return versionedWeme.equals(other.versionedWeme) && userPrefs.equals(other.userPrefs) && filteredMemes.equals(other.filteredMemes) + && stagedMemeList.equals(other.stagedMemeList) + && importMemeList.equals(other.importMemeList) && context.getValue().equals(other.context.getValue()); } diff --git a/src/main/java/seedu/weme/model/util/ImageUtil.java b/src/main/java/seedu/weme/model/util/ImageUtil.java index 7d0e4a391b7..bc12cd3c85d 100644 --- a/src/main/java/seedu/weme/model/util/ImageUtil.java +++ b/src/main/java/seedu/weme/model/util/ImageUtil.java @@ -53,7 +53,7 @@ public static Template copyTemplate(Template toCopy, Path templateLocation) thro * @return the new {@code Path} of the copied image * @throws IOException if an error occurred during IO */ - private static Path copyImageFile(Path originalPath, Path destinationDir) throws IOException { + public static Path copyImageFile(Path originalPath, Path destinationDir) throws IOException { String extension = FileUtil.getExtension(originalPath).orElse(""); Path newPath = getNewImagePath(destinationDir, extension); FileUtil.copy(originalPath, newPath); diff --git a/src/test/java/seedu/weme/logic/commands/exportcommand/ExportCommandTest.java b/src/test/java/seedu/weme/logic/commands/exportcommand/ExportCommandTest.java new file mode 100644 index 00000000000..16ae909f22f --- /dev/null +++ b/src/test/java/seedu/weme/logic/commands/exportcommand/ExportCommandTest.java @@ -0,0 +1,63 @@ +package seedu.weme.logic.commands.exportcommand; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.weme.testutil.TypicalIndexes.INDEX_FIRST; +import static seedu.weme.testutil.TypicalWeme.getTypicalWeme; + +import org.junit.jupiter.api.Test; + +import seedu.weme.logic.commands.memecommand.MemeClearCommand; +import seedu.weme.model.DirectoryPath; +import seedu.weme.model.Model; +import seedu.weme.model.ModelManager; +import seedu.weme.model.UserPrefs; +import seedu.weme.model.meme.Meme; +import seedu.weme.testutil.TestUtil; + +class ExportCommandTest { + + private static final String VALID_SANDBOX_DIRECTORY = TestUtil.getSandboxFolder().toString(); + private static final String VALID_SANDBOX_DIRECTORY_2 = TestUtil.getSecondSandboxFolder().toString(); + private static final String INVALID_SANDBOX_DIRECTORY = TestUtil.getInvalidSandboxFolder().toString(); + + private final Model model = new ModelManager(getTypicalWeme(), new UserPrefs()); + private final Model expectedModel = new ModelManager(getTypicalWeme(), new UserPrefs()); + + @Test + public void execute_export_successMessage() { + Meme memeToStage = model.getWeme().getMemeList().get(INDEX_FIRST.getZeroBased()); + model.stageMeme(memeToStage); + expectedModel.stageMeme(memeToStage); + + ExportCommand exportCommand = new ExportCommand(new DirectoryPath(VALID_SANDBOX_DIRECTORY)); + + assertCommandSuccess(exportCommand, model, ExportCommand.MESSAGE_SUCCESS, expectedModel); + // Test if file is present in the folder + + TestUtil.clearSandBoxFolder(); + } + + @Test + public void equals() { + final ExportCommand standardCommand = new ExportCommand(new DirectoryPath(VALID_SANDBOX_DIRECTORY)); + + // same values -> returns true + ExportCommand commandWithSameValues = new ExportCommand(new DirectoryPath(VALID_SANDBOX_DIRECTORY)); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + // different types -> returns false + assertFalse(standardCommand.equals(new MemeClearCommand())); + + // different paths -> returns false + assertFalse(standardCommand.equals(new ExportCommand(new DirectoryPath(VALID_SANDBOX_DIRECTORY_2)))); + } + +} diff --git a/src/test/java/seedu/weme/logic/commands/exportcommand/UnstageCommandTest.java b/src/test/java/seedu/weme/logic/commands/exportcommand/UnstageCommandTest.java new file mode 100644 index 00000000000..1b0a1000bbe --- /dev/null +++ b/src/test/java/seedu/weme/logic/commands/exportcommand/UnstageCommandTest.java @@ -0,0 +1,72 @@ +package seedu.weme.logic.commands.exportcommand; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.weme.commons.core.Messages.MESSAGE_INVALID_MEME_DISPLAYED_INDEX; +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.weme.testutil.TypicalIndexes.INDEX_FIRST; +import static seedu.weme.testutil.TypicalIndexes.INDEX_SECOND; +import static seedu.weme.testutil.TypicalWeme.getTypicalWeme; + +import org.junit.jupiter.api.Test; + +import seedu.weme.logic.commands.memecommand.MemeStageCommand; +import seedu.weme.model.Model; +import seedu.weme.model.ModelManager; +import seedu.weme.model.UserPrefs; +import seedu.weme.model.meme.Meme; + +class UnstageCommandTest { + private final Model model = new ModelManager(getTypicalWeme(), new UserPrefs()); + private final Model expectedModel = new ModelManager(getTypicalWeme(), new UserPrefs()); + + @Test + public void execute_unstageMeme_success() { + Meme memeToStage = model.getWeme().getMemeList().get(INDEX_FIRST.getZeroBased()); + expectedModel.stageMeme(memeToStage); + + MemeStageCommand memeStageCommand = new MemeStageCommand(INDEX_FIRST); + + String expectedMessageStaged = String.format(MemeStageCommand.MESSAGE_SUCCESS, memeToStage); + expectedModel.commitWeme(expectedMessageStaged); + assertCommandSuccess(memeStageCommand, model, expectedMessageStaged, expectedModel); + + String expectedMessageUnstaged = String.format(UnstageCommand.MESSAGE_SUCCESS, memeToStage); + expectedModel.unstageMeme(memeToStage); + expectedModel.commitWeme(expectedMessageUnstaged); + UnstageCommand unstageCommand = new UnstageCommand(INDEX_FIRST); + assertCommandSuccess(unstageCommand, model, expectedMessageUnstaged, expectedModel); + + } + + @Test + public void execute_invalidMemeIndex_failure() { + // Attempt to unstage a meme in the empty staged list. + UnstageCommand unstageCommand = new UnstageCommand(INDEX_FIRST); + assertCommandFailure(unstageCommand, model, MESSAGE_INVALID_MEME_DISPLAYED_INDEX); + } + + @Test + public void equals() { + UnstageCommand unstageFirstCommand = new UnstageCommand(INDEX_FIRST); + UnstageCommand unstageSecondCommand = new UnstageCommand(INDEX_SECOND); + + // same object -> returns true + assertTrue(unstageFirstCommand.equals(unstageFirstCommand)); + + // same values -> returns true + UnstageCommand unstageFirstCommandCopy = new UnstageCommand(INDEX_FIRST); + assertTrue(unstageFirstCommand.equals(unstageFirstCommandCopy)); + + // different types -> returns false + assertFalse(unstageFirstCommand.equals(1)); + + // null -> returns false + assertFalse(unstageFirstCommand.equals(null)); + + // different meme -> returns false + assertFalse(unstageFirstCommand.equals(unstageSecondCommand)); + } + +} diff --git a/src/test/java/seedu/weme/logic/commands/importcommand/ImportCommandTest.java b/src/test/java/seedu/weme/logic/commands/importcommand/ImportCommandTest.java new file mode 100644 index 00000000000..e08997a4188 --- /dev/null +++ b/src/test/java/seedu/weme/logic/commands/importcommand/ImportCommandTest.java @@ -0,0 +1,107 @@ +package seedu.weme.logic.commands.importcommand; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.weme.testutil.TypicalWeme.getTypicalWeme; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; +import java.util.Set; + +import org.junit.jupiter.api.Test; + +import org.testfx.framework.junit5.ApplicationTest; + +import seedu.weme.commons.util.FileUtil; +import seedu.weme.model.DirectoryPath; +import seedu.weme.model.Model; +import seedu.weme.model.ModelManager; +import seedu.weme.model.UserPrefs; +import seedu.weme.model.imagePath.ImagePath; +import seedu.weme.model.meme.Description; +import seedu.weme.model.meme.Meme; +import seedu.weme.model.tag.Tag; +import seedu.weme.model.util.ImageUtil; + +class ImportCommandTest extends ApplicationTest { + + private static final DirectoryPath LOAD_DIRECTORY_PATH = new DirectoryPath("src/test/data/memes/"); + + private final Model model = new ModelManager(getTypicalWeme(), new UserPrefs()); + private final Model expectedModel = new ModelManager(getTypicalWeme(), new UserPrefs()); + + @Test + public void execute_import_successMessage() throws IOException { + + List pathList = FileUtil.loadImagePath(LOAD_DIRECTORY_PATH); + expectedModel.loadMemes(pathList); + + LoadCommand loadCommand = new LoadCommand(LOAD_DIRECTORY_PATH); + + assertCommandSuccess(loadCommand, model, LoadCommand.MESSAGE_SUCCESS, expectedModel); + + // importing the memes + for (Meme meme : expectedModel.getImportList()) { + Meme copiedMeme = copyMeme(meme, expectedModel.getMemeImagePath()); + expectedModel.addMeme(copiedMeme); + } + expectedModel.clearImportList(); + expectedModel.commitWeme(ImportCommand.MESSAGE_SUCCESS); + + assertCommandSuccess(new ImportCommand(), model, ImportCommand.MESSAGE_SUCCESS, expectedModel); + + } + + private MemeStub copyMeme(Meme toCopy, Path memeLocation) throws IOException { + Path originalPath = toCopy.getImagePath().getFilePath(); + Path newPath = ImageUtil.copyImageFile(originalPath, memeLocation); + return new MemeStub(new ImagePath(newPath.toString()), toCopy.getDescription(), toCopy.getTags()); + } + + /** + * A meme stub that checks for equality without checking for filePath to + * bypass the random UUID generation issue. + */ + private class MemeStub extends Meme { + + public MemeStub(ImagePath imagePath, Description description, Set tags) { + super(imagePath, description, tags); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof Meme)) { + return false; + } + + Meme otherMeme = (Meme) other; + return otherMeme.getDescription().equals(getDescription()) + && otherMeme.getTags().equals(getTags()) + && otherMeme.isArchived() == isArchived(); + } + } + + @Test + public void equals() { + final ImportCommand standardCommand = new ImportCommand(); + + // same values -> returns true + ImportCommand commandWithSameValues = new ImportCommand(); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + } + + +} diff --git a/src/test/java/seedu/weme/logic/commands/importcommand/LoadCommandTest.java b/src/test/java/seedu/weme/logic/commands/importcommand/LoadCommandTest.java new file mode 100644 index 00000000000..efb8a7552d9 --- /dev/null +++ b/src/test/java/seedu/weme/logic/commands/importcommand/LoadCommandTest.java @@ -0,0 +1,39 @@ +package seedu.weme.logic.commands.importcommand; + +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.weme.testutil.TypicalWeme.getTypicalWeme; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.List; + +import org.junit.jupiter.api.Test; + +import org.testfx.framework.junit5.ApplicationTest; + +import seedu.weme.commons.util.FileUtil; +import seedu.weme.model.DirectoryPath; +import seedu.weme.model.Model; +import seedu.weme.model.ModelManager; +import seedu.weme.model.UserPrefs; + +class LoadCommandTest extends ApplicationTest { + + private static final DirectoryPath LOAD_DIRECTORY_PATH = new DirectoryPath("src/test/data/memes/"); + + private final Model model = new ModelManager(getTypicalWeme(), new UserPrefs()); + private final Model expectedModel = new ModelManager(getTypicalWeme(), new UserPrefs()); + + @Test + public void execute_load_successMessage() throws IOException { + + List pathList = FileUtil.loadImagePath(LOAD_DIRECTORY_PATH); + expectedModel.loadMemes(pathList); + + LoadCommand loadCommand = new LoadCommand(LOAD_DIRECTORY_PATH); + + assertCommandSuccess(loadCommand, model, LoadCommand.MESSAGE_SUCCESS, expectedModel); + + } + +} diff --git a/src/test/java/seedu/weme/logic/commands/memecommand/MemeStageCommandTest.java b/src/test/java/seedu/weme/logic/commands/memecommand/MemeStageCommandTest.java new file mode 100644 index 00000000000..ae17d10b395 --- /dev/null +++ b/src/test/java/seedu/weme/logic/commands/memecommand/MemeStageCommandTest.java @@ -0,0 +1,116 @@ +package seedu.weme.logic.commands.memecommand; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.weme.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.weme.logic.commands.CommandTestUtil.showMemeAtIndex; +import static seedu.weme.logic.commands.memecommand.MemeStageCommand.MESSAGE_MEME_ALREADY_STAGED; +import static seedu.weme.testutil.TypicalIndexes.INDEX_FIRST; +import static seedu.weme.testutil.TypicalIndexes.INDEX_SECOND; +import static seedu.weme.testutil.TypicalIndexes.INDEX_THIRD; +import static seedu.weme.testutil.TypicalWeme.getTypicalWeme; + +import org.junit.jupiter.api.Test; + +import seedu.weme.commons.core.Messages; +import seedu.weme.commons.core.index.Index; +import seedu.weme.model.Model; +import seedu.weme.model.ModelManager; +import seedu.weme.model.UserPrefs; +import seedu.weme.model.meme.Meme; + +class MemeStageCommandTest { + private final Model model = new ModelManager(getTypicalWeme(), new UserPrefs()); + private final Model expectedModel = new ModelManager(getTypicalWeme(), new UserPrefs()); + + @Test + public void execute_stageMeme_success() { + Meme memeToStage = model.getWeme().getMemeList().get(INDEX_FIRST.getZeroBased()); + expectedModel.stageMeme(memeToStage); + + MemeStageCommand memeStageCommand = new MemeStageCommand(INDEX_FIRST); + + String expectedMessage = String.format(MemeStageCommand.MESSAGE_SUCCESS, memeToStage); + expectedModel.commitWeme(expectedMessage); + assertCommandSuccess(memeStageCommand, model, expectedMessage, expectedModel); + } + + @Test + public void execute_stageMultipleMemes_success() { + Meme memeToStage1 = model.getWeme().getMemeList().get(INDEX_FIRST.getZeroBased()); + Meme memeToStage2 = model.getWeme().getMemeList().get(INDEX_SECOND.getZeroBased()); + Meme memeToStage3 = model.getWeme().getMemeList().get(INDEX_THIRD.getZeroBased()); + + String expectedMessage1 = String.format(MemeStageCommand.MESSAGE_SUCCESS, memeToStage1); + String expectedMessage2 = String.format(MemeStageCommand.MESSAGE_SUCCESS, memeToStage2); + String expectedMessage3 = String.format(MemeStageCommand.MESSAGE_SUCCESS, memeToStage3); + + MemeStageCommand memeStageCommand1 = new MemeStageCommand(INDEX_FIRST); + MemeStageCommand memeStageCommand2 = new MemeStageCommand(INDEX_SECOND); + MemeStageCommand memeStageCommand3 = new MemeStageCommand(INDEX_THIRD); + + expectedModel.stageMeme(memeToStage1); + expectedModel.commitWeme(expectedMessage1); + assertCommandSuccess(memeStageCommand1, model, expectedMessage1, expectedModel); + + expectedModel.stageMeme(memeToStage2); + expectedModel.commitWeme(expectedMessage2); + assertCommandSuccess(memeStageCommand2, model, expectedMessage2, expectedModel); + + expectedModel.stageMeme(memeToStage3); + expectedModel.commitWeme(expectedMessage3); + assertCommandSuccess(memeStageCommand3, model, expectedMessage3, expectedModel); + } + + /** + * Stage filtered list where index is larger than size of filtered list, + * but smaller than size of the meme list. + */ + @Test + public void execute_invalidMemeIndexFilteredList_failure() { + showMemeAtIndex(model, INDEX_FIRST); + Index outOfBoundIndex = INDEX_SECOND; + // ensures that outOfBoundIndex is still in bounds of weme list + assertTrue(outOfBoundIndex.getZeroBased() < model.getWeme().getMemeList().size()); + + MemeStageCommand memeStageCommand = new MemeStageCommand(outOfBoundIndex); + + assertCommandFailure(memeStageCommand, model, Messages.MESSAGE_INVALID_MEME_DISPLAYED_INDEX); + } + + @Test + public void execute_stageStagedMeme_failure() { + Meme memeToStage = model.getWeme().getMemeList().get(INDEX_SECOND.getZeroBased()); + String expectedMessage = String.format(MemeStageCommand.MESSAGE_SUCCESS, memeToStage); + model.stageMeme(memeToStage); + model.commitWeme(expectedMessage); + + MemeStageCommand memeStageCommand = new MemeStageCommand(INDEX_SECOND); + + assertCommandFailure(memeStageCommand, model, MESSAGE_MEME_ALREADY_STAGED); + } + + @Test + public void equals() { + MemeStageCommand stageFirstCommand = new MemeStageCommand(INDEX_FIRST); + MemeStageCommand stageSecondCommand = new MemeStageCommand(INDEX_SECOND); + + // same object -> returns true + assertTrue(stageFirstCommand.equals(stageFirstCommand)); + + // same values -> returns true + MemeStageCommand stageFirstCommandCopy = new MemeStageCommand(INDEX_FIRST); + assertTrue(stageFirstCommand.equals(stageFirstCommandCopy)); + + // different types -> returns false + assertFalse(stageFirstCommand.equals(1)); + + // null -> returns false + assertFalse(stageFirstCommand.equals(null)); + + // different meme -> returns false + assertFalse(stageFirstCommand.equals(stageSecondCommand)); + } + +} diff --git a/src/test/java/seedu/weme/logic/parser/commandparser/exportcommandparser/ExportCommandParserTest.java b/src/test/java/seedu/weme/logic/parser/commandparser/exportcommandparser/ExportCommandParserTest.java new file mode 100644 index 00000000000..b77a82d5b2c --- /dev/null +++ b/src/test/java/seedu/weme/logic/parser/commandparser/exportcommandparser/ExportCommandParserTest.java @@ -0,0 +1,35 @@ +package seedu.weme.logic.parser.commandparser.exportcommandparser; + +import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.weme.logic.parser.util.CliSyntax.PREFIX_FILEPATH; + +import org.junit.jupiter.api.Test; + +import seedu.weme.logic.commands.exportcommand.ExportCommand; +import seedu.weme.model.DirectoryPath; +import seedu.weme.testutil.TestUtil; + +class ExportCommandParserTest { + + private static final String VALID_SANDBOX_DIRECTORY = TestUtil.getSandboxFolder().toString(); + private static final String SANDBOX_DIRECTORY_DESC = " " + PREFIX_FILEPATH + VALID_SANDBOX_DIRECTORY; + + private ExportCommandParser parser = new ExportCommandParser(); + + @Test + public void parse_pathSpecified_success() { + // sandbox path specified + DirectoryPath directoryPath = new DirectoryPath(VALID_SANDBOX_DIRECTORY); + + ExportCommand expectedCommand = new ExportCommand(directoryPath); + assertParseSuccess(parser, SANDBOX_DIRECTORY_DESC, expectedCommand); + } + + @Test + public void parse_noPathSpecified_success() { + ExportCommand expectedCommand = new ExportCommand(true); + + assertParseSuccess(parser, " ", expectedCommand); + } + +} diff --git a/src/test/java/seedu/weme/logic/parser/commandparser/exportcommandparser/UnstageCommandParserTest.java b/src/test/java/seedu/weme/logic/parser/commandparser/exportcommandparser/UnstageCommandParserTest.java new file mode 100644 index 00000000000..c0d4dafc5a2 --- /dev/null +++ b/src/test/java/seedu/weme/logic/parser/commandparser/exportcommandparser/UnstageCommandParserTest.java @@ -0,0 +1,26 @@ +package seedu.weme.logic.parser.commandparser.exportcommandparser; + +import static seedu.weme.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.weme.testutil.TypicalIndexes.INDEX_FIRST; + +import org.junit.jupiter.api.Test; + +import seedu.weme.logic.commands.exportcommand.UnstageCommand; + +class UnstageCommandParserTest { + + private UnstageCommandParser parser = new UnstageCommandParser(); + + @Test + public void parse_validArgs_returnsDeleteCommand() { + assertParseSuccess(parser, "1", new UnstageCommand(INDEX_FIRST)); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnstageCommand.MESSAGE_USAGE)); + } + +} diff --git a/src/test/java/seedu/weme/logic/parser/commandparser/memecommandparser/MemeStageCommandParserTest.java b/src/test/java/seedu/weme/logic/parser/commandparser/memecommandparser/MemeStageCommandParserTest.java new file mode 100644 index 00000000000..1653cfc5e18 --- /dev/null +++ b/src/test/java/seedu/weme/logic/parser/commandparser/memecommandparser/MemeStageCommandParserTest.java @@ -0,0 +1,27 @@ +package seedu.weme.logic.parser.commandparser.memecommandparser; + +import static seedu.weme.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.weme.testutil.TypicalIndexes.INDEX_FIRST; + +import org.junit.jupiter.api.Test; + +import seedu.weme.logic.commands.memecommand.MemeStageCommand; + + +class MemeStageCommandParserTest { + + private MemeStageCommandParser parser = new MemeStageCommandParser(); + + @Test + public void parse_validArgs_returnsStageCommand() { + assertParseSuccess(parser, "1", new MemeStageCommand(INDEX_FIRST)); + } + + @Test + public void parse_invalidArgs_throwsParseException() { + assertParseFailure(parser, "a", String.format(MESSAGE_INVALID_COMMAND_FORMAT, MemeStageCommand.MESSAGE_USAGE)); + } + +} diff --git a/src/test/java/seedu/weme/testutil/TestUtil.java b/src/test/java/seedu/weme/testutil/TestUtil.java index 31db19d040b..d72be5b3c5c 100644 --- a/src/test/java/seedu/weme/testutil/TestUtil.java +++ b/src/test/java/seedu/weme/testutil/TestUtil.java @@ -22,6 +22,10 @@ public class TestUtil { */ private static final Path SANDBOX_FOLDER = Paths.get("src", "test", "data", "sandbox"); + private static final Path SANDBOX_FOLDER_2 = Paths.get("src", "test", "data", "sandbox2"); + + private static final Path SANDBOX_FOLDER_3 = Paths.get("src", "test", "data", "sandbox3"); + /** * Appends {@code fileName} to the sandbox folder path and returns the resulting path. * Creates the sandbox folder if it doesn't exist. @@ -35,6 +39,32 @@ public static Path getFilePathInSandboxFolder(String fileName) { return SANDBOX_FOLDER.resolve(fileName); } + /** + * Returns the sandbox folder path. + * Creates the sandbox folder if it doesn't exist. + */ + public static Path getSandboxFolder() { + try { + Files.createDirectories(SANDBOX_FOLDER); + } catch (IOException e) { + throw new RuntimeException(e); + } + return SANDBOX_FOLDER; + } + + public static Path getSecondSandboxFolder() { + try { + Files.createDirectories(SANDBOX_FOLDER_2); + } catch (IOException e) { + throw new RuntimeException(e); + } + return SANDBOX_FOLDER_2; + } + + public static Path getInvalidSandboxFolder() { + return SANDBOX_FOLDER_3; + } + /** * Clears all files and directories in the sandbox folder. */