forked from nus-cs2103-AY2324S2/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 #223 from narwhalsilent/branch-testing
Add tests for `JsonSerializableAddressBook`
- Loading branch information
Showing
8 changed files
with
158 additions
and
66 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
42 changes: 42 additions & 0 deletions
42
src/test/data/JsonSerializableAddressBookTest/duplicateLoanAddressBook.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,42 @@ | ||
{ | ||
"persons" : [ { | ||
"name" : "Alex Yeet", | ||
"phone" : "87438807", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Geylang Street 29, #06-40", | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Bernice Yu", | ||
"phone" : "99272758", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Lorong 3 Serangoon Gardens, #07-18", | ||
"tags" : [ "colleagues", "friends" ] | ||
} ], | ||
"loans" : [ { | ||
"value" : 200, | ||
"startDate" : "2024-02-02", | ||
"returnDate" : "2024-04-09", | ||
"id" : 2, | ||
"isReturned" : false, | ||
"assignee" : { | ||
"name" : "Alex Yeet", | ||
"phone" : "87438807", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Geylang Street 29, #06-40", | ||
"tags" : [ "friends" ] | ||
} | ||
}, { | ||
"value" : 2000, | ||
"startDate" : "2024-01-01", | ||
"returnDate" : "2024-04-11", | ||
"id" : 2, | ||
"isReturned" : true, | ||
"assignee" : { | ||
"name" : "Alex Yeet", | ||
"phone" : "87438807", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Geylang Street 29, #06-40", | ||
"tags" : [ "friends" ] | ||
} | ||
} ] | ||
} |
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 |
---|---|---|
|
@@ -4,19 +4,13 @@ | |
"phone": "94351253", | ||
"email": "[email protected]", | ||
"address": "123, Jurong West Ave 6, #08-111", | ||
"tags": [ "friends" ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags": [ "friends" ] | ||
}, { | ||
"name": "Alice Pauline", | ||
"phone": "94351253", | ||
"email": "[email protected]", | ||
"address": "4th street", | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
} ] | ||
"tags": [ "friends" ] | ||
} ], | ||
"loans" : [ ] | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/data/JsonSerializableAddressBookTest/invalidLoanAddressBook.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,29 @@ | ||
{ | ||
"persons" : [ { | ||
"name" : "Alex Yeet", | ||
"phone" : "87438807", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Geylang Street 29, #06-40", | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Bernice Yu", | ||
"phone" : "99272758", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Lorong 3 Serangoon Gardens, #07-18", | ||
"tags" : [ "colleagues", "friends" ] | ||
} ], | ||
"loans" : [ { | ||
"value" : 200, | ||
"startDate" : "2024-02-02", | ||
"returnDate" : "2024-04-09", | ||
"id" : 2, | ||
"isReturned" : false, | ||
"assignee" : { | ||
"name" : "Bernice Yu", | ||
"phone" : "87438807", | ||
"email" : "[email protected]", | ||
"address" : "Blk 30 Geylang Street 29, #06-40", | ||
"tags" : [ "friends" ] | ||
} | ||
} ] | ||
} |
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
81 changes: 46 additions & 35 deletions
81
src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.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 |
---|---|---|
@@ -1,74 +1,85 @@ | ||
{ | ||
"_comment": "AddressBook save file which contains the same Person values as in TypicalPersons#getTypicalAddressBook()", | ||
"persons" : [ { | ||
"name" : "Alice Pauline", | ||
"phone" : "94351253", | ||
"email" : "[email protected]", | ||
"address" : "123, Jurong West Ave 6, #08-111", | ||
"tags" : [ "friends" ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Benson Meier", | ||
"phone" : "98765432", | ||
"email" : "[email protected]", | ||
"address" : "311, Clementi Ave 2, #02-25", | ||
"tags" : [ "owesMoney", "friends" ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags" : [ "owesMoney", "friends" ] | ||
}, { | ||
"name" : "Carl Kurz", | ||
"phone" : "95352563", | ||
"email" : "[email protected]", | ||
"address" : "wall street", | ||
"tags" : [ ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags" : [ ] | ||
}, { | ||
"name" : "Daniel Meier", | ||
"phone" : "87652533", | ||
"email" : "[email protected]", | ||
"address" : "10th street", | ||
"tags" : [ "friends" ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags" : [ "friends" ] | ||
}, { | ||
"name" : "Elle Meyer", | ||
"phone" : "9482224", | ||
"email" : "[email protected]", | ||
"address" : "michegan ave", | ||
"tags" : [ ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags" : [ ] | ||
}, { | ||
"name" : "Fiona Kunz", | ||
"phone" : "9482427", | ||
"email" : "[email protected]", | ||
"address" : "little tokyo", | ||
"tags" : [ ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
} | ||
"tags" : [ ] | ||
}, { | ||
"name" : "George Best", | ||
"phone" : "9482442", | ||
"email" : "[email protected]", | ||
"address" : "4th street", | ||
"tags" : [ ], | ||
"loanRecords" : { | ||
"loans" : [ ], | ||
"nextLoanId" : 1 | ||
"tags" : [ ] | ||
} ], | ||
"loans" : [ { | ||
"value" : 100, | ||
"startDate" : "2020-01-01", | ||
"returnDate" : "2020-01-13", | ||
"id" : 1, | ||
"isReturned" : false, | ||
"assignee" : { | ||
"name" : "Alice Pauline", | ||
"phone" : "94351253", | ||
"email" : "[email protected]", | ||
"address" : "123, Jurong West Ave 6, #08-111", | ||
"tags" : [ "friends" ] | ||
} | ||
}, { | ||
"value" : 200, | ||
"startDate" : "2024-02-01", | ||
"returnDate" : "2024-02-13", | ||
"id" : 2, | ||
"isReturned" : false, | ||
"assignee" : { | ||
"name" : "Benson Meier", | ||
"phone" : "98765432", | ||
"email" : "[email protected]", | ||
"address" : "311, Clementi Ave 2, #02-25", | ||
"tags" : [ "owesMoney", "friends" ] | ||
} | ||
}, { | ||
"value" : 300, | ||
"startDate" : "2024-02-13", | ||
"returnDate" : "2024-02-14", | ||
"id" : 3, | ||
"isReturned" : false, | ||
"assignee" : { | ||
"name" : "Carl Kurz", | ||
"phone" : "95352563", | ||
"email" : "[email protected]", | ||
"address" : "wall street", | ||
"tags" : [ ] | ||
} | ||
} ] | ||
} |
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
41 changes: 34 additions & 7 deletions
41
src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.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 |
---|---|---|
@@ -1,35 +1,62 @@ | ||
package seedu.address.storage; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
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.AddressBook; | ||
|
||
public class JsonSerializableAddressBookTest { | ||
|
||
private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableAddressBookTest"); | ||
private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); | ||
private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); | ||
private static final Path INVALID_LOAN_FILE = TEST_DATA_FOLDER.resolve("invalidLoanAddressBook.json"); | ||
private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); | ||
private static final Path DUPLICATE_LOAN_FILE = TEST_DATA_FOLDER.resolve("duplicateLoanAddressBook.json"); | ||
|
||
@Test | ||
public void toModelType_typicalPersonsFile_success() throws Exception { | ||
// TODO: Implement test for JsonSerializableAddressBook.toModelType | ||
assertTrue(true); | ||
JsonSerializableAddressBook ab = | ||
JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE, JsonSerializableAddressBook.class).get(); | ||
AddressBook addressBook = ab.toModelType(); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidPersonFile_throwsIllegalValueException() throws Exception { | ||
// TODO: Implement test for JsonSerializableAddressBook.toModelType | ||
assertTrue(true); | ||
JsonSerializableAddressBook ab = | ||
JsonUtil.readJsonFile(INVALID_PERSON_FILE, JsonSerializableAddressBook.class).get(); | ||
assertThrows(IllegalValueException.class, ab::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { | ||
// TODO: Implement test for JsonSerializableAddressBook.toModelType | ||
assertTrue(true); | ||
JsonSerializableAddressBook ab = | ||
JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE, JsonSerializableAddressBook.class).get(); | ||
assertThrows(IllegalValueException.class, | ||
JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, | ||
ab::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_invalidLoanFile_throwsIllegalValueException() throws Exception { | ||
JsonSerializableAddressBook ab = | ||
JsonUtil.readJsonFile(INVALID_LOAN_FILE, JsonSerializableAddressBook.class).get(); | ||
assertThrows(IllegalValueException.class, ab::toModelType); | ||
} | ||
|
||
@Test | ||
public void toModelType_duplicateLoans_throwsIllegalValueException() throws Exception { | ||
JsonSerializableAddressBook ab = | ||
JsonUtil.readJsonFile(DUPLICATE_LOAN_FILE, JsonSerializableAddressBook.class).get(); | ||
assertThrows(IllegalValueException.class, | ||
JsonSerializableAddressBook.MESSAGE_DUPLICATE_LOAN, | ||
ab::toModelType); | ||
} | ||
|
||
} |