Skip to content

Commit

Permalink
# This is a combination of 7 commits.
Browse files Browse the repository at this point in the history
# 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
BillChee123 committed Nov 8, 2019
1 parent e55ca10 commit 11b1772
Show file tree
Hide file tree
Showing 20 changed files with 548 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion docs/diagrams/ImportExportObjectDiagram.puml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ object "__:ExportCommand__" as ExportCommand

LoadCommand --> model
StageCommand --> model
StageCommand --> model
UnstageCommand --> model
ExportCommand --> model
ImportCommand --> model
Expand Down
Binary file modified docs/images/ImportExportObjectDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/livingonedge.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/livingonedge.png
Binary file not shown.
4 changes: 3 additions & 1 deletion docs/team/livingonedge.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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;

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;
Expand Down Expand Up @@ -37,22 +37,22 @@ 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<DirectoryPath> exportPath;
private boolean isApplicationPath;

/**
* Creates an ExportCommand to export the memes from the specified {@code Path}.
*/
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;
}

Expand All @@ -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);
Expand All @@ -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;
}

}
2 changes: 2 additions & 0 deletions src/main/java/seedu/weme/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/weme/model/util/ImageUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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))));
}

}
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));
}

}
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));

}


}
Loading

0 comments on commit 11b1772

Please sign in to comment.