forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# This is a combination of 7 commits.
# This is the 1st commit message: Add Test for Stage and Unstage commands Add Parser Test for Stage and Unstage Command Add ExportCommandTest Fix checkstyle issues Add Load Command Test Add TestFX Set up TestFX Fix checkstyle issues Configure travis.yml Configure travis.yml Configure travis.yml Configure travis.yml Configure travis.yml Configure travis.yml Configure travis.yml Add ImportCommandTest # This is the commit message #2: Add Tests # This is the commit message #3: Configure travis # This is the commit message #4: Configure travis.yml # This is the commit message #5: Update ppp # This is the commit message #6: Update build.gradle # This is the commit message #7: Update ppp
- Loading branch information
1 parent
e55ca10
commit 11b1772
Showing
20 changed files
with
548 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
src/test/java/seedu/weme/logic/commands/exportcommand/ExportCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)))); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
src/test/java/seedu/weme/logic/commands/exportcommand/UnstageCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |
107 changes: 107 additions & 0 deletions
107
src/test/java/seedu/weme/logic/commands/importcommand/ImportCommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Path> 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<Tag> 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)); | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.