diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 85b48f1ceff..ff825db3c9e 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -54,11 +54,6 @@ public Address getAddress() { return address; } - public Analytics getAnalytics() { // This method will likely be deprecated - // TODO - return null; - } - /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} * if modification is attempted. diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicateLoanAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicateLoanAddressBook.json new file mode 100644 index 00000000000..c10733d4e4e --- /dev/null +++ b/src/test/data/JsonSerializableAddressBookTest/duplicateLoanAddressBook.json @@ -0,0 +1,42 @@ +{ + "persons" : [ { + "name" : "Alex Yeet", + "phone" : "87438807", + "email" : "alexyeoh@example.com", + "address" : "Blk 30 Geylang Street 29, #06-40", + "tags" : [ "friends" ] + }, { + "name" : "Bernice Yu", + "phone" : "99272758", + "email" : "berniceyu@example.com", + "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" : "alexyeoh@example.com", + "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" : "alexyeoh@example.com", + "address" : "Blk 30 Geylang Street 29, #06-40", + "tags" : [ "friends" ] + } + } ] +} diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index bcfb7ac765e..fb80ae7c959 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -4,19 +4,13 @@ "phone": "94351253", "email": "alice@example.com", "address": "123, Jurong West Ave 6, #08-111", - "tags": [ "friends" ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags": [ "friends" ] }, { "name": "Alice Pauline", "phone": "94351253", "email": "pauline@example.com", "address": "4th street", - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } - } ] + "tags": [ "friends" ] + } ], + "loans" : [ ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/invalidLoanAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/invalidLoanAddressBook.json new file mode 100644 index 00000000000..2ef38e5073f --- /dev/null +++ b/src/test/data/JsonSerializableAddressBookTest/invalidLoanAddressBook.json @@ -0,0 +1,29 @@ +{ + "persons" : [ { + "name" : "Alex Yeet", + "phone" : "87438807", + "email" : "alexyeoh@example.com", + "address" : "Blk 30 Geylang Street 29, #06-40", + "tags" : [ "friends" ] + }, { + "name" : "Bernice Yu", + "phone" : "99272758", + "email" : "berniceyu@example.com", + "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" : "alexyeoh@example.com", + "address" : "Blk 30 Geylang Street 29, #06-40", + "tags" : [ "friends" ] + } + } ] +} diff --git a/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json index 2ab53b39d69..6113859e5af 100644 --- a/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/invalidPersonAddressBook.json @@ -4,9 +4,7 @@ "phone": "9482424", "email": "invalid@email!3e", "address": "4th street", - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } - } ] + "tags": [ ] + } ], + "loans" : [ ] } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index a4ec2f6dc35..eacfbab4da1 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -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" : "alice@example.com", "address" : "123, Jurong West Ave 6, #08-111", - "tags" : [ "friends" ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags" : [ "friends" ] }, { "name" : "Benson Meier", "phone" : "98765432", "email" : "johnd@example.com", "address" : "311, Clementi Ave 2, #02-25", - "tags" : [ "owesMoney", "friends" ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags" : [ "owesMoney", "friends" ] }, { "name" : "Carl Kurz", "phone" : "95352563", "email" : "heinz@example.com", "address" : "wall street", - "tags" : [ ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags" : [ ] }, { "name" : "Daniel Meier", "phone" : "87652533", "email" : "cornelia@example.com", "address" : "10th street", - "tags" : [ "friends" ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags" : [ "friends" ] }, { "name" : "Elle Meyer", "phone" : "9482224", "email" : "werner@example.com", "address" : "michegan ave", - "tags" : [ ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags" : [ ] }, { "name" : "Fiona Kunz", "phone" : "9482427", "email" : "lydia@example.com", "address" : "little tokyo", - "tags" : [ ], - "loanRecords" : { - "loans" : [ ], - "nextLoanId" : 1 - } + "tags" : [ ] }, { "name" : "George Best", "phone" : "9482442", "email" : "anna@example.com", "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" : "alice@example.com", + "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" : "johnd@example.com", + "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" : "heinz@example.com", + "address" : "wall street", + "tags" : [ ] } } ] } diff --git a/src/test/java/seedu/address/commons/util/JsonUtilTest.java b/src/test/java/seedu/address/commons/util/JsonUtilTest.java index d4907539dee..8d6aac1521b 100644 --- a/src/test/java/seedu/address/commons/util/JsonUtilTest.java +++ b/src/test/java/seedu/address/commons/util/JsonUtilTest.java @@ -38,8 +38,4 @@ public void deserializeObjectFromJsonFile_noExceptionThrown() throws IOException assertEquals(serializableTestClass.getListOfLocalDateTimes(), SerializableTestClass.getListTestValues()); assertEquals(serializableTestClass.getMapOfIntegerToString(), SerializableTestClass.getHashMapTestValues()); } - - //TODO: @Test jsonUtil_readJsonStringToObjectInstance_correctObject() - - //TODO: @Test jsonUtil_writeThenReadObjectToJson_correctObject() } diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index 507d80490ea..9fcecb8deee 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -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); } }