forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from moreTriangles/import-json
Test cases for Import
- Loading branch information
Showing
5 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
Empty file.
12 changes: 12 additions & 0 deletions
12
src/test/data/ExportImportCommandTest/FolderWithJson/testFile.json
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,12 @@ | ||
{ | ||
"persons" : [ | ||
{ | ||
"name": "Amy Bee", | ||
"telegram": "amy_bee", | ||
"phone": "85355255", | ||
"email": "[email protected]", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"tagged": [] | ||
} | ||
] | ||
} |
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
71 changes: 71 additions & 0 deletions
71
src/test/java/seedu/address/logic/commands/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,71 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; | ||
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.UserPrefs; | ||
import seedu.address.model.person.Person; | ||
import seedu.address.testutil.PersonBuilder; | ||
|
||
public class ImportCommandTest { | ||
private static final String PATH_EMPTY_FOLDER = "src/test/data/ExportImportCommandTest/EmptyFolder/"; | ||
private static final String PATH_FOLDER_WITH_JSON = "src/test/data/ExportImportCommandTest/FolderWithJson/"; | ||
private static final String TEST_FILE_NAME = "testFile"; | ||
|
||
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); | ||
|
||
@Test | ||
public void equals() { | ||
ImportCommand importFirstCommand = new ImportCommand("first"); | ||
ImportCommand importSecondCommand = new ImportCommand("second"); | ||
|
||
// same object -> returns true | ||
assertTrue(importFirstCommand.equals(importFirstCommand)); | ||
|
||
// same filename -> returns true | ||
assertTrue(importFirstCommand.equals(new ImportCommand("first"))); | ||
|
||
// different types -> returns false | ||
assertFalse(importFirstCommand.equals(1)); | ||
|
||
// null -> returns false | ||
assertFalse(importFirstCommand.equals(null)); | ||
|
||
// different filename -> returns false | ||
assertFalse(importFirstCommand.equals(importSecondCommand)); | ||
|
||
} | ||
|
||
/** | ||
* Imports the JSON file with the filename provided. | ||
* Test occurs in src/test/data/ExportImportCommandTest/FolderWithJson. | ||
*/ | ||
@Test | ||
public void execute_fileName_importSuccess() { | ||
Person newPerson = new PersonBuilder().build(); | ||
expectedModel.addPerson(newPerson); | ||
ImportCommand importNewPerson = new ImportCommand(PATH_FOLDER_WITH_JSON, TEST_FILE_NAME); | ||
String expectedMessage = String.format(ImportCommand.MESSAGE_IMPORT_SUCCESS, TEST_FILE_NAME); | ||
assertCommandSuccess(importNewPerson, model, expectedMessage, expectedModel); | ||
} | ||
|
||
/** | ||
* Import command fails when there is no file with the provided file name. | ||
* Test occurs in src/test/data/ExportImportCommandTest/EmptyFolder. | ||
*/ | ||
@Test | ||
public void execute_fileName_fileMissing() { | ||
String expectedMessage = String.format(ImportCommand.MESSAGE_IMPORT_FILE_NOT_FOUND, TEST_FILE_NAME); | ||
ImportCommand importNewPerson = new ImportCommand(PATH_EMPTY_FOLDER, TEST_FILE_NAME); | ||
assertCommandFailure(importNewPerson, model, expectedMessage); | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
src/test/java/seedu/address/logic/parser/ImportCommandParserTest.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,26 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_FILENAME_FRIENDS; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.ImportCommand; | ||
|
||
public class ImportCommandParserTest { | ||
|
||
private ImportCommandParser parser = new ImportCommandParser(); | ||
|
||
@Test | ||
public void parse_fileNamePresent_success() { | ||
// file name present | ||
assertParseSuccess(parser, VALID_FILENAME_FRIENDS, new ImportCommand(VALID_FILENAME_FRIENDS)); | ||
} | ||
|
||
@Test void parse_fileNameMissing_failure() { | ||
// file name missing | ||
assertParseFailure(parser, "", String.format(MESSAGE_INVALID_COMMAND_FORMAT, ImportCommand.MESSAGE_USAGE)); | ||
} | ||
} |