Skip to content

Commit

Permalink
Merge pull request #223 from narwhalsilent/branch-testing
Browse files Browse the repository at this point in the history
Add tests for `JsonSerializableAddressBook`
  • Loading branch information
Joseph31416 authored Apr 15, 2024
2 parents 0e0ea99 + f4fafbd commit d31b671
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 66 deletions.
5 changes: 0 additions & 5 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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" ]
}
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" : [ ]
}
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" ]
}
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"phone": "9482424",
"email": "invalid@email!3e",
"address": "4th street",
"loanRecords" : {
"loans" : [ ],
"nextLoanId" : 1
}
} ]
"tags": [ ]
} ],
"loans" : [ ]
}
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" : [ ]
}
} ]
}
4 changes: 0 additions & 4 deletions src/test/java/seedu/address/commons/util/JsonUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
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);
}

}

0 comments on commit d31b671

Please sign in to comment.