From 3717c7e92422d1492d2c0416059488793eb3ffc5 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Thu, 14 Mar 2024 23:37:15 +0800 Subject: [PATCH 1/7] Add Meeting Class --- .../model/meeting/Description.java | 66 +++++++++++++++++++ .../staffconnect/model/meeting/MeetDate.java | 66 +++++++++++++++++++ .../staffconnect/model/meeting/Meeting.java | 57 ++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 src/main/java/staffconnect/model/meeting/Description.java create mode 100644 src/main/java/staffconnect/model/meeting/MeetDate.java create mode 100644 src/main/java/staffconnect/model/meeting/Meeting.java diff --git a/src/main/java/staffconnect/model/meeting/Description.java b/src/main/java/staffconnect/model/meeting/Description.java new file mode 100644 index 00000000000..ba198834231 --- /dev/null +++ b/src/main/java/staffconnect/model/meeting/Description.java @@ -0,0 +1,66 @@ +package staffconnect.model.meeting; + +import static java.util.Objects.requireNonNull; +import static staffconnect.commons.util.AppUtil.checkArgument; + +/** + * Represents a Meeting's description in the staff book. + * Guarantees: immutable; is valid as declared in {@link #isValidDescription(String)} + */ +public class Description { + + public static final String MESSAGE_CONSTRAINTS = + "Description should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the name must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + + public final String description; + + /** + * Constructs a {@code Description}. + * + * @param textDescription A valid name. + */ + public Description(String textDescription) { + requireNonNull(textDescription); + checkArgument(isValidDescription(textDescription), MESSAGE_CONSTRAINTS); + description = textDescription; + } + + /** + * Returns true if a given string is a valid description. + */ + public static boolean isValidDescription(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public int hashCode() { + return description.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof staffconnect.model.meeting.Description)) { + return false; + } + + staffconnect.model.meeting.Description otherDecription = (staffconnect.model.meeting.Description) other; + return description.equals(otherDecription.description); + } + + @Override + public String toString() { + return description; + } + +} \ No newline at end of file diff --git a/src/main/java/staffconnect/model/meeting/MeetDate.java b/src/main/java/staffconnect/model/meeting/MeetDate.java new file mode 100644 index 00000000000..0c846d4fcc3 --- /dev/null +++ b/src/main/java/staffconnect/model/meeting/MeetDate.java @@ -0,0 +1,66 @@ +package staffconnect.model.meeting; + +import static java.util.Objects.requireNonNull; +import static staffconnect.commons.util.AppUtil.checkArgument; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Represents a Meeting's starting time in the staff book. + * Guarantees: immutable; is valid as declared in {@link #isValidStartTime(String)} + */ +public class MeetDate { + + public static final String MESSAGE_CONSTRAINTS = "Date should be of the correct format dd/mm/yyyy"; + public static final String VALIDATION_REGEX = "\\d{2}/\\d{2}/\\d{4}"; + + private static final DateTimeFormatter PROCESS_FORMAT = DateTimeFormatter.ofPattern("dd/MM/yy"); + + private final LocalDateTime value; + + + /** + * Constructs a {@code MeetDate}. + * + * @param date A valid date. + */ + public MeetDate(String date) { + requireNonNull(date); + checkArgument(isValidStartTime(date), MESSAGE_CONSTRAINTS); + value = java.time.LocalDateTime.parse(date, PROCESS_FORMAT); + } + + /** + * Returns true if a given string is a valid date. + */ + public static boolean isValidStartTime(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public int hashCode() { + return value.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof staffconnect.model.meeting.MeetDate)) { + return false; + } + + staffconnect.model.meeting.MeetDate otherDate = (staffconnect.model.meeting.MeetDate) other; + return value.equals(otherDate.value); + } + + @Override + public String toString() { + return value.format(PROCESS_FORMAT); + } + +} diff --git a/src/main/java/staffconnect/model/meeting/Meeting.java b/src/main/java/staffconnect/model/meeting/Meeting.java new file mode 100644 index 00000000000..a6d9c1507ce --- /dev/null +++ b/src/main/java/staffconnect/model/meeting/Meeting.java @@ -0,0 +1,57 @@ +package staffconnect.model.meeting; + + +import static staffconnect.commons.util.CollectionUtil.requireAllNonNull; + +import java.util.Objects; + +/** + * Represents a Meeting event in the staff book. + * Guarantees: details are present and not null, field values are validated, immutable. + */ +public class Meeting { + + private final Description description; + private final MeetDate startDate; + + /** + * Constructs a {@code Meeting}. + * + * @param description A valid meeting description. + */ + + public Meeting(Description description, MeetDate startDate) { + requireAllNonNull(description, startDate); + this.description = description; + this.startDate = startDate; + } + + + @Override + public int hashCode() { + return Objects.hash(description, startDate); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof staffconnect.model.meeting.Meeting)) { + return false; + } + + staffconnect.model.meeting.Meeting otherMeeting = (staffconnect.model.meeting.Meeting) other; + return description.equals(otherMeeting.description) && startDate.equals(otherMeeting.startDate); + } + + /** + * Format state as text for viewing. + */ + public String toString() { + return startDate + ":" + description; + } + +} From 0028cfbfaae3f36a896d8a3d0b7688d9e3111781 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Fri, 15 Mar 2024 07:52:26 +0800 Subject: [PATCH 2/7] Add Junit test for Meetings --- .../model/meeting/Description.java | 2 +- .../{MeetDate.java => MeetDateTime.java} | 20 ++--- .../staffconnect/model/meeting/Meeting.java | 4 +- .../model/meeting/DescriptionTest.java | 71 +++++++++++++++++ .../model/meeting/MeetDateTimeTest.java | 76 +++++++++++++++++++ .../model/meeting/MeetingTest.java | 56 ++++++++++++++ 6 files changed, 216 insertions(+), 13 deletions(-) rename src/main/java/staffconnect/model/meeting/{MeetDate.java => MeetDateTime.java} (71%) create mode 100644 src/test/java/staffconnect/model/meeting/DescriptionTest.java create mode 100644 src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java create mode 100644 src/test/java/staffconnect/model/meeting/MeetingTest.java diff --git a/src/main/java/staffconnect/model/meeting/Description.java b/src/main/java/staffconnect/model/meeting/Description.java index ba198834231..cde6e7b4917 100644 --- a/src/main/java/staffconnect/model/meeting/Description.java +++ b/src/main/java/staffconnect/model/meeting/Description.java @@ -63,4 +63,4 @@ public String toString() { return description; } -} \ No newline at end of file +} diff --git a/src/main/java/staffconnect/model/meeting/MeetDate.java b/src/main/java/staffconnect/model/meeting/MeetDateTime.java similarity index 71% rename from src/main/java/staffconnect/model/meeting/MeetDate.java rename to src/main/java/staffconnect/model/meeting/MeetDateTime.java index 0c846d4fcc3..c5f60f67aa9 100644 --- a/src/main/java/staffconnect/model/meeting/MeetDate.java +++ b/src/main/java/staffconnect/model/meeting/MeetDateTime.java @@ -8,14 +8,14 @@ /** * Represents a Meeting's starting time in the staff book. - * Guarantees: immutable; is valid as declared in {@link #isValidStartTime(String)} + * Guarantees: immutable; is valid as declared in {@link #isValidMeetDateTime(String)} */ -public class MeetDate { +public class MeetDateTime { - public static final String MESSAGE_CONSTRAINTS = "Date should be of the correct format dd/mm/yyyy"; - public static final String VALIDATION_REGEX = "\\d{2}/\\d{2}/\\d{4}"; + public static final String MESSAGE_CONSTRAINTS = "DateTime should be of the correct format dd/mm/yyyy HH:mm"; + public static final String VALIDATION_REGEX = "\\d{2}/\\d{2}/\\d{4} \\d{2}:\\d{2}"; - private static final DateTimeFormatter PROCESS_FORMAT = DateTimeFormatter.ofPattern("dd/MM/yy"); + private static final DateTimeFormatter PROCESS_FORMAT = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm"); private final LocalDateTime value; @@ -25,16 +25,16 @@ public class MeetDate { * * @param date A valid date. */ - public MeetDate(String date) { + public MeetDateTime(String date) { requireNonNull(date); - checkArgument(isValidStartTime(date), MESSAGE_CONSTRAINTS); + checkArgument(isValidMeetDateTime(date), MESSAGE_CONSTRAINTS); value = java.time.LocalDateTime.parse(date, PROCESS_FORMAT); } /** * Returns true if a given string is a valid date. */ - public static boolean isValidStartTime(String test) { + public static boolean isValidMeetDateTime(String test) { return test.matches(VALIDATION_REGEX); } @@ -50,11 +50,11 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof staffconnect.model.meeting.MeetDate)) { + if (!(other instanceof staffconnect.model.meeting.MeetDateTime)) { return false; } - staffconnect.model.meeting.MeetDate otherDate = (staffconnect.model.meeting.MeetDate) other; + staffconnect.model.meeting.MeetDateTime otherDate = (staffconnect.model.meeting.MeetDateTime) other; return value.equals(otherDate.value); } diff --git a/src/main/java/staffconnect/model/meeting/Meeting.java b/src/main/java/staffconnect/model/meeting/Meeting.java index a6d9c1507ce..e9bc83544e0 100644 --- a/src/main/java/staffconnect/model/meeting/Meeting.java +++ b/src/main/java/staffconnect/model/meeting/Meeting.java @@ -12,7 +12,7 @@ public class Meeting { private final Description description; - private final MeetDate startDate; + private final MeetDateTime startDate; /** * Constructs a {@code Meeting}. @@ -20,7 +20,7 @@ public class Meeting { * @param description A valid meeting description. */ - public Meeting(Description description, MeetDate startDate) { + public Meeting(Description description, MeetDateTime startDate) { requireAllNonNull(description, startDate); this.description = description; this.startDate = startDate; diff --git a/src/test/java/staffconnect/model/meeting/DescriptionTest.java b/src/test/java/staffconnect/model/meeting/DescriptionTest.java new file mode 100644 index 00000000000..22d0542b0a0 --- /dev/null +++ b/src/test/java/staffconnect/model/meeting/DescriptionTest.java @@ -0,0 +1,71 @@ +package staffconnect.model.meeting; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static staffconnect.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +import staffconnect.model.person.Name; + +class DescriptionTest { + + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Name(null)); + } + + @Test + public void constructor_invalidName_throwsIllegalArgumentException() { + String invalidDescription = ""; + assertThrows(IllegalArgumentException.class, () -> new Name(invalidDescription)); + } + + @Test + public void isValidDescription() { + // null name + assertThrows(NullPointerException.class, () -> Description.isValidDescription(null)); + + // invalid name + assertFalse(Name.isValidName("")); // empty string + assertFalse(Name.isValidName(" ")); // spaces only + assertFalse(Name.isValidName("^")); // only non-alphanumeric characters + assertFalse(Name.isValidName("peter meeting*")); // contains non-alphanumeric characters + + // valid name + assertTrue(Name.isValidName("meeting")); // alphabets only + assertTrue(Name.isValidName("12345")); // numbers only + assertTrue(Name.isValidName("meeting at for 2nd finals")); // alphanumeric characters + assertTrue(Name.isValidName("Crush the exam")); // with capital letters + assertTrue(Name.isValidName("Super hard midterm with finals and project combined 2nd")); // long names + } + + @Test + public void equals() { + Description description = new Description("Valid Description"); + + // same values -> returns true + assertEquals(description, new Description("Valid Description")); + + // same object -> returns true + assertEquals(description, description); + + // null -> returns false + assertNotEquals(null, description); + + // different types -> returns false + assertNotEquals(5.0f, description); + + // different values -> returns false + assertNotEquals(description, new Name("Other valid description")); + } + @Test + public void asSymmetricHashcode() { + Description first = new Description("Valid Description"); + Description second = new Description("Valid Description"); + assertEquals(first.hashCode(), second.hashCode()); + } +} diff --git a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java new file mode 100644 index 00000000000..40c38a0eeea --- /dev/null +++ b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java @@ -0,0 +1,76 @@ +package staffconnect.model.meeting; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static staffconnect.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + + +class MeetDateTimeTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new MeetDateTime(null)); + } + + @Test + public void constructor_invalidModule_throwsIllegalArgumentException() { + String invalidDate = ""; + assertThrows(IllegalArgumentException.class, () -> new MeetDateTime(invalidDate)); + } + + @Test + public void isValidMeetDate() { + // null Date + assertThrows(NullPointerException.class, () -> MeetDateTime.isValidMeetDateTime(null)); + + // invalid Meeting Date code + assertFalse(MeetDateTime.isValidMeetDateTime("")); // empty string + assertFalse(MeetDateTime.isValidMeetDateTime(" ")); // spaces only + assertFalse(MeetDateTime.isValidMeetDateTime("ABCD")); // letters only + assertFalse(MeetDateTime.isValidMeetDateTime("1234")); // numbers only + assertFalse(MeetDateTime.isValidMeetDateTime("120420231200")); // missing separator no space + assertFalse(MeetDateTime.isValidMeetDateTime("12/0420231200")); // only 1 separator no space + assertFalse(MeetDateTime.isValidMeetDateTime("1204/2023 1200")); // only 1 separator + assertFalse(MeetDateTime.isValidMeetDateTime("12-04-2023 12:00")); // wrong separator + assertFalse(MeetDateTime.isValidMeetDateTime("12/04/23 12:00")); // wrong digits for year + assertFalse(MeetDateTime.isValidMeetDateTime("12/4/2023 12:00")); // wrong number digits for month + assertFalse(MeetDateTime.isValidMeetDateTime("1/04/2023 12:00")); // wrong number digits for day + + // valid module code + assertTrue(MeetDateTime.isValidMeetDateTime("12/04/2023 12:00")); // dd/MM/yyyy HH:mm + assertTrue(MeetDateTime.isValidMeetDateTime("15/02/2024 12:00")); // dd/MM/yyyy HH:mm + } + + @Test + public void equals() { + MeetDateTime date = new MeetDateTime("20/01/2023 12:00"); + + // same values -> returns true + assertEquals(date, new MeetDateTime("20/01/2023 12:00")); + + // same object -> returns true + assertEquals(date, date); + + // null -> returns false + assertNotEquals(null, date); + + // different types -> returns false + assertNotEquals(1234, date); + + // different values -> returns false + assertNotEquals(date, new MeetDateTime("15/02/2024 12:00")); + } + + @Test + public void asSymmetricHashcode() { + MeetDateTime first = new MeetDateTime("12/04/2023 12:00"); + MeetDateTime second = new MeetDateTime("12/04/2023 12:00"); + assertEquals(first.hashCode(), second.hashCode()); + } + + +} diff --git a/src/test/java/staffconnect/model/meeting/MeetingTest.java b/src/test/java/staffconnect/model/meeting/MeetingTest.java new file mode 100644 index 00000000000..0d1749f5ef5 --- /dev/null +++ b/src/test/java/staffconnect/model/meeting/MeetingTest.java @@ -0,0 +1,56 @@ +package staffconnect.model.meeting; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import org.junit.jupiter.api.Test; + +class MeetingTest { + private static final Description testDescription = new Description("Valid description"); + private static final MeetDateTime testDate = new MeetDateTime("12/04/2023 12:00"); + private static final Description otherDescription = new Description("Another valid description"); + private static final MeetDateTime otherDate = new MeetDateTime("13/04/2023 13:00"); + + @Test + public void equals() { + + Meeting testMeeting = new Meeting(testDescription, testDate); + Meeting diffMeetingDescription = new Meeting(otherDescription, testDate); + Meeting diffMeetingTime = new Meeting(testDescription, otherDate); + + // same values -> returns true + assertEquals(testMeeting, new Meeting(new Description("Valid description"), + new MeetDateTime("12/04/2023 12:00"))); + + // same object -> returns true + assertEquals(testMeeting, testMeeting); + + // null -> returns false + assertNotEquals(null, testMeeting); + + // different type -> returns false + assertNotEquals(5, testMeeting); + + // different description -> returns false + assertNotEquals(testMeeting, diffMeetingDescription); + + // different time -> returns false + assertNotEquals(testMeeting, diffMeetingTime); + } + + @Test + public void asSymmetricHashcode() { + Meeting first = new Meeting(new Description("test"), new MeetDateTime("12/04/2023 12:00")); + Meeting second = new Meeting(new Description("test"), new MeetDateTime("12/04/2023 12:00")); + assertEquals(first.hashCode(), second.hashCode()); + } + + @Test + public void toStringMethod() { + Meeting testMeeting = new Meeting(testDescription, testDate); + String expected = testDate + ":" + testDescription; + assertEquals(expected, testMeeting.toString()); + } + + +} From 4f80e1e2f23177c7c0d93c9fa15c4f3af913f934 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Fri, 15 Mar 2024 10:36:15 +0800 Subject: [PATCH 3/7] Add more junit test --- src/main/java/staffconnect/model/meeting/Meeting.java | 1 + .../java/staffconnect/model/meeting/DescriptionTest.java | 4 ++++ .../java/staffconnect/model/meeting/MeetDateTimeTest.java | 4 ++++ src/test/java/staffconnect/model/meeting/MeetingTest.java | 6 ++++++ 4 files changed, 15 insertions(+) diff --git a/src/main/java/staffconnect/model/meeting/Meeting.java b/src/main/java/staffconnect/model/meeting/Meeting.java index e9bc83544e0..899db8d3b0f 100644 --- a/src/main/java/staffconnect/model/meeting/Meeting.java +++ b/src/main/java/staffconnect/model/meeting/Meeting.java @@ -18,6 +18,7 @@ public class Meeting { * Constructs a {@code Meeting}. * * @param description A valid meeting description. + * @param startDate A valid time and date for the meeting. */ public Meeting(Description description, MeetDateTime startDate) { diff --git a/src/test/java/staffconnect/model/meeting/DescriptionTest.java b/src/test/java/staffconnect/model/meeting/DescriptionTest.java index 22d0542b0a0..19619d9531f 100644 --- a/src/test/java/staffconnect/model/meeting/DescriptionTest.java +++ b/src/test/java/staffconnect/model/meeting/DescriptionTest.java @@ -46,6 +46,7 @@ public void isValidDescription() { @Test public void equals() { Description description = new Description("Valid Description"); + MeetDateTime testDate = new MeetDateTime("12/04/2023 12:00"); // same values -> returns true assertEquals(description, new Description("Valid Description")); @@ -59,6 +60,9 @@ public void equals() { // different types -> returns false assertNotEquals(5.0f, description); + //Different object type -> returns false + assertFalse(description.equals(testDate)); + // different values -> returns false assertNotEquals(description, new Name("Other valid description")); } diff --git a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java index 40c38a0eeea..7819dcdb2bb 100644 --- a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java +++ b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java @@ -48,6 +48,7 @@ public void isValidMeetDate() { @Test public void equals() { MeetDateTime date = new MeetDateTime("20/01/2023 12:00"); + Description testDescription = new Description("Valid Description"); // same values -> returns true assertEquals(date, new MeetDateTime("20/01/2023 12:00")); @@ -61,6 +62,9 @@ public void equals() { // different types -> returns false assertNotEquals(1234, date); + //Different object type -> returns false + assertFalse(date.equals(testDescription)); + // different values -> returns false assertNotEquals(date, new MeetDateTime("15/02/2024 12:00")); } diff --git a/src/test/java/staffconnect/model/meeting/MeetingTest.java b/src/test/java/staffconnect/model/meeting/MeetingTest.java index 0d1749f5ef5..11d1b4086b0 100644 --- a/src/test/java/staffconnect/model/meeting/MeetingTest.java +++ b/src/test/java/staffconnect/model/meeting/MeetingTest.java @@ -1,6 +1,7 @@ package staffconnect.model.meeting; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import org.junit.jupiter.api.Test; @@ -17,6 +18,8 @@ public void equals() { Meeting testMeeting = new Meeting(testDescription, testDate); Meeting diffMeetingDescription = new Meeting(otherDescription, testDate); Meeting diffMeetingTime = new Meeting(testDescription, otherDate); + MeetDateTime testDate = new MeetDateTime("12/04/2023 12:00"); + // same values -> returns true assertEquals(testMeeting, new Meeting(new Description("Valid description"), @@ -31,6 +34,9 @@ public void equals() { // different type -> returns false assertNotEquals(5, testMeeting); + //Different object type -> returns false + assertFalse(testMeeting.equals(testDate)); + // different description -> returns false assertNotEquals(testMeeting, diffMeetingDescription); From 79ca09082ae12b135fc8790a65dd61d7aefadc19 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Fri, 15 Mar 2024 14:29:49 +0800 Subject: [PATCH 4/7] Amend typos and add getters to meeting --- .../staffconnect/model/meeting/Description.java | 2 +- .../java/staffconnect/model/meeting/Meeting.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/staffconnect/model/meeting/Description.java b/src/main/java/staffconnect/model/meeting/Description.java index cde6e7b4917..d8cda0dfe2c 100644 --- a/src/main/java/staffconnect/model/meeting/Description.java +++ b/src/main/java/staffconnect/model/meeting/Description.java @@ -23,7 +23,7 @@ public class Description { /** * Constructs a {@code Description}. * - * @param textDescription A valid name. + * @param textDescription A valid description. */ public Description(String textDescription) { requireNonNull(textDescription); diff --git a/src/main/java/staffconnect/model/meeting/Meeting.java b/src/main/java/staffconnect/model/meeting/Meeting.java index 899db8d3b0f..c1c15ba9030 100644 --- a/src/main/java/staffconnect/model/meeting/Meeting.java +++ b/src/main/java/staffconnect/model/meeting/Meeting.java @@ -18,7 +18,7 @@ public class Meeting { * Constructs a {@code Meeting}. * * @param description A valid meeting description. - * @param startDate A valid time and date for the meeting. + * @param startDate A valid time and date for the meeting. */ public Meeting(Description description, MeetDateTime startDate) { @@ -27,6 +27,13 @@ public Meeting(Description description, MeetDateTime startDate) { this.startDate = startDate; } + public Description getDescription() { + return description; + } + + public MeetDateTime getStartDate() { + return startDate; + } @Override public int hashCode() { @@ -40,11 +47,11 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof staffconnect.model.meeting.Meeting)) { + if (!(other instanceof Meeting)) { return false; } - staffconnect.model.meeting.Meeting otherMeeting = (staffconnect.model.meeting.Meeting) other; + Meeting otherMeeting = (Meeting) other; return description.equals(otherMeeting.description) && startDate.equals(otherMeeting.startDate); } From c2a4081be1a4796b222b2f286737bce6b1576da0 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Fri, 15 Mar 2024 14:32:28 +0800 Subject: [PATCH 5/7] Fix access path --- src/main/java/staffconnect/model/meeting/Description.java | 4 ++-- src/main/java/staffconnect/model/meeting/MeetDateTime.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/staffconnect/model/meeting/Description.java b/src/main/java/staffconnect/model/meeting/Description.java index d8cda0dfe2c..a60c379b52f 100644 --- a/src/main/java/staffconnect/model/meeting/Description.java +++ b/src/main/java/staffconnect/model/meeting/Description.java @@ -50,11 +50,11 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof staffconnect.model.meeting.Description)) { + if (!(other instanceof Description)) { return false; } - staffconnect.model.meeting.Description otherDecription = (staffconnect.model.meeting.Description) other; + Description otherDecription = (Description) other; return description.equals(otherDecription.description); } diff --git a/src/main/java/staffconnect/model/meeting/MeetDateTime.java b/src/main/java/staffconnect/model/meeting/MeetDateTime.java index c5f60f67aa9..c36a98b8b4c 100644 --- a/src/main/java/staffconnect/model/meeting/MeetDateTime.java +++ b/src/main/java/staffconnect/model/meeting/MeetDateTime.java @@ -50,11 +50,11 @@ public boolean equals(Object other) { } // instanceof handles nulls - if (!(other instanceof staffconnect.model.meeting.MeetDateTime)) { + if (!(other instanceof MeetDateTime)) { return false; } - staffconnect.model.meeting.MeetDateTime otherDate = (staffconnect.model.meeting.MeetDateTime) other; + MeetDateTime otherDate = (MeetDateTime) other; return value.equals(otherDate.value); } From 01ee036df15b52b91af20d87db15a8167e11bb91 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Fri, 15 Mar 2024 14:39:41 +0800 Subject: [PATCH 6/7] Fix typos --- .../staffconnect/model/meeting/MeetDateTime.java | 2 +- .../model/meeting/DescriptionTest.java | 6 +++--- .../model/meeting/MeetDateTimeTest.java | 4 ++-- .../staffconnect/model/meeting/MeetingTest.java | 16 ++++++++-------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/java/staffconnect/model/meeting/MeetDateTime.java b/src/main/java/staffconnect/model/meeting/MeetDateTime.java index c36a98b8b4c..5467c076be6 100644 --- a/src/main/java/staffconnect/model/meeting/MeetDateTime.java +++ b/src/main/java/staffconnect/model/meeting/MeetDateTime.java @@ -21,7 +21,7 @@ public class MeetDateTime { /** - * Constructs a {@code MeetDate}. + * Constructs a {@code MeetDateTime}. * * @param date A valid date. */ diff --git a/src/test/java/staffconnect/model/meeting/DescriptionTest.java b/src/test/java/staffconnect/model/meeting/DescriptionTest.java index 19619d9531f..4f8a60670d8 100644 --- a/src/test/java/staffconnect/model/meeting/DescriptionTest.java +++ b/src/test/java/staffconnect/model/meeting/DescriptionTest.java @@ -26,16 +26,16 @@ public void constructor_invalidName_throwsIllegalArgumentException() { @Test public void isValidDescription() { - // null name + // null Description assertThrows(NullPointerException.class, () -> Description.isValidDescription(null)); - // invalid name + // invalid Description assertFalse(Name.isValidName("")); // empty string assertFalse(Name.isValidName(" ")); // spaces only assertFalse(Name.isValidName("^")); // only non-alphanumeric characters assertFalse(Name.isValidName("peter meeting*")); // contains non-alphanumeric characters - // valid name + // valid Description assertTrue(Name.isValidName("meeting")); // alphabets only assertTrue(Name.isValidName("12345")); // numbers only assertTrue(Name.isValidName("meeting at for 2nd finals")); // alphanumeric characters diff --git a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java index 7819dcdb2bb..c5877282e0c 100644 --- a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java +++ b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java @@ -27,7 +27,7 @@ public void isValidMeetDate() { // null Date assertThrows(NullPointerException.class, () -> MeetDateTime.isValidMeetDateTime(null)); - // invalid Meeting Date code + // invalid Meeting Date assertFalse(MeetDateTime.isValidMeetDateTime("")); // empty string assertFalse(MeetDateTime.isValidMeetDateTime(" ")); // spaces only assertFalse(MeetDateTime.isValidMeetDateTime("ABCD")); // letters only @@ -40,7 +40,7 @@ public void isValidMeetDate() { assertFalse(MeetDateTime.isValidMeetDateTime("12/4/2023 12:00")); // wrong number digits for month assertFalse(MeetDateTime.isValidMeetDateTime("1/04/2023 12:00")); // wrong number digits for day - // valid module code + // valid meeting Date assertTrue(MeetDateTime.isValidMeetDateTime("12/04/2023 12:00")); // dd/MM/yyyy HH:mm assertTrue(MeetDateTime.isValidMeetDateTime("15/02/2024 12:00")); // dd/MM/yyyy HH:mm } diff --git a/src/test/java/staffconnect/model/meeting/MeetingTest.java b/src/test/java/staffconnect/model/meeting/MeetingTest.java index 11d1b4086b0..3b7fe7e1b8b 100644 --- a/src/test/java/staffconnect/model/meeting/MeetingTest.java +++ b/src/test/java/staffconnect/model/meeting/MeetingTest.java @@ -7,17 +7,17 @@ import org.junit.jupiter.api.Test; class MeetingTest { - private static final Description testDescription = new Description("Valid description"); - private static final MeetDateTime testDate = new MeetDateTime("12/04/2023 12:00"); - private static final Description otherDescription = new Description("Another valid description"); + private static final Description TEST_DESCRIPTION = new Description("Valid description"); + private static final MeetDateTime TEST_DATE = new MeetDateTime("12/04/2023 12:00"); + private static final Description TEST_OTHERDESCRIPTION = new Description("Another valid description"); private static final MeetDateTime otherDate = new MeetDateTime("13/04/2023 13:00"); @Test public void equals() { - Meeting testMeeting = new Meeting(testDescription, testDate); - Meeting diffMeetingDescription = new Meeting(otherDescription, testDate); - Meeting diffMeetingTime = new Meeting(testDescription, otherDate); + Meeting testMeeting = new Meeting(TEST_DESCRIPTION, TEST_DATE); + Meeting diffMeetingDescription = new Meeting(TEST_OTHERDESCRIPTION, TEST_DATE); + Meeting diffMeetingTime = new Meeting(TEST_DESCRIPTION, otherDate); MeetDateTime testDate = new MeetDateTime("12/04/2023 12:00"); @@ -53,8 +53,8 @@ public void asSymmetricHashcode() { @Test public void toStringMethod() { - Meeting testMeeting = new Meeting(testDescription, testDate); - String expected = testDate + ":" + testDescription; + Meeting testMeeting = new Meeting(TEST_DESCRIPTION, TEST_DATE); + String expected = TEST_DATE + ":" + TEST_DESCRIPTION; assertEquals(expected, testMeeting.toString()); } From 5031b3f756e3ecdcfb2147bad2fd07a490190816 Mon Sep 17 00:00:00 2001 From: Pluiexo Date: Fri, 15 Mar 2024 15:14:27 +0800 Subject: [PATCH 7/7] Fix even more typos --- .../model/meeting/DescriptionTest.java | 27 +++++++++---------- .../model/meeting/MeetDateTimeTest.java | 2 +- .../model/meeting/MeetingTest.java | 4 +-- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/test/java/staffconnect/model/meeting/DescriptionTest.java b/src/test/java/staffconnect/model/meeting/DescriptionTest.java index 4f8a60670d8..1363cd114c2 100644 --- a/src/test/java/staffconnect/model/meeting/DescriptionTest.java +++ b/src/test/java/staffconnect/model/meeting/DescriptionTest.java @@ -8,20 +8,19 @@ import org.junit.jupiter.api.Test; -import staffconnect.model.person.Name; class DescriptionTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Name(null)); + assertThrows(NullPointerException.class, () -> new Description(null)); } @Test - public void constructor_invalidName_throwsIllegalArgumentException() { + public void constructor_invalidDescription_throwsIllegalArgumentException() { String invalidDescription = ""; - assertThrows(IllegalArgumentException.class, () -> new Name(invalidDescription)); + assertThrows(IllegalArgumentException.class, () -> new Description(invalidDescription)); } @Test @@ -30,17 +29,17 @@ public void isValidDescription() { assertThrows(NullPointerException.class, () -> Description.isValidDescription(null)); // invalid Description - assertFalse(Name.isValidName("")); // empty string - assertFalse(Name.isValidName(" ")); // spaces only - assertFalse(Name.isValidName("^")); // only non-alphanumeric characters - assertFalse(Name.isValidName("peter meeting*")); // contains non-alphanumeric characters + assertFalse(Description.isValidDescription("")); // empty string + assertFalse(Description.isValidDescription(" ")); // spaces only + assertFalse(Description.isValidDescription("^")); // only non-alphanumeric characters + assertFalse(Description.isValidDescription("peter meeting*")); // contains non-alphanumeric characters // valid Description - assertTrue(Name.isValidName("meeting")); // alphabets only - assertTrue(Name.isValidName("12345")); // numbers only - assertTrue(Name.isValidName("meeting at for 2nd finals")); // alphanumeric characters - assertTrue(Name.isValidName("Crush the exam")); // with capital letters - assertTrue(Name.isValidName("Super hard midterm with finals and project combined 2nd")); // long names + assertTrue(Description.isValidDescription("meeting")); // alphabets only + assertTrue(Description.isValidDescription("12345")); // numbers only + assertTrue(Description.isValidDescription("meeting at for 2nd finals")); // alphanumeric characters + assertTrue(Description.isValidDescription("Crush the exam")); // with capital letters + assertTrue(Description.isValidDescription("Super hard midterm with finals and project combined 2nd")); } @Test @@ -64,7 +63,7 @@ public void equals() { assertFalse(description.equals(testDate)); // different values -> returns false - assertNotEquals(description, new Name("Other valid description")); + assertNotEquals(description, new Description("Other valid description")); } @Test public void asSymmetricHashcode() { diff --git a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java index c5877282e0c..c20399d0167 100644 --- a/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java +++ b/src/test/java/staffconnect/model/meeting/MeetDateTimeTest.java @@ -23,7 +23,7 @@ public void constructor_invalidModule_throwsIllegalArgumentException() { } @Test - public void isValidMeetDate() { + public void isValidMeetDateTime() { // null Date assertThrows(NullPointerException.class, () -> MeetDateTime.isValidMeetDateTime(null)); diff --git a/src/test/java/staffconnect/model/meeting/MeetingTest.java b/src/test/java/staffconnect/model/meeting/MeetingTest.java index 3b7fe7e1b8b..83fb779f74a 100644 --- a/src/test/java/staffconnect/model/meeting/MeetingTest.java +++ b/src/test/java/staffconnect/model/meeting/MeetingTest.java @@ -10,14 +10,14 @@ class MeetingTest { private static final Description TEST_DESCRIPTION = new Description("Valid description"); private static final MeetDateTime TEST_DATE = new MeetDateTime("12/04/2023 12:00"); private static final Description TEST_OTHERDESCRIPTION = new Description("Another valid description"); - private static final MeetDateTime otherDate = new MeetDateTime("13/04/2023 13:00"); + private static final MeetDateTime TEST_OTHERDATE = new MeetDateTime("13/04/2023 13:00"); @Test public void equals() { Meeting testMeeting = new Meeting(TEST_DESCRIPTION, TEST_DATE); Meeting diffMeetingDescription = new Meeting(TEST_OTHERDESCRIPTION, TEST_DATE); - Meeting diffMeetingTime = new Meeting(TEST_DESCRIPTION, otherDate); + Meeting diffMeetingTime = new Meeting(TEST_DESCRIPTION, TEST_OTHERDATE); MeetDateTime testDate = new MeetDateTime("12/04/2023 12:00");