From d1f63e4ca8f79b8330fcad97e53d8be249bec790 Mon Sep 17 00:00:00 2001 From: zoebelle-pang Date: Thu, 21 Mar 2024 13:43:56 +0800 Subject: [PATCH] no message --- .../java/seedu/address/ui/PersonCard.java | 3 +- .../duplicatePersonAddressBook.json | 4 ++ .../typicalPersonsAddressBook.json | 14 ++++ .../logic/commands/CommandTestUtil.java | 13 ++++ .../logic/parser/AddCommandParserTest.java | 50 +++++++++----- .../address/logic/parser/ParserUtilTest.java | 39 +++++++++++ .../address/model/person/AttendanceTest.java | 54 +++++++++++++++ .../address/model/person/PaymentTest.java | 54 +++++++++++++++ .../address/model/person/PersonTest.java | 1 + .../storage/JsonAdaptedPersonTest.java | 69 +++++++++++++------ .../seedu/address/testutil/PersonBuilder.java | 28 +++++++- 11 files changed, 289 insertions(+), 40 deletions(-) create mode 100644 src/test/java/seedu/address/model/person/AttendanceTest.java create mode 100644 src/test/java/seedu/address/model/person/PaymentTest.java diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 919e7755230..205f7062ffd 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -44,6 +44,7 @@ public class PersonCard extends UiPart { private Label grade; @FXML private Label subject; + @FXML private Label attendance; @FXML private Label payment; @@ -72,7 +73,7 @@ public PersonCard(Person person, int displayedIndex) { .sorted(Comparator.comparing(dateTime -> dateTime.value)) .forEach(dateTime -> dateTimes.getChildren() .add(new Label(LocalDateTime.parse(dateTime.value, - DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")) + DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")) .format(DateTimeFormatter.ofPattern("MMM d uuuu h:mma"))))); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) diff --git a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json index 6a9a482c548..b4b23e9bcab 100644 --- a/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/duplicatePersonAddressBook.json @@ -6,6 +6,8 @@ "address": "123, Jurong West Ave 6, #08-111", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-03-02 1800" ], "tags": [ "friends" ] }, { @@ -14,6 +16,8 @@ "email": "pauline@example.com", "grade": "A", "subject": "Maths", + "attendance": "Present", + "payment": "Not Paid", "dateTimes": [ "2024-03-21 1800" ], "address": "4th street" } ] diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json index 84564f39c66..f7d676290d7 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalPersonsAddressBook.json @@ -7,6 +7,8 @@ "address" : "123, Jurong West Ave 6, #08-111", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ ], "tags" : [ "friends" ] }, { @@ -16,6 +18,8 @@ "address" : "311, Clementi Ave 2, #02-25", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-02-03 1800" ], "tags" : [ "owesMoney", "friends" ] }, { @@ -25,6 +29,8 @@ "address" : "wall street", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-02-03 1800" ], "tags" : [ ] }, { @@ -34,6 +40,8 @@ "address" : "10th street", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-02-03 1800" ], "tags" : [ "friends" ] }, { @@ -43,6 +51,8 @@ "address" : "michegan ave", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-02-03 1800" ], "tags" : [ ] }, { @@ -52,6 +62,8 @@ "address" : "little tokyo", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-02-03 1800" ], "tags" : [ ] }, { @@ -61,6 +73,8 @@ "address" : "4th street", "grade": "A", "subject": "English", + "attendance": "Present", + "payment": "Paid", "dateTimes": [ "2024-02-03 1800" ], "tags" : [ ] } ] diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index e3327170120..0b12625e288 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -3,10 +3,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ATTENDANCE; import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PAYMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_SUBJECT; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -41,6 +43,10 @@ public class CommandTestUtil { public static final String VALID_GRADE_BOB = "B-"; public static final String VALID_SUBJECT_AMY = "Mathematics"; public static final String VALID_SUBJECT_BOB = "English"; + public static final String VALID_ATTENDANCE_PRESENT = "Present"; + public static final String VALID_ATTENDANCE_ABSENT = "Absent"; + public static final String VALID_PAYMENT_PAID = "Paid"; + public static final String VALID_PAYMENT_UNPAID = "Not Paid"; public static final String VALID_DATETIME_MAR = "2024-03-04 1800"; public static final String VALID_DATETIME_FEB = "2024-02-03 1800"; public static final String VALID_TAG_HUSBAND = "husband"; @@ -58,6 +64,10 @@ public class CommandTestUtil { public static final String GRADE_DESC_BOB = " " + PREFIX_GRADE + VALID_GRADE_BOB; public static final String SUBJECT_DESC_AMY = " " + PREFIX_SUBJECT + VALID_SUBJECT_AMY; public static final String SUBJECT_DESC_BOB = " " + PREFIX_SUBJECT + VALID_SUBJECT_BOB; + public static final String ATTENDANCE_DESC_PRESENT = " " + PREFIX_ATTENDANCE + VALID_ATTENDANCE_PRESENT; + public static final String ATTENDANCE_DESC_ABSENT = " " + PREFIX_ATTENDANCE + VALID_ATTENDANCE_ABSENT; + public static final String PAYMENT_DESC_PAID = " " + PREFIX_PAYMENT + VALID_PAYMENT_PAID; + public static final String PAYMENT_DESC_UNPAID = " " + PREFIX_PAYMENT + VALID_PAYMENT_UNPAID; public static final String DATETIME_DESC_MAR = " " + PREFIX_DATETIME + VALID_DATETIME_MAR; public static final String DATETIME_DESC_FEB = " " + PREFIX_DATETIME + VALID_DATETIME_FEB; @@ -70,6 +80,9 @@ public class CommandTestUtil { public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses public static final String INVALID_GRADE_DESC = " " + PREFIX_GRADE + "C++"; // extra + not allowed public static final String INVALID_SUBJECT_DESC = " " + PREFIX_SUBJECT; // empty string not allowed for subject + public static final String INVALID_ATTENDANCE_DESC = " " + PREFIX_ATTENDANCE + + "Prasent"; // extra characters not allowed + public static final String INVALID_PAYMENT_DESC = " " + PREFIX_PAYMENT + "paid1"; // numbers not allowed public static final String INVALID_DATETIME_DESC = " " + PREFIX_DATETIME + "2024-02-31 1800"; // invalid date not allowed in tags public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 72ea0019acb..b8afbfd5eab 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -3,6 +3,7 @@ import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.ATTENDANCE_DESC_PRESENT; import static seedu.address.logic.commands.CommandTestUtil.DATETIME_DESC_FEB; import static seedu.address.logic.commands.CommandTestUtil.DATETIME_DESC_MAR; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; @@ -10,15 +11,19 @@ import static seedu.address.logic.commands.CommandTestUtil.GRADE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.GRADE_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_ATTENDANCE_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_DATETIME_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_GRADE_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC; +import static seedu.address.logic.commands.CommandTestUtil.INVALID_PAYMENT_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_SUBJECT_DESC; import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB; +import static seedu.address.logic.commands.CommandTestUtil.PAYMENT_DESC_PAID; +import static seedu.address.logic.commands.CommandTestUtil.PAYMENT_DESC_UNPAID; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY; import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB; import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY; @@ -49,10 +54,12 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.AddCommand; import seedu.address.model.person.Address; +import seedu.address.model.person.Attendance; import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; +import seedu.address.model.person.Payment; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.person.Subject; @@ -210,38 +217,48 @@ public void parse_compulsoryFieldMissing_failure() { public void parse_invalidValue_failure() { // invalid name assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - Name.MESSAGE_CONSTRAINTS); + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + DATETIME_DESC_MAR + + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Name.MESSAGE_CONSTRAINTS); // invalid phone assertParseFailure(parser, NAME_DESC_BOB + INVALID_PHONE_DESC + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - Phone.MESSAGE_CONSTRAINTS); + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + DATETIME_DESC_MAR + + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Phone.MESSAGE_CONSTRAINTS); // invalid email assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ADDRESS_DESC_BOB - + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - Email.MESSAGE_CONSTRAINTS); + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + DATETIME_DESC_MAR + + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS); // invalid address assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC - + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - Address.MESSAGE_CONSTRAINTS); + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + DATETIME_DESC_MAR + + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Address.MESSAGE_CONSTRAINTS); // invalid grade assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + INVALID_GRADE_DESC + SUBJECT_DESC_BOB + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - Grade.MESSAGE_CONSTRAINTS); + + INVALID_GRADE_DESC + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Grade.MESSAGE_CONSTRAINTS); // invalid subject assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + GRADE_DESC_BOB + INVALID_SUBJECT_DESC + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - Subject.MESSAGE_CONSTRAINTS); + + GRADE_DESC_BOB + INVALID_SUBJECT_DESC + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Subject.MESSAGE_CONSTRAINTS); + + // invalid attendance + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + INVALID_ATTENDANCE_DESC + PAYMENT_DESC_PAID + + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Attendance.MESSAGE_CONSTRAINTS); + + // invalid payment + assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + INVALID_PAYMENT_DESC + + DATETIME_DESC_MAR + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Payment.MESSAGE_CONSTRAINTS); // invalid dateTime assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB - + GRADE_DESC_BOB + SUBJECT_DESC_BOB + INVALID_DATETIME_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, - DateTime.MESSAGE_CONSTRAINTS); + + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_PAID + + INVALID_DATETIME_DESC + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, DateTime.MESSAGE_CONSTRAINTS); // invalid tag assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB @@ -253,7 +270,8 @@ public void parse_invalidValue_failure() { // non-empty preamble assertParseFailure(parser, PREAMBLE_NON_EMPTY + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB - + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + DATETIME_DESC_FEB + TAG_DESC_HUSBAND - + TAG_DESC_FRIEND, String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); + + ADDRESS_DESC_BOB + GRADE_DESC_BOB + SUBJECT_DESC_BOB + ATTENDANCE_DESC_PRESENT + PAYMENT_DESC_UNPAID + + DATETIME_DESC_FEB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, + String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } } diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index cb9cfde4fd3..9c1bc59294c 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -15,10 +15,12 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; +import seedu.address.model.person.Attendance; import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; +import seedu.address.model.person.Payment; import seedu.address.model.person.Phone; import seedu.address.model.person.Subject; import seedu.address.model.tag.Tag; @@ -30,6 +32,8 @@ public class ParserUtilTest { private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_GRADE = "C++"; private static final String INVALID_SUBJECT = " "; + private static final String INVALID_ATTENDANCE = "Pressent"; + private static final String INVALID_PAYMENT = "PAID50"; private static final String INVALID_DATETIME = "2024-02-31 2500"; private static final String INVALID_TAG = "#friend"; @@ -39,6 +43,8 @@ public class ParserUtilTest { private static final String VALID_EMAIL = "rachel@example.com"; private static final String VALID_GRADE = "B-"; private static final String VALID_SUBJECT = "English"; + private static final String VALID_ATTENDANCE = "Present"; + private static final String VALID_PAYMENT = "Paid"; private static final String VALID_DATETIME_1 = "2024-02-03 1800"; private static final String VALID_DATETIME_2 = "2024-03-04 1900"; private static final String VALID_TAG_1 = "friend"; @@ -204,6 +210,39 @@ void parseSubject_validValueWithWhitespace_returnsTrimmedSubject() throws Except assertEquals(expectedSubject, ParserUtil.parseSubject(subjectWithWhitespace)); } + @Test + public void parseAttendance_invalidValue_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parseAttendance(INVALID_ATTENDANCE)); + } + @Test + public void parseAttendance_validValueWithoutWhitespace_returnsSubject() throws Exception { + Attendance expectedAttendance = new Attendance(VALID_ATTENDANCE); + assertEquals(expectedAttendance, ParserUtil.parseAttendance(VALID_ATTENDANCE)); + } + + @Test + void parseAttendance_validValueWithWhitespace_returnsTrimmedAttendance() throws Exception { + String attendanceWithWhitespace = WHITESPACE + VALID_ATTENDANCE + WHITESPACE; + Attendance expectedAttendance = new Attendance(VALID_ATTENDANCE); + assertEquals(expectedAttendance, ParserUtil.parseAttendance(attendanceWithWhitespace)); + } + @Test + public void parsePayment_invalidValue_throwsParseException() { + assertThrows(ParseException.class, () -> ParserUtil.parsePayment(INVALID_PAYMENT)); + } + @Test + public void parsePayment_validValueWithoutWhitespace_returnsPayment() throws Exception { + Payment expectedPayment = new Payment(VALID_PAYMENT); + assertEquals(expectedPayment, ParserUtil.parsePayment(VALID_PAYMENT)); + } + + @Test + void parsePayment_validValueWithWhitespace_returnsTrimmedPayment() throws Exception { + String paymentWithWhitespace = WHITESPACE + VALID_PAYMENT + WHITESPACE; + Payment expectedPayment = new Payment(VALID_PAYMENT); + assertEquals(expectedPayment, ParserUtil.parsePayment(paymentWithWhitespace)); + } + @Test public void parseDateTime_null_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> ParserUtil.parseDateTime(null)); diff --git a/src/test/java/seedu/address/model/person/AttendanceTest.java b/src/test/java/seedu/address/model/person/AttendanceTest.java new file mode 100644 index 00000000000..327df413474 --- /dev/null +++ b/src/test/java/seedu/address/model/person/AttendanceTest.java @@ -0,0 +1,54 @@ +package seedu.address.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +public class AttendanceTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Attendance(null)); + } + + @Test + public void constructor_invalidAttendance_throwsIllegalArgumentException() { + String invalidAttendance = "On leave"; + assertThrows(IllegalArgumentException.class, () -> new Attendance(invalidAttendance)); + } + + @Test + public void isValidAttendance() { + // null attendance + assertThrows(NullPointerException.class, () -> Attendance.isValidAttendance(null)); + + // invalid attendance + assertFalse(Attendance.isValidAttendance("On leave")); // Invalid status + + // valid attendance + assertTrue(Attendance.isValidAttendance("Present")); + assertTrue(Attendance.isValidAttendance("Absent")); + } + + @Test + public void equals() { + Attendance attendance = new Attendance("Present"); + + // same values -> returns true + assertTrue(attendance.equals(new Attendance("Present"))); + + // same object -> returns true + assertTrue(attendance.equals(attendance)); + + // null -> returns false + assertFalse(attendance.equals(null)); + + // different types -> returns false + assertFalse(attendance.equals(5.0f)); + + // different values -> returns false + assertFalse(attendance.equals(new Attendance("Absent"))); + } +} diff --git a/src/test/java/seedu/address/model/person/PaymentTest.java b/src/test/java/seedu/address/model/person/PaymentTest.java new file mode 100644 index 00000000000..d6f88fb1bf7 --- /dev/null +++ b/src/test/java/seedu/address/model/person/PaymentTest.java @@ -0,0 +1,54 @@ +package seedu.address.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +public class PaymentTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Payment(null)); + } + + @Test + public void constructor_invalidPayment_throwsIllegalArgumentException() { + String invalidPayment = "Unpaid"; + assertThrows(IllegalArgumentException.class, () -> new Payment(invalidPayment)); + } + + @Test + public void isValidPayment() { + // null payment + assertThrows(NullPointerException.class, () -> Payment.isValidPayment(null)); + + // invalid payment + assertFalse(Payment.isValidPayment("Unpaid")); // Invalid status + + // valid payment + assertTrue(Payment.isValidPayment("Paid")); + assertTrue(Payment.isValidPayment("Not Paid")); + } + + @Test + public void equals() { + Payment payment = new Payment("Paid"); + + // same values -> returns true + assertTrue(payment.equals(new Payment("Paid"))); + + // same object -> returns true + assertTrue(payment.equals(payment)); + + // null -> returns false + assertFalse(payment.equals(null)); + + // different types -> returns false + assertFalse(payment.equals(5.0f)); + + // different values -> returns false + assertFalse(payment.equals(new Payment("Not Paid"))); + } +} diff --git a/src/test/java/seedu/address/model/person/PersonTest.java b/src/test/java/seedu/address/model/person/PersonTest.java index bcf3034eeb2..7d0474f6d99 100644 --- a/src/test/java/seedu/address/model/person/PersonTest.java +++ b/src/test/java/seedu/address/model/person/PersonTest.java @@ -95,6 +95,7 @@ public void toStringMethod() { String expected = Person.class.getCanonicalName() + "{name=" + ALICE.getName() + ", phone=" + ALICE.getPhone() + ", email=" + ALICE.getEmail() + ", address=" + ALICE.getAddress() + ", grade=" + ALICE.getGrade() + ", subject=" + ALICE.getSubject() + + ", attendance=" + ALICE.getAttendance() + ", payment=" + ALICE.getPayment() + ", dateTimes=" + ALICE.getDateTimes() + ", tags=" + ALICE.getTags() + "}"; assertEquals(expected, ALICE.toString()); } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index b81258cbc9b..ecf551699f7 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -13,12 +13,15 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.person.Address; +import seedu.address.model.person.Attendance; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; +import seedu.address.model.person.Payment; import seedu.address.model.person.Phone; import seedu.address.model.person.Subject; + public class JsonAdaptedPersonTest { private static final String INVALID_NAME = "R@chel"; private static final String INVALID_PHONE = "+651234"; @@ -26,6 +29,8 @@ public class JsonAdaptedPersonTest { private static final String INVALID_EMAIL = "example.com"; private static final String INVALID_GRADE = "E"; private static final String INVALID_SUBJECT = " "; + private static final String INVALID_ATTENDANCE = "prasent"; + private static final String INVALID_PAYMENT = "Paid500"; private static final String INVALID_DATETIME = "2024-02-31 2500"; private static final String INVALID_TAG = "#friend"; @@ -35,6 +40,8 @@ public class JsonAdaptedPersonTest { private static final String VALID_ADDRESS = BENSON.getAddress().toString(); private static final String VALID_GRADE = BENSON.getGrade().toString(); private static final String VALID_SUBJECT = BENSON.getSubject().toString(); + private static final String VALID_ATTENDANCE = BENSON.getAttendance().toString(); + private static final String VALID_PAYMENT = BENSON.getPayment().toString(); private static final List VALID_DATETIME = BENSON.getDateTimes().stream() .map(JsonAdaptedDateTime::new) .collect(Collectors.toList()); @@ -51,8 +58,8 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception { @Test public void toModelType_invalidName_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = Name.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -60,7 +67,7 @@ public void toModelType_invalidName_throwsIllegalValueException() { @Test public void toModelType_nullName_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + VALID_GRADE, VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -68,8 +75,8 @@ public void toModelType_nullName_throwsIllegalValueException() { @Test public void toModelType_invalidPhone_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = Phone.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -77,7 +84,7 @@ public void toModelType_invalidPhone_throwsIllegalValueException() { @Test public void toModelType_nullPhone_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + VALID_GRADE, VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -85,8 +92,8 @@ public void toModelType_nullPhone_throwsIllegalValueException() { @Test public void toModelType_invalidEmail_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = Email.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -94,7 +101,7 @@ public void toModelType_invalidEmail_throwsIllegalValueException() { @Test public void toModelType_nullEmail_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + VALID_GRADE, VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -102,8 +109,8 @@ public void toModelType_nullEmail_throwsIllegalValueException() { @Test public void toModelType_invalidAddress_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = Address.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -111,7 +118,7 @@ public void toModelType_invalidAddress_throwsIllegalValueException() { @Test public void toModelType_nullAddress_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + VALID_GRADE, VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -119,8 +126,8 @@ public void toModelType_nullAddress_throwsIllegalValueException() { @Test public void toModelType_invalidGrade_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - INVALID_GRADE, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, INVALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = Grade.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -128,7 +135,7 @@ public void toModelType_invalidGrade_throwsIllegalValueException() { @Test public void toModelType_nullGrade_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - null, VALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + null, VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Grade.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -136,8 +143,8 @@ public void toModelType_nullGrade_throwsIllegalValueException() { @Test public void toModelType_invalidSubject_throwsIllegalValueException() { JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, INVALID_SUBJECT, VALID_DATETIME, VALID_TAGS); + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + INVALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = Subject.MESSAGE_CONSTRAINTS; assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -145,18 +152,36 @@ public void toModelType_invalidSubject_throwsIllegalValueException() { @Test public void toModelType_nullSubject_throwsIllegalValueException() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, null, VALID_DATETIME, VALID_TAGS); + VALID_GRADE, null, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Subject.class.getSimpleName()); assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } + @Test + public void toModelType_invalidAttendance_throwsIllegalValueException() { + JsonAdaptedPerson person = + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, INVALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, VALID_TAGS); + String expectedMessage = Attendance.MESSAGE_CONSTRAINTS; + assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + } + + @Test + public void toModelType_invalidPayment_throwsIllegalValueException() { + JsonAdaptedPerson person = + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, INVALID_PAYMENT, VALID_DATETIME, VALID_TAGS); + String expectedMessage = Payment.MESSAGE_CONSTRAINTS; + assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + } + @Test public void toModelType_invalidDateTimes_throwsIllegalValueException() { List invalidDateTimes = new ArrayList<>(VALID_DATETIME); invalidDateTimes.add(new JsonAdaptedDateTime(INVALID_DATETIME)); JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, invalidDateTimes, VALID_TAGS); + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, invalidDateTimes, VALID_TAGS); assertThrows(IllegalValueException.class, person::toModelType); } @@ -165,8 +190,8 @@ public void toModelType_invalidTags_throwsIllegalValueException() { List invalidTags = new ArrayList<>(VALID_TAGS); invalidTags.add(new JsonAdaptedTag(INVALID_TAG)); JsonAdaptedPerson person = - new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_GRADE, VALID_SUBJECT, VALID_DATETIME, invalidTags); + new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_GRADE, + VALID_SUBJECT, VALID_ATTENDANCE, VALID_PAYMENT, VALID_DATETIME, invalidTags); assertThrows(IllegalValueException.class, person::toModelType); } diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 094697e4e9d..51944884530 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -4,10 +4,12 @@ import java.util.Set; import seedu.address.model.person.Address; +import seedu.address.model.person.Attendance; import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; +import seedu.address.model.person.Payment; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; import seedu.address.model.person.Subject; @@ -25,6 +27,8 @@ public class PersonBuilder { public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; public static final String DEFAULT_GRADE = "A"; public static final String DEFAULT_SUBJECT = "English"; + public static final String DEFAULT_ATTENDANCE = "Present"; + public static final String DEFAULT_PAYMENT = "Paid"; private Name name; private Phone phone; @@ -32,6 +36,8 @@ public class PersonBuilder { private Address address; private Grade grade; private Subject subject; + private Attendance attendance; + private Payment payment; private Set dateTimes; private Set tags; @@ -45,6 +51,8 @@ public PersonBuilder() { address = new Address(DEFAULT_ADDRESS); grade = new Grade(DEFAULT_GRADE); subject = new Subject(DEFAULT_SUBJECT); + attendance = new Attendance(DEFAULT_ATTENDANCE); + payment = new Payment(DEFAULT_PAYMENT); dateTimes = new HashSet<>(); tags = new HashSet<>(); } @@ -59,6 +67,8 @@ public PersonBuilder(Person personToCopy) { address = personToCopy.getAddress(); grade = personToCopy.getGrade(); subject = personToCopy.getSubject(); + attendance = personToCopy.getAttendance(); + payment = personToCopy.getPayment(); dateTimes = new HashSet<>(personToCopy.getDateTimes()); tags = new HashSet<>(personToCopy.getTags()); } @@ -119,6 +129,22 @@ public PersonBuilder withSubject(String subject) { return this; } + /** + * Sets the {@code Attendance} of the {@code Person} that we are building. + */ + public PersonBuilder withAttendance(String attendance) { + this.attendance = new Attendance(attendance); + return this; + } + + /** + * Sets the {@code Payment} of the {@code Person} that we are building. + */ + public PersonBuilder withPayment(String payment) { + this.payment = new Payment(payment); + return this; + } + /** * Sets the {@code DateTime} of the {@code Person} that we are building. */ @@ -128,7 +154,7 @@ public PersonBuilder withDateTimes(String ... dateTimes) { } public Person build() { - return new Person(name, phone, email, address, grade, subject, dateTimes, tags); + return new Person(name, phone, email, address, grade, subject, attendance, payment, dateTimes, tags); } }