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 #205 from wlren/branch-tests
Update Storage test and Minor changes to UG
- Loading branch information
Showing
8 changed files
with
190 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
43 changes: 43 additions & 0 deletions
43
src/test/data/JsonSerializableTaskListTest/invalidTasksTaskList.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,43 @@ | ||
{ | ||
"tasks" : [ { | ||
"title" : "Finish CS2103 tasks", | ||
"description" : "1. Settle merge conflicts \n2. Create new PR\n3. Triage PE-D Bugs", | ||
"timestamp" : "invalid timestamp", | ||
"isDone" : "Not Done", | ||
"tagged" : [ "todo", "urgent" ], | ||
"contacts" : [ { | ||
"name" : "Jeremy", | ||
"isInAddressBook" : false | ||
}, { | ||
"name" : "Roy Balakrishnan", | ||
"isInAddressBook" : true | ||
} ] | ||
}, { | ||
"title" : "Finish CS2105 Assignment", | ||
"description" : "Finish up the last question", | ||
"timestamp" : "08-11-2021", | ||
"isDone" : "Not Done", | ||
"tagged" : [ ], | ||
"contacts" : [ ] | ||
}, { | ||
"title" : "Submit CS2100 Assignment", | ||
"description" : "Upload to Luminus", | ||
"timestamp" : "08-11-2021", | ||
"isDone" : "Done", | ||
"tagged" : [ "todo", "urgent" ], | ||
"contacts" : [ ] | ||
}, { | ||
"title" : "Finish this mod", | ||
"description" : "Submit this project", | ||
"timestamp" : "08-11-2021", | ||
"isDone" : "Not Done", | ||
"tagged" : [ "todo", "urgent" ], | ||
"contacts" : [ { | ||
"name" : "Jeremy", | ||
"isInAddressBook" : false | ||
}, { | ||
"name" : "Roy Balakrishnan", | ||
"isInAddressBook" : true | ||
} ] | ||
} ] | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/data/JsonSerializableTaskListTest/typicalTasksTaskList.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,37 @@ | ||
{ | ||
"tasks" : [ { | ||
"title" : "Buy groceries", | ||
"description" : "Two eggs, one carton of milk and five tomatoes", | ||
"timestamp" : "27-07-2021", | ||
"isDone" : "Not Done", | ||
"tagged" : [ ], | ||
"contacts" : [ ] | ||
}, { | ||
"title" : "Do homework", | ||
"description" : "Math, physics and chemistry", | ||
"timestamp" : "27-07-2021", | ||
"isDone" : "Not Done", | ||
"tagged" : [ "important", "homework" ], | ||
"contacts" : [ ] | ||
}, { | ||
"title" : "Clean my room", | ||
"description" : "Two eggs, one carton of milk and five tomatoes", | ||
"timestamp" : "27-07-2021", | ||
"isDone" : "Not Done", | ||
"tagged" : [ "important" ], | ||
"contacts" : [ { | ||
"name" : "Mother", | ||
"isInAddressBook" : false | ||
} ] | ||
}, { | ||
"title" : "Arrange meeting", | ||
"description" : "Two eggs, one carton of milk and five tomatoes", | ||
"timestamp" : "27-07-2021", | ||
"isDone" : "Done", | ||
"tagged" : [ "work", "important" ], | ||
"contacts" : [ { | ||
"name" : "Amy Bee", | ||
"isInAddressBook" : false | ||
} ] | ||
} ] | ||
} |
65 changes: 65 additions & 0 deletions
65
src/test/java/seedu/address/storage/JsonAdaptedTaskTest.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,65 @@ | ||
package seedu.address.storage; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static seedu.address.storage.JsonAdaptedTask.MISSING_FIELD_MESSAGE_FORMAT; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalTasks.BUY_GROCERIES; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
|
||
public class JsonAdaptedTaskTest { | ||
|
||
private static final String INVALID_TAG = "#friend"; | ||
private static final String INVALID_TIMESTAMP = "1999-06-23"; | ||
private static final String INVALID_CONTACT = "@jeff"; | ||
|
||
private static final String VALID_TITLE = BUY_GROCERIES.getTitle(); | ||
private static final String VALID_DESCRIPTION = BUY_GROCERIES.getDescription().get(); | ||
private static final String VALID_TIMESTAMP = BUY_GROCERIES.getTimestamp().get().toString(); | ||
private static final String VALID_ISDONE = BUY_GROCERIES.isDone() ? "Done" : "Not Done"; | ||
private static final List<JsonAdaptedTag> VALID_TAGS = BUY_GROCERIES.getTags().stream() | ||
.map(JsonAdaptedTag::new).collect(Collectors.toList()); | ||
private static final List<JsonAdaptedContact> VALID_CONTACTS = BUY_GROCERIES.getContacts().stream() | ||
.map(JsonAdaptedContact::new).collect(Collectors.toList()); | ||
|
||
|
||
@Test | ||
public void toModelType_validTaskDetails_returnsTask() throws Exception { | ||
JsonAdaptedTask task = new JsonAdaptedTask(BUY_GROCERIES); | ||
assertEquals(BUY_GROCERIES.getTitle(), task.toModelType().getTitle()); | ||
} | ||
|
||
@Test | ||
public void toModelType_nulTaskTitle_throwsIllegalValueException() { | ||
JsonAdaptedTask task = new JsonAdaptedTask(null, VALID_DESCRIPTION, | ||
VALID_TIMESTAMP, VALID_ISDONE, VALID_TAGS, VALID_CONTACTS); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, "title"); | ||
assertThrows(IllegalValueException.class, expectedMessage, task::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidTaskTags_throwsIllegalValueException() { | ||
List<JsonAdaptedTag> invalidTags = new ArrayList<>(VALID_TAGS); | ||
invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); | ||
JsonAdaptedTask task = | ||
new JsonAdaptedTask(VALID_TITLE, VALID_DESCRIPTION, VALID_TIMESTAMP, | ||
VALID_ISDONE, invalidTags, VALID_CONTACTS); | ||
assertThrows(IllegalValueException.class, task::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidTaskContacts_throwsIllegalValueException() { | ||
List<JsonAdaptedContact> invalidContacts = new ArrayList<>(VALID_CONTACTS); | ||
invalidContacts.add(new JsonAdaptedContact(INVALID_CONTACT, false)); | ||
JsonAdaptedTask task = | ||
new JsonAdaptedTask(VALID_TITLE, VALID_DESCRIPTION, VALID_TIMESTAMP, | ||
VALID_ISDONE, VALID_TAGS, invalidContacts); | ||
assertThrows(IllegalValueException.class, task::toModelType); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/java/seedu/address/storage/JsonSerializableTaskListTest.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,38 @@ | ||
package seedu.address.storage; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.commons.util.JsonUtil; | ||
import seedu.address.model.TaskList; | ||
import seedu.address.testutil.TypicalTasks; | ||
|
||
public class JsonSerializableTaskListTest { | ||
|
||
private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableTaskListTest"); | ||
private static final Path TYPICAL_TASKS_FILE = TEST_DATA_FOLDER.resolve("typicalTasksTaskList.json"); | ||
private static final Path INVALID_TASKS_FILE = TEST_DATA_FOLDER.resolve("invalidTasksTaskList.json"); | ||
|
||
@Test | ||
public void toModelType_typicalTasksFile_success() throws Exception { | ||
JsonSerializableTaskList dataFromFile = JsonUtil.readJsonFile(TYPICAL_TASKS_FILE, | ||
JsonSerializableTaskList.class).get(); | ||
TaskList tasklistFromFile = dataFromFile.toModelType(); | ||
TaskList typicalTasksTaskList = TypicalTasks.getTypicalTaskList(); | ||
assertEquals(tasklistFromFile, typicalTasksTaskList); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidTaskFile_throwsIllegalValueException() throws Exception { | ||
JsonSerializableTaskList dataFromFile = JsonUtil.readJsonFile(INVALID_TASKS_FILE, | ||
JsonSerializableTaskList.class).get(); | ||
assertThrows(IllegalValueException.class, dataFromFile::toModelType); | ||
} | ||
|
||
} |
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