Skip to content

Commit

Permalink
Merge c7f4303 into d2160ca
Browse files Browse the repository at this point in the history
  • Loading branch information
BillChee123 committed Nov 8, 2019
2 parents d2160ca + c7f4303 commit 55c4684
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class LoadCommand extends Command {
+ PREFIX_FILEPATH + "C:/Users/username/Downloads/ ";
public static final String MESSAGE_SUCCESS = "Memes loaded successfully to the import staging area.";
public static final String MESSAGE_LOAD_FAILURE = "Invalid directory path given.";
public static final String MESSAGE_LOAD_NON_EMPTY_TAB_FAILURE = "There are memes present in the import tab. "
+ "Please import them first or clear them before loading again.";
private final DirectoryPath importDirectoryPath;

/**
Expand All @@ -44,6 +46,9 @@ public LoadCommand(DirectoryPath path) {
@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
if (!model.getImportList().isEmpty()) {
throw new CommandException(MESSAGE_LOAD_NON_EMPTY_TAB_FAILURE);
}

try {
List<Path> pathList = FileUtil.loadImagePath(importDirectoryPath);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/weme/model/path/DirectoryPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public DirectoryPath(String directoryPath) {
/**
* Returns true if the given string is a valid Path.
*/
private boolean isValidDirectoryPath(String test) {
public static boolean isValidDirectoryPath(String test) {
// Paths.get() throws InvalidPathException when the path is a invalid.
// It is caught and becomes return false.
return FileUtil.isValidDirectoryPath(test);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.weme.logic.commands.importcommand;

import static seedu.weme.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.weme.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.weme.testutil.TypicalWeme.getTypicalWeme;

Expand Down Expand Up @@ -35,4 +36,16 @@ public void execute_load_successMessage() throws IOException {

}

@Test
public void execute_loadNonEmptyImportTab_failure() 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);

assertCommandFailure(loadCommand, model, LoadCommand.MESSAGE_LOAD_NON_EMPTY_TAB_FAILURE);
}

}
55 changes: 55 additions & 0 deletions src/test/java/seedu/weme/model/path/DirectoryPathTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.weme.model.path;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.weme.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.weme.model.meme.Description;
import seedu.weme.testutil.TestUtil;

class DirectoryPathTest {

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 static final String SAMPLE_DESCRIPTION = "Sample Description";

@Test
public void constructor_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new DirectoryPath(null));
}

@Test
public void isValidDirectoryPath() {
// null directory path
assertThrows(NullPointerException.class, () -> DirectoryPath.isValidDirectoryPath(null));

// valid directory path
assertTrue(DirectoryPath.isValidDirectoryPath("")); // empty string
assertTrue(DirectoryPath.isValidDirectoryPath(VALID_SANDBOX_DIRECTORY)); // valid directory path
assertFalse(DirectoryPath.isValidDirectoryPath(INVALID_SANDBOX_DIRECTORY)); // invalid directory path
}

@Test
public void equals() {
final DirectoryPath directoryPath = new DirectoryPath(VALID_SANDBOX_DIRECTORY);

// same values -> returns true
assertTrue(directoryPath.equals(new DirectoryPath(VALID_SANDBOX_DIRECTORY)));

// same object -> returns true
assertTrue(directoryPath.equals(directoryPath));

// null -> returns false
assertFalse(directoryPath.equals(null));

// different types -> returns false
assertFalse(directoryPath.equals(new Description(SAMPLE_DESCRIPTION)));

// different paths -> returns false
assertFalse(directoryPath.equals(new DirectoryPath(VALID_SANDBOX_DIRECTORY_2)));
}

}

0 comments on commit 55c4684

Please sign in to comment.