forked from nus-cs2103-AY2324S1/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.
Add unit tests for Json adapted classes in Storage
- Loading branch information
Showing
6 changed files
with
113 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"java.format.settings.url": "eclipse-formatter.xml" | ||
} |
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
58 changes: 58 additions & 0 deletions
58
src/test/java/seedu/address/storage/JsonAdaptedEventTest.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,58 @@ | ||
package seedu.address.storage; | ||
|
||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.storage.JsonAdaptedEvent.MISSING_FIELD_MESSAGE_FORMAT; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.model.event.EventInformation; | ||
import seedu.address.model.event.EventLocation; | ||
|
||
public class JsonAdaptedEventTest { | ||
private static final String VALID_NAME = "Meeting with professor"; | ||
private static final String VALID_START_TIME = "12:00"; | ||
private static final String VALID_END_TIME = "01:00"; | ||
private static final String VALID_LOCATION = "COM 1 Basement"; | ||
private static final String VALID_INFORMATION = "Discuss the project implementation with the professor"; | ||
|
||
@Test | ||
public void toModelType_nullName_throwsIllegalValueException() { | ||
JsonAdaptedEvent event = new JsonAdaptedEvent(null, VALID_START_TIME, VALID_END_TIME, VALID_LOCATION, | ||
VALID_INFORMATION); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, "name"); | ||
assertThrows(IllegalValueException.class, expectedMessage, event::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullStartTime_throwsIllegalValueException() { | ||
JsonAdaptedEvent event = new JsonAdaptedEvent(VALID_NAME, null, VALID_END_TIME, VALID_LOCATION, | ||
VALID_INFORMATION); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, "start"); | ||
assertThrows(IllegalValueException.class, expectedMessage, event::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullEndTime_throwsIllegalValueException() { | ||
JsonAdaptedEvent event = new JsonAdaptedEvent(VALID_NAME, VALID_START_TIME, null, VALID_LOCATION, | ||
VALID_INFORMATION); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, "end"); | ||
assertThrows(IllegalValueException.class, expectedMessage, event::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullLocation_throwsIllegalValueException() { | ||
JsonAdaptedEvent event = new JsonAdaptedEvent(VALID_NAME, VALID_START_TIME, VALID_END_TIME, null, | ||
VALID_INFORMATION); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, EventLocation.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, event::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullInformation_throwsIllegalValueException() { | ||
JsonAdaptedEvent event = new JsonAdaptedEvent(VALID_NAME, VALID_START_TIME, VALID_END_TIME, VALID_LOCATION, | ||
null); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, EventInformation.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, event::toModelType); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/seedu/address/storage/JsonAdaptedNoteTest.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,37 @@ | ||
package seedu.address.storage; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.storage.JsonAdaptedNote.MISSING_FIELD_MESSAGE_FORMAT; | ||
import static seedu.address.testutil.TypicalNotes.NOTE_A; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.model.note.NoteContent; | ||
import seedu.address.model.note.NoteTitle; | ||
|
||
public class JsonAdaptedNoteTest { | ||
private static final String VALID_TITLE = "Hello World!"; | ||
private static final String VALID_CONTENT = "CS2103T is the best module I've taken."; | ||
|
||
@Test | ||
public void toModelType_validNoteDetails_returnsNote() throws Exception { | ||
JsonAdaptedNote note = new JsonAdaptedNote(NOTE_A); | ||
assertEquals(NOTE_A, note.toModelType()); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullTitle_throwsIllegalValueException() { | ||
JsonAdaptedNote note = new JsonAdaptedNote(null, VALID_CONTENT); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, NoteTitle.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, note::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_nullContent_throwsIllegalValueException() { | ||
JsonAdaptedNote note = new JsonAdaptedNote(VALID_TITLE, null); | ||
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, NoteContent.class.getSimpleName()); | ||
assertThrows(IllegalValueException.class, expectedMessage, note::toModelType); | ||
} | ||
} |