From 0e3513344b46e1b8aedbe699480ace06c7631c2c Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:53:47 +0800 Subject: [PATCH 01/13] Course Command v1 --- .../logic/commands/SetCourseCommand.java | 43 +++++++++++++++++++ .../logic/parser/AddressBookParser.java | 5 ++- .../logic/parser/SetCourseCommandParser.java | 4 ++ .../logic/commands/SetCourseCommandTest.java | 19 ++++++++ .../logic/parser/AddressBookParserTest.java | 6 +++ 5 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/main/java/seedu/address/logic/commands/SetCourseCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java create mode 100644 src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java new file mode 100644 index 00000000000..a7c2caef8da --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java @@ -0,0 +1,43 @@ +package seedu.address.logic.commands; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +public class SetCourseCommand extends Command { + public static final String COMMAND_WORD = "setcrs"; + + public static final String MESSAGE_ARGUMENTS = "Course: %1$s"; + + private final String course; + + public SetCourseCommand(String course) { + requireAllNonNull(course); + this.course = course; + } + + + public static final String MESSAGE_NOT_IMPLEMENTED_YET = + "Remark command not implemented yet"; + @Override + public CommandResult execute(Model model) throws CommandException { + throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET + course); + } + + @Override + public boolean equals(Object other) { + // short circuit if same object + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof SetCourseCommand)) { + return false; + } + + // state check + SetCourseCommand e = (SetCourseCommand) other; + return course.equals(e.course); + + } + +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 3149ee07e0b..e3e7671081d 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -17,6 +17,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -73,10 +74,12 @@ public Command parseCommand(String userInput) throws ParseException { case ExitCommand.COMMAND_WORD: return new ExitCommand(); - case HelpCommand.COMMAND_WORD: return new HelpCommand(); + case SetCourseCommand.COMMAND_WORD: + return new SetCourseCommand(); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java new file mode 100644 index 00000000000..78e0dadc18c --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java @@ -0,0 +1,4 @@ +package seedu.address.logic.parser; + +public class SetCourseCommandParser { +} diff --git a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java new file mode 100644 index 00000000000..547e531804a --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java @@ -0,0 +1,19 @@ +package seedu.address.logic.commands; + +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; + +public class SetCourseCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute() { + assertCommandFailure(new SetCourseCommand(), model, "hi"); + } +} diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 5a1ab3dbc0c..57df0d401c8 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -22,6 +22,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; @@ -94,6 +95,11 @@ public void parseCommand_unrecognisedInput_throwsParseException() { -> parser.parseCommand("")); } + @Test + public void parseCommand_setcourse() throws Exception { + assertTrue(parser.parseCommand(SetCourseCommand.COMMAND_WORD) instanceof SetCourseCommand); + } + @Test public void parseCommand_unknownCommand_throwsParseException() { assertThrows(ParseException.class, MESSAGE_UNKNOWN_COMMAND, () -> parser.parseCommand("unknownCommand")); From 6fcd9c1ebe25f6bf82823058d2ae645bb3ae80c0 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:05:45 +0800 Subject: [PATCH 02/13] Set Course Command Parsing --- .../logic/commands/SetCourseCommand.java | 11 +++- .../logic/parser/AddressBookParser.java | 2 +- .../address/logic/parser/ParserUtil.java | 22 ++++++- .../logic/parser/SetCourseCommandParser.java | 32 +++++++++- .../seedu/address/model/course/Course.java | 64 +++++++++++++++++++ .../logic/commands/CommandTestUtil.java | 2 + .../logic/commands/SetCourseCommandTest.java | 11 +++- 7 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/main/java/seedu/address/model/course/Course.java diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java index a7c2caef8da..da5cfe6ebd5 100644 --- a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java +++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java @@ -1,22 +1,27 @@ package seedu.address.logic.commands; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; +import seedu.address.model.course.Course; + import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; public class SetCourseCommand extends Command { public static final String COMMAND_WORD = "setcrs"; public static final String MESSAGE_ARGUMENTS = "Course: %1$s"; - private final String course; + public static final String MESSAGE_CONSTRAINTS = + "Course code should follow the format \"XX1234Y\", Y is optional"; + + private final Course course; - public SetCourseCommand(String course) { + public SetCourseCommand(Course course) { requireAllNonNull(course); this.course = course; } public static final String MESSAGE_NOT_IMPLEMENTED_YET = - "Remark command not implemented yet"; + "Course command not implemented yet"; @Override public CommandResult execute(Model model) throws CommandException { throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET + course); diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 2deb56a94f1..6880c77145a 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -78,7 +78,7 @@ public Command parseCommand(String userInput) throws ParseException { return new HelpCommand(); case SetCourseCommand.COMMAND_WORD: - return new SetCourseCommand(); + return new SetCourseCommandParser().parse(arguments); default: logger.finer("This user input caused a ParseException: " + userInput); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 4f7382e8f81..f9f2514e072 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,11 +9,12 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.course.Course; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.NusNet; -import seedu.address.model.person.Phone; +import seedu.address.model.person.Phone;; import seedu.address.model.tag.Tag; /** @@ -112,7 +113,22 @@ public static NusNet parseNusNet(String nusNet) throws ParseException { } /** - * Parses a {@code String tag} into a {@code Tag}. + * Parses a {@code String code} into a {@code Course}. + * Leading and trailing whitespaces will be trimmed. + * + * @throws ParseException if the given {@code code} is invalid. + */ + public static Course parseCourse(String code) throws ParseException { + requireNonNull(code); + String trimmedCode = code.trim(); + if (!Tag.isValidTagName(trimmedCode)) { + throw new ParseException(Course.MESSAGE_CONSTRAINTS); + } + return new Course(trimmedCode); + } + + /** + * Parses a {@code String course} into a {@code course}. * Leading and trailing whitespaces will be trimmed. * * @throws ParseException if the given {@code tag} is invalid. @@ -126,6 +142,8 @@ public static Tag parseTag(String tag) throws ParseException { return new Tag(trimmedTag); } + + /** * Parses {@code Collection tags} into a {@code Set}. */ diff --git a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java index 78e0dadc18c..50489172e75 100644 --- a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java @@ -1,4 +1,32 @@ package seedu.address.logic.parser; -public class SetCourseCommandParser { -} +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import seedu.address.commons.core.index.Index; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.logic.commands.SetCourseCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.course.Course; + +/** + * Parses input arguments and creates a new {@code SetCourseCommand} object + */ +public class SetCourseCommandParser implements Parser { + /** + * Parses the given {@code String} of arguments in the context of the {@code RemarkCommand} + * and returns a {@code RemarkCommand} object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public SetCourseCommand parse(String args) throws ParseException { + requireNonNull(args); + + Course course; + try { + course = ParserUtil.parseCourse(args); + } catch (IllegalValueException ive) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCourseCommand.MESSAGE_CONSTRAINTS), ive); + } + + return new SetCourseCommand(course); + } +} \ No newline at end of file diff --git a/src/main/java/seedu/address/model/course/Course.java b/src/main/java/seedu/address/model/course/Course.java new file mode 100644 index 00000000000..57f86ec92c1 --- /dev/null +++ b/src/main/java/seedu/address/model/course/Course.java @@ -0,0 +1,64 @@ +package seedu.address.model.course; + +import seedu.address.model.person.Name; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + + +public class Course { + public static final String MESSAGE_CONSTRAINTS = + "Course code should follow the format \"XX1234Y\", Y is optional"; + + /** + * Represents a course code validation in NUS Computer Science. + * A valid course code must have two uppercase letters, followed by four digits, + * and can optionally end with an uppercase letter. + */ + + public static final String VALIDATION_REGEX = "^[A-Z]{2}\\d{4}[A-Z]?$"; + + public String course_code; + // Decided to not have the code as final above, as changes may occur. + + /** + * Constructs a {@code Course}. + * + * @param code A valid course. + */ + public Course(String code) { + requireNonNull(code); + checkArgument(isValidCode(code), MESSAGE_CONSTRAINTS); + course_code = code; + } + + public static boolean isValidCode(String test) { + return test.matches(VALIDATION_REGEX); + } + + @Override + public String toString() { + return course_code; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Course)) { + return false; + } + + Course otherCourse = (Course) other; + return course_code.equals(otherCourse.course_code); + } + + @Override + public int hashCode() { + return course_code.hashCode(); + } + +} diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 08e6a999c43..a14c7f62644 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -35,6 +35,8 @@ public class CommandTestUtil { public static final String VALID_EMAIL_BOB = "bob@example.com"; public static final String VALID_NUSNET_AMY = "e1111111"; public static final String VALID_NUSNET_BOB = "e2222222"; + public static final String VALID_COURSE_CODE_BOB = "CS2103T"; + public static final String VALID_COURSE_CODE_AMY = "CS2101"; public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1"; public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3"; public static final String VALID_TAG_HUSBAND = "husband"; diff --git a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java index 547e531804a..cbb9c3471af 100644 --- a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java @@ -1,6 +1,13 @@ package seedu.address.logic.commands; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_AMY; + import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.SetCourseCommand.MESSAGE_ARGUMENTS; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.Test; @@ -8,12 +15,14 @@ import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.course.Course; public class SetCourseCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); @Test public void execute() { - assertCommandFailure(new SetCourseCommand(), model, "hi"); + Course course = new Course("CS2103T"); + assertCommandFailure(new SetCourseCommand(course), model, "hi"); } } From b5dda300877e18d6149ce4964307f4f4f6783f85 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:12:58 +0800 Subject: [PATCH 03/13] Created Course Storage --- src/main/java/seedu/address/MainApp.java | 2 +- .../logic/commands/SetCourseCommand.java | 16 +++- .../java/seedu/address/model/CourseName.java | 77 +++++++++++++++++++ src/main/java/seedu/address/model/Model.java | 52 +++++++++++++ .../seedu/address/model/ModelManager.java | 54 ++++++++++++- .../seedu/address/model/ReadOnlyCourse.java | 18 +++++ .../java/seedu/address/model/UserPrefs.java | 17 +++- .../seedu/address/model/course/Course.java | 9 ++- .../seedu/address/storage/CourseStorage.java | 42 ++++++++++ .../address/storage/JsonAdaptedCourse.java | 47 +++++++++++ .../storage/JsonSerializableAddressBook.java | 1 + .../java/seedu/address/ui/MainWindow.java | 23 +++++- src/main/java/seedu/address/ui/UiManager.java | 8 +- .../logic/commands/SetCourseCommandTest.java | 23 +++++- .../logic/parser/AddressBookParserTest.java | 6 +- .../logic/parser/RemarkCommandParserTest.java | 24 ++++++ 16 files changed, 400 insertions(+), 19 deletions(-) create mode 100644 src/main/java/seedu/address/model/CourseName.java create mode 100644 src/main/java/seedu/address/model/ReadOnlyCourse.java create mode 100644 src/main/java/seedu/address/storage/CourseStorage.java create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedCourse.java create mode 100644 src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 3d6bd06d5af..3df0a1d0ff6 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -64,7 +64,7 @@ public void init() throws Exception { logic = new LogicManager(model, storage); - ui = new UiManager(logic); + ui = new UiManager(logic, model); } /** diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java index da5cfe6ebd5..ec5b3d54bc6 100644 --- a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java +++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java @@ -4,6 +4,8 @@ import seedu.address.model.course.Course; import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import static seedu.address.model.course.Course.isValidCode; + public class SetCourseCommand extends Command { public static final String COMMAND_WORD = "setcrs"; @@ -12,6 +14,11 @@ public class SetCourseCommand extends Command { public static final String MESSAGE_CONSTRAINTS = "Course code should follow the format \"XX1234Y\", Y is optional"; + public static final String MESSAGE_USAGE = COMMAND_WORD + "Sets course"; + + public static final String MESSAGE_SUCCESS = "Successfully updated course"; + + private final Course course; public SetCourseCommand(Course course) { @@ -19,12 +26,13 @@ public SetCourseCommand(Course course) { this.course = course; } - - public static final String MESSAGE_NOT_IMPLEMENTED_YET = - "Course command not implemented yet"; @Override public CommandResult execute(Model model) throws CommandException { - throw new CommandException(MESSAGE_NOT_IMPLEMENTED_YET + course); + if (!isValidCode(course.toString())) { + throw new CommandException(MESSAGE_CONSTRAINTS); + } + model.changeCode(course.toString()); + return new CommandResult(MESSAGE_SUCCESS); } @Override diff --git a/src/main/java/seedu/address/model/CourseName.java b/src/main/java/seedu/address/model/CourseName.java new file mode 100644 index 00000000000..5953d3e27cb --- /dev/null +++ b/src/main/java/seedu/address/model/CourseName.java @@ -0,0 +1,77 @@ +package seedu.address.model; + +import static java.util.Objects.requireNonNull; + +import seedu.address.model.course.Course; + +/** + * Wraps all data at the address-book level + * Duplicates are not allowed (by .isSamePerson comparison) + */ +public class CourseName implements ReadOnlyCourse { + + private Course course; + + + public CourseName() {} + + /** + * Creates a Course using the course in the {@code toBeCopied} + */ + public CourseName(ReadOnlyCourse toBeCopied) { + this(); + resetData(toBeCopied); + } + + //// list overwrite operations + + /** + * Replaces the contents of the course. + */ + public void setCourse(Course c) { + this.course = c; + } + + /** + * Resets the existing data of this {@code CourseName} with {@code newData}. + */ + public void resetData(ReadOnlyCourse newData) { + requireNonNull(newData); + + this.course = newData.getCourse(); + } + + + + //// util methods + + @Override + public String toString() { + return course.toString(); + } + + @Override + public Course getCourse() { + return this.course; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof CourseName)) { + return false; + } + + CourseName otherCourseName = (CourseName) other; + return course.equals(otherCourseName.course); + } + + @Override + public int hashCode() { + return course.hashCode(); + } +} diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index d54df471c1f..ff7f5c32b9b 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -4,6 +4,7 @@ import java.util.function.Predicate; import javafx.collections.ObservableList; +import javafx.beans.property.ReadOnlyStringProperty; import seedu.address.commons.core.GuiSettings; import seedu.address.model.person.Person; @@ -84,4 +85,55 @@ public interface Model { * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredPersonList(Predicate predicate); + + /** Changes the course code with the one specified */ + void changeCode(String code); + + /** + * Returns a ReadOnlyStringProperty for the course code. + * This allows observers to track changes to the course code. + * @return a read-only string property representing the course code. + */ + ReadOnlyStringProperty courseCodeProperty(); + + /** + * Returns the file path where the course name data is stored. + * This method provides the location of the storage file that contains + * the course name information. The path can be used to read from or write to + * the file directly. + * + * @return the {@link Path} representing the file path of the course name data. + */ + Path getCourseNameFilePath(); + + /** + * Sets the file path for storing the course name data. + * This method updates the storage location to the specified file path. + * Future operations to save the course name will use this new path. + * + * @param courseNameFilePath the {@link Path} to the file where the course name data should be saved. + */ + void setCourseNameFilePath(Path courseNameFilePath); + + /** + * Saves the given course name information to the storage. + * This method serializes the {@link ReadOnlyCourse} object and saves it + * to the designated storage file. It is used to persist changes to the course + * name across application runs. + * + * @param course the {@link ReadOnlyCourse} object representing the course name to be saved. + */ + void setCourseName(ReadOnlyCourse course); + + + /** + * Retrieves the course name from the storage. + * This method reads the stored course name data from the file and deserializes it + * into a {@link CourseName} object. It is used to load the course name information + * when the application starts or whenever the course name needs to be accessed. + * + * @return the {@link CourseName} object representing the course name retrieved from storage + */ + CourseName getCourseName(); + } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 57bc563fde6..59b53bd17fe 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -7,11 +7,14 @@ import java.util.function.Predicate; import java.util.logging.Logger; +import javafx.beans.property.ReadOnlyStringWrapper; +import javafx.beans.property.ReadOnlyStringProperty; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; import seedu.address.model.person.Person; +import seedu.address.model.course.Course; /** * Represents the in-memory model of the address book data. @@ -23,10 +26,14 @@ public class ModelManager implements Model { private final UserPrefs userPrefs; private final FilteredList filteredPersons; + private final CourseName currentCourse; + + private ReadOnlyStringWrapper courseCode = new ReadOnlyStringWrapper("defaultCode"); + /** - * Initializes a ModelManager with the given addressBook and userPrefs. + * Initializes a ModelManager with the given addressBook, userPrefs and currentCourse. */ - public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) { + public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs, ReadOnlyCourse currentCourse) { requireAllNonNull(addressBook, userPrefs); logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); @@ -34,10 +41,11 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs this.addressBook = new AddressBook(addressBook); this.userPrefs = new UserPrefs(userPrefs); filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); + this.currentCourse = new CourseName(currentCourse); } public ModelManager() { - this(new AddressBook(), new UserPrefs()); + this(new AddressBook(), new UserPrefs(), new CourseName()); } //=========== UserPrefs ================================================================================== @@ -128,6 +136,46 @@ public void updateFilteredPersonList(Predicate predicate) { filteredPersons.setPredicate(predicate); } + //=========== Course Code ============================================================= + @Override + public Path getCourseNameFilePath() { + return userPrefs.getCourseNameFilePath(); + } + + @Override + public void setCourseNameFilePath(Path courseNameFilePath) { + requireNonNull(courseNameFilePath); + userPrefs.setAddressBookFilePath(courseNameFilePath); + } + + //=========== AddressBook ================================================================================ + + @Override + public void setCourseName(ReadOnlyCourse course) { + this.currentCourse.resetData(course); + } + + @Override + public CourseName getCourseName() { + return currentCourse; + } + + @Override + public void changeCode(String newCode) { + requireNonNull(newCode); + if (Course.isValidCode(newCode)) { + currentCourse.setCourse(new Course(newCode)); + this.courseCode.set(newCode); + } else { + throw new IllegalArgumentException(Course.MESSAGE_CONSTRAINTS); + } + } + + @Override + public ReadOnlyStringProperty courseCodeProperty() { + return courseCode.getReadOnlyProperty(); + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/model/ReadOnlyCourse.java b/src/main/java/seedu/address/model/ReadOnlyCourse.java new file mode 100644 index 00000000000..8fd41eb1f2d --- /dev/null +++ b/src/main/java/seedu/address/model/ReadOnlyCourse.java @@ -0,0 +1,18 @@ +package seedu.address.model; + +import javafx.collections.ObservableList; +import seedu.address.model.course.Course; + +/** + * Unmodifiable view of a list of course (only 1 for now) + */ +public interface ReadOnlyCourse { + + /** + * Returns an unmodifiable view of the courses. + * This list will not contain any duplicate courses, and only. + * have one for now. + */ + Course getCourse(); + +} diff --git a/src/main/java/seedu/address/model/UserPrefs.java b/src/main/java/seedu/address/model/UserPrefs.java index 6be655fb4c7..d676769f754 100644 --- a/src/main/java/seedu/address/model/UserPrefs.java +++ b/src/main/java/seedu/address/model/UserPrefs.java @@ -15,7 +15,7 @@ public class UserPrefs implements ReadOnlyUserPrefs { private GuiSettings guiSettings = new GuiSettings(); private Path addressBookFilePath = Paths.get("data" , "addressbook.json"); - + private Path courseNameFilePath = Paths.get("data", "coursename.json"); /** * Creates a {@code UserPrefs} with default values. */ @@ -36,6 +36,7 @@ public void resetData(ReadOnlyUserPrefs newUserPrefs) { requireNonNull(newUserPrefs); setGuiSettings(newUserPrefs.getGuiSettings()); setAddressBookFilePath(newUserPrefs.getAddressBookFilePath()); + } public GuiSettings getGuiSettings() { @@ -50,12 +51,20 @@ public void setGuiSettings(GuiSettings guiSettings) { public Path getAddressBookFilePath() { return addressBookFilePath; } + public Path getCourseNameFilePath() { + return courseNameFilePath; + } public void setAddressBookFilePath(Path addressBookFilePath) { requireNonNull(addressBookFilePath); this.addressBookFilePath = addressBookFilePath; } + public void setCourseNameFilePath(Path courseNameFilePath) { + requireNonNull(courseNameFilePath); + this.courseNameFilePath = courseNameFilePath; + } + @Override public boolean equals(Object other) { if (other == this) { @@ -69,12 +78,13 @@ public boolean equals(Object other) { UserPrefs otherUserPrefs = (UserPrefs) other; return guiSettings.equals(otherUserPrefs.guiSettings) - && addressBookFilePath.equals(otherUserPrefs.addressBookFilePath); + && addressBookFilePath.equals(otherUserPrefs.addressBookFilePath) + && courseNameFilePath.equals(otherUserPrefs.courseNameFilePath); } @Override public int hashCode() { - return Objects.hash(guiSettings, addressBookFilePath); + return Objects.hash(guiSettings, addressBookFilePath, courseNameFilePath); } @Override @@ -82,6 +92,7 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Gui Settings : " + guiSettings); sb.append("\nLocal data file location : " + addressBookFilePath); + sb.append("\nLocal Course Name file location : " + courseNameFilePath); return sb.toString(); } diff --git a/src/main/java/seedu/address/model/course/Course.java b/src/main/java/seedu/address/model/course/Course.java index 57f86ec92c1..f0f22901f8b 100644 --- a/src/main/java/seedu/address/model/course/Course.java +++ b/src/main/java/seedu/address/model/course/Course.java @@ -1,7 +1,5 @@ package seedu.address.model.course; -import seedu.address.model.person.Name; - import static java.util.Objects.requireNonNull; import static seedu.address.commons.util.AppUtil.checkArgument; @@ -28,8 +26,9 @@ public class Course { */ public Course(String code) { requireNonNull(code); - checkArgument(isValidCode(code), MESSAGE_CONSTRAINTS); + course_code = code; + } public static boolean isValidCode(String test) { @@ -41,6 +40,10 @@ public String toString() { return course_code; } + public void changeCode(String code) { + this.course_code = code; + } + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/storage/CourseStorage.java b/src/main/java/seedu/address/storage/CourseStorage.java new file mode 100644 index 00000000000..60f95282a71 --- /dev/null +++ b/src/main/java/seedu/address/storage/CourseStorage.java @@ -0,0 +1,42 @@ +package seedu.address.storage; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; + +import seedu.address.commons.exceptions.DataLoadingException; +import seedu.address.model.ReadOnlyCourse; +public interface CourseStorage { + + /** + * Returns the file path of the data file. + */ + Path getCourseNameFilePath(); + + /** + * Returns AddressBook data as a {@link ReadOnlyCourse}. + * Returns {@code Optional.empty()} if storage file is not found. + * + * @throws DataLoadingException if loading the data from storage failed. + */ + Optional read() throws DataLoadingException; + + /** + * @see #getCourseNameFilePath() + */ + Optional readCourseName(Path filePath) throws DataLoadingException; + + /** + * Saves the given {@link ReadOnlyCourse} to the storage. + * @param course cannot be null. + * @throws IOException if there was any problem writing to the file. + */ + void saveCourse(ReadOnlyCourse course) throws IOException; + + /** + * @see #saveCourse(ReadOnlyCourse) + */ + void saveCourse(ReadOnlyCourse course, Path filePath) throws IOException; + + +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedCourse.java b/src/main/java/seedu/address/storage/JsonAdaptedCourse.java new file mode 100644 index 00000000000..7ef2bfa2354 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedCourse.java @@ -0,0 +1,47 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.course.Course; + +/** + * Jackson-friendly version of {@link Course}. + */ +public class JsonAdaptedCourse { + + private String courseCode; + + /** + * Constructs a {@code JsonAdaptedCourse} with the given {@code courseCode}. + */ + @JsonCreator + public JsonAdaptedCourse(String courseCode) { + this.courseCode = courseCode; + } + + /** + * Converts a given {@code Course} into this class for Jackson use. + */ + public JsonAdaptedCourse(Course source) { + courseCode = source.toString(); + } + + @JsonValue + public String getCourseCode() { + return courseCode; + } + + /** + * Converts this Jackson-friendly adapted tag object into the model's {@code Tag} object. + * + * @throws IllegalValueException if there were any data constraints violated in the adapted tag. + */ + public Course toModelType() throws IllegalValueException { + if (!Course.isValidCode(courseCode)) { + throw new IllegalValueException(Course.MESSAGE_CONSTRAINTS); + } + return new Course(courseCode); + } +} diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 5efd834091d..b903e06a844 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -23,6 +23,7 @@ class JsonSerializableAddressBook { private final List persons = new ArrayList<>(); + /** * Constructs a {@code JsonSerializableAddressBook} with the given persons. */ diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 79e74ef37c0..a498a39ae2c 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -2,6 +2,8 @@ import java.util.logging.Logger; + +import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.MenuItem; @@ -16,6 +18,7 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.Model; /** * The Main Window. Provides the basic application layout containing @@ -30,6 +33,11 @@ public class MainWindow extends UiPart { private Stage primaryStage; private Logic logic; + private Model model; + + + + // Independent Ui parts residing in this Ui container private PersonListPanel personListPanel; private ResultDisplay resultDisplay; @@ -53,12 +61,17 @@ public class MainWindow extends UiPart { /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. */ - public MainWindow(Stage primaryStage, Logic logic) { + public MainWindow(Stage primaryStage, Logic logic, Model model) { super(FXML, primaryStage); // Set dependencies this.primaryStage = primaryStage; this.logic = logic; + this.model = model; + + model.courseCodeProperty().addListener((obs, oldVal, newVal) -> { + Platform.runLater(() -> setWindowTitle("Course:" + newVal)); + }); // Configure the UI setWindowDefaultSize(logic.getGuiSettings()); @@ -72,6 +85,14 @@ public Stage getPrimaryStage() { return primaryStage; } + /** + * Sets the title of the application window. + * @param title The title to set for the window. + */ + private void setWindowTitle(String title) { + primaryStage.setTitle(title); + } + private void setAccelerators() { setAccelerator(helpMenuItem, KeyCombination.valueOf("F1")); } diff --git a/src/main/java/seedu/address/ui/UiManager.java b/src/main/java/seedu/address/ui/UiManager.java index fdf024138bc..b34d8824803 100644 --- a/src/main/java/seedu/address/ui/UiManager.java +++ b/src/main/java/seedu/address/ui/UiManager.java @@ -11,6 +11,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.commons.util.StringUtil; import seedu.address.logic.Logic; +import seedu.address.model.Model; /** * The manager of the UI component. @@ -23,13 +24,16 @@ public class UiManager implements Ui { private static final String ICON_APPLICATION = "/images/address_book_32.png"; private Logic logic; + + private Model model; private MainWindow mainWindow; /** * Creates a {@code UiManager} with the given {@code Logic}. */ - public UiManager(Logic logic) { + public UiManager(Logic logic, Model model) { this.logic = logic; + this.model = model; } @Override @@ -40,7 +44,7 @@ public void start(Stage primaryStage) { primaryStage.getIcons().add(getImage(ICON_APPLICATION)); try { - mainWindow = new MainWindow(primaryStage, logic); + mainWindow = new MainWindow(primaryStage, logic, model); mainWindow.show(); //This should be called before creating other UI parts mainWindow.fillInnerParts(); diff --git a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java index cbb9c3471af..f1ca2aa3a8d 100644 --- a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java @@ -23,6 +23,27 @@ public class SetCourseCommandTest { @Test public void execute() { Course course = new Course("CS2103T"); - assertCommandFailure(new SetCourseCommand(course), model, "hi"); + assertCommandFailure(new SetCourseCommand(course), model, "CS2103T" ); + } + + @Test + public void equals() { + final SetCourseCommand standardCommand = new SetCourseCommand(new Course(VALID_COURSE_CODE_AMY)); + + // same values -> returns true + SetCourseCommand commandWithSameValues = new SetCourseCommand(new Course(VALID_COURSE_CODE_AMY)); + assertTrue(standardCommand.equals(commandWithSameValues)); + + // same object -> returns true + assertTrue(standardCommand.equals(standardCommand)); + + // null -> returns false + assertFalse(standardCommand.equals(null)); + + // different types -> returns false + assertFalse(standardCommand.equals(new ClearCommand())); + + // different course_code -> returns false + assertFalse(standardCommand.equals(new SetCourseCommand(new Course(VALID_COURSE_CODE_BOB)))); } } diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 604cb4231a2..b5ce374c35c 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -24,6 +24,7 @@ import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.commands.ListPersonCommand; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.course.Course; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; import seedu.address.testutil.EditPersonDescriptorBuilder; @@ -97,7 +98,10 @@ public void parseCommand_unrecognisedInput_throwsParseException() { @Test public void parseCommand_setcourse() throws Exception { - assertTrue(parser.parseCommand(SetCourseCommand.COMMAND_WORD) instanceof SetCourseCommand); + final String code = "CS2103T"; + SetCourseCommand command = (SetCourseCommand) parser.parseCommand(SetCourseCommand.COMMAND_WORD + " " + + code); + assertEquals(new SetCourseCommand(new Course(code)), command); } @Test diff --git a/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java b/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java new file mode 100644 index 00000000000..8f94a467bcb --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java @@ -0,0 +1,24 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.SetCourseCommand; + +public class SetCourseCommandParserTest { + private SetCourseCommandParser parser = new SetCourseCommandParser(); + private final String course = "CS2103T"; + + + @Test + public void parse_missingCompulsoryField_failure() { + String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCourseCommand.MESSAGE_USAGE); + + assertParseFailure(parser, SetCourseCommand.COMMAND_WORD, expectedMessage); + + assertParseFailure(parser, SetCourseCommand.COMMAND_WORD + " " + course, expectedMessage); + } +} From 75343320b2d3562546d4541eb6d2afbc6d30d558 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:59:46 +0800 Subject: [PATCH 04/13] Added Course Storage Classes --- .../java/seedu/address/model/CourseName.java | 6 +- src/main/java/seedu/address/model/Model.java | 6 +- .../seedu/address/model/ModelManager.java | 4 +- ...nlyCourse.java => ReadOnlyCourseName.java} | 3 +- .../address/model/ReadOnlyUserPrefs.java | 1 + .../java/seedu/address/model/UserPrefs.java | 2 +- ...rseStorage.java => CourseStorageName.java} | 18 ++--- .../storage/JsonCourseNameStorage.java | 81 +++++++++++++++++++ .../storage/JsonSerializableCourseName.java | 47 +++++++++++ .../java/seedu/address/storage/Storage.java | 13 ++- .../seedu/address/storage/StorageManager.java | 33 ++++++++ 11 files changed, 193 insertions(+), 21 deletions(-) rename src/main/java/seedu/address/model/{ReadOnlyCourse.java => ReadOnlyCourseName.java} (81%) rename src/main/java/seedu/address/storage/{CourseStorage.java => CourseStorageName.java} (55%) create mode 100644 src/main/java/seedu/address/storage/JsonCourseNameStorage.java create mode 100644 src/main/java/seedu/address/storage/JsonSerializableCourseName.java diff --git a/src/main/java/seedu/address/model/CourseName.java b/src/main/java/seedu/address/model/CourseName.java index 5953d3e27cb..4cc9ba36940 100644 --- a/src/main/java/seedu/address/model/CourseName.java +++ b/src/main/java/seedu/address/model/CourseName.java @@ -8,7 +8,7 @@ * Wraps all data at the address-book level * Duplicates are not allowed (by .isSamePerson comparison) */ -public class CourseName implements ReadOnlyCourse { +public class CourseName implements ReadOnlyCourseName { private Course course; @@ -18,7 +18,7 @@ public CourseName() {} /** * Creates a Course using the course in the {@code toBeCopied} */ - public CourseName(ReadOnlyCourse toBeCopied) { + public CourseName(ReadOnlyCourseName toBeCopied) { this(); resetData(toBeCopied); } @@ -35,7 +35,7 @@ public void setCourse(Course c) { /** * Resets the existing data of this {@code CourseName} with {@code newData}. */ - public void resetData(ReadOnlyCourse newData) { + public void resetData(ReadOnlyCourseName newData) { requireNonNull(newData); this.course = newData.getCourse(); diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index ff7f5c32b9b..ac893853e10 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -117,13 +117,13 @@ public interface Model { /** * Saves the given course name information to the storage. - * This method serializes the {@link ReadOnlyCourse} object and saves it + * This method serializes the {@link ReadOnlyCourseName} object and saves it * to the designated storage file. It is used to persist changes to the course * name across application runs. * - * @param course the {@link ReadOnlyCourse} object representing the course name to be saved. + * @param course the {@link ReadOnlyCourseName} object representing the course name to be saved. */ - void setCourseName(ReadOnlyCourse course); + void setCourseName(ReadOnlyCourseName course); /** diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 59b53bd17fe..e64fdffc2d1 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -33,7 +33,7 @@ public class ModelManager implements Model { /** * Initializes a ModelManager with the given addressBook, userPrefs and currentCourse. */ - public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs, ReadOnlyCourse currentCourse) { + public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs, ReadOnlyCourseName currentCourse) { requireAllNonNull(addressBook, userPrefs); logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); @@ -151,7 +151,7 @@ public void setCourseNameFilePath(Path courseNameFilePath) { //=========== AddressBook ================================================================================ @Override - public void setCourseName(ReadOnlyCourse course) { + public void setCourseName(ReadOnlyCourseName course) { this.currentCourse.resetData(course); } diff --git a/src/main/java/seedu/address/model/ReadOnlyCourse.java b/src/main/java/seedu/address/model/ReadOnlyCourseName.java similarity index 81% rename from src/main/java/seedu/address/model/ReadOnlyCourse.java rename to src/main/java/seedu/address/model/ReadOnlyCourseName.java index 8fd41eb1f2d..9774ffa7bc4 100644 --- a/src/main/java/seedu/address/model/ReadOnlyCourse.java +++ b/src/main/java/seedu/address/model/ReadOnlyCourseName.java @@ -1,12 +1,11 @@ package seedu.address.model; -import javafx.collections.ObservableList; import seedu.address.model.course.Course; /** * Unmodifiable view of a list of course (only 1 for now) */ -public interface ReadOnlyCourse { +public interface ReadOnlyCourseName { /** * Returns an unmodifiable view of the courses. diff --git a/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java b/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java index befd58a4c73..f6dd5e751d7 100644 --- a/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java +++ b/src/main/java/seedu/address/model/ReadOnlyUserPrefs.java @@ -13,4 +13,5 @@ public interface ReadOnlyUserPrefs { Path getAddressBookFilePath(); + Path getCourseNameFilePath(); } diff --git a/src/main/java/seedu/address/model/UserPrefs.java b/src/main/java/seedu/address/model/UserPrefs.java index d676769f754..a281dfa2598 100644 --- a/src/main/java/seedu/address/model/UserPrefs.java +++ b/src/main/java/seedu/address/model/UserPrefs.java @@ -36,7 +36,7 @@ public void resetData(ReadOnlyUserPrefs newUserPrefs) { requireNonNull(newUserPrefs); setGuiSettings(newUserPrefs.getGuiSettings()); setAddressBookFilePath(newUserPrefs.getAddressBookFilePath()); - + setCourseNameFilePath(newUserPrefs.getCourseNameFilePath()); } public GuiSettings getGuiSettings() { diff --git a/src/main/java/seedu/address/storage/CourseStorage.java b/src/main/java/seedu/address/storage/CourseStorageName.java similarity index 55% rename from src/main/java/seedu/address/storage/CourseStorage.java rename to src/main/java/seedu/address/storage/CourseStorageName.java index 60f95282a71..5bab10255c9 100644 --- a/src/main/java/seedu/address/storage/CourseStorage.java +++ b/src/main/java/seedu/address/storage/CourseStorageName.java @@ -5,8 +5,8 @@ import java.util.Optional; import seedu.address.commons.exceptions.DataLoadingException; -import seedu.address.model.ReadOnlyCourse; -public interface CourseStorage { +import seedu.address.model.ReadOnlyCourseName; +public interface CourseStorageName { /** * Returns the file path of the data file. @@ -14,29 +14,29 @@ public interface CourseStorage { Path getCourseNameFilePath(); /** - * Returns AddressBook data as a {@link ReadOnlyCourse}. + * Returns AddressBook data as a {@link ReadOnlyCourseName}. * Returns {@code Optional.empty()} if storage file is not found. * * @throws DataLoadingException if loading the data from storage failed. */ - Optional read() throws DataLoadingException; + Optional readCourse() throws DataLoadingException; /** * @see #getCourseNameFilePath() */ - Optional readCourseName(Path filePath) throws DataLoadingException; + Optional readCourse(Path filePath) throws DataLoadingException; /** - * Saves the given {@link ReadOnlyCourse} to the storage. + * Saves the given {@link ReadOnlyCourseName} to the storage. * @param course cannot be null. * @throws IOException if there was any problem writing to the file. */ - void saveCourse(ReadOnlyCourse course) throws IOException; + void saveCourse(ReadOnlyCourseName course) throws IOException; /** - * @see #saveCourse(ReadOnlyCourse) + * @see #saveCourse(ReadOnlyCourseName) */ - void saveCourse(ReadOnlyCourse course, Path filePath) throws IOException; + void saveCourse(ReadOnlyCourseName course, Path filePath) throws IOException; } diff --git a/src/main/java/seedu/address/storage/JsonCourseNameStorage.java b/src/main/java/seedu/address/storage/JsonCourseNameStorage.java new file mode 100644 index 00000000000..a303f82e245 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonCourseNameStorage.java @@ -0,0 +1,81 @@ +package seedu.address.storage; + +import static java.util.Objects.requireNonNull; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.Optional; +import java.util.logging.Logger; + +import seedu.address.commons.core.LogsCenter; +import seedu.address.commons.exceptions.DataLoadingException; +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.commons.util.FileUtil; +import seedu.address.commons.util.JsonUtil; +import seedu.address.model.ReadOnlyCourseName; + +/** + * A class to access Course data stored as a json file on the hard disk. + */ +public class JsonCourseNameStorage implements CourseStorageName { + + private static final Logger logger = LogsCenter.getLogger(JsonCourseNameStorage.class); + + private Path filePath; + + public JsonCourseNameStorage(Path filePath) { + this.filePath = filePath; + } + + public Path getCourseNameFilePath() { + return filePath; + } + + @Override + public Optional readCourse() throws DataLoadingException { + return readCourse(this.filePath); + } + + + /** + * Similar to {@link #readCourse()}. + * + * @param filePath location of the data. Cannot be null. + * @throws DataLoadingException if loading the data from storage failed. + */ + public Optional readCourse(Path filePath) throws DataLoadingException { + requireNonNull(filePath); + + Optional jsonCourse = JsonUtil.readJsonFile( + filePath, JsonSerializableCourseName.class); + if (!jsonCourse.isPresent()) { + return Optional.empty(); + } + + try { + return Optional.of(jsonCourse.get().toModelType()); + } catch (IllegalValueException ive) { + logger.info("Illegal values found in " + filePath + ": " + ive.getMessage()); + throw new DataLoadingException(ive); + } + } + + @Override + public void saveCourse(ReadOnlyCourseName course) throws IOException { + saveCourse(course, filePath); + } + + /** + * Similar to {@link #saveCourse(ReadOnlyCourseName)}. + * + * @param filePath location of the data. Cannot be null. + */ + public void saveCourse(ReadOnlyCourseName course, Path filePath) throws IOException { + requireNonNull(course); + requireNonNull(filePath); + + FileUtil.createIfMissing(filePath); + JsonUtil.saveJsonFile(new JsonSerializableCourseName(course), filePath); + } + +} diff --git a/src/main/java/seedu/address/storage/JsonSerializableCourseName.java b/src/main/java/seedu/address/storage/JsonSerializableCourseName.java new file mode 100644 index 00000000000..d0ca1938af0 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonSerializableCourseName.java @@ -0,0 +1,47 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.CourseName; +import seedu.address.model.ReadOnlyCourseName; + +/** + * An Immutable Course that is serializable to JSON format. + */ +@JsonRootName(value = "course") +public class JsonSerializableCourseName { + + private JsonAdaptedCourse course; + + /** + * Constructs a {@code JsonSerializableCourse} with the given code. + */ + @JsonCreator + public JsonSerializableCourseName(@JsonProperty("course") JsonAdaptedCourse course) { + this.course = course; + } + + /** + * Converts a given {@code ReadOnlyCourse} into this class for Jackson use. + * + * @param source future changes to this will not affect the created {@code JsonSerializableCourse}. + */ + public JsonSerializableCourseName(ReadOnlyCourseName source) { + course = new JsonAdaptedCourse(source.getCourse().toString()); + } + + /** + * Converts this course into the model's {@code Course} object. + * + * @throws IllegalValueException if there were any data constraints violated. + */ + public CourseName toModelType() throws IllegalValueException { + CourseName courseName = new CourseName(); + courseName.setCourse(this.course.toModelType()); + return courseName; + } + +} diff --git a/src/main/java/seedu/address/storage/Storage.java b/src/main/java/seedu/address/storage/Storage.java index 9fba0c7a1d6..82c0df9a4d9 100644 --- a/src/main/java/seedu/address/storage/Storage.java +++ b/src/main/java/seedu/address/storage/Storage.java @@ -6,13 +6,14 @@ import seedu.address.commons.exceptions.DataLoadingException; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; /** * API of the Storage component */ -public interface Storage extends AddressBookStorage, UserPrefsStorage { +public interface Storage extends AddressBookStorage, UserPrefsStorage, CourseStorageName { @Override Optional readUserPrefs() throws DataLoadingException; @@ -23,10 +24,20 @@ public interface Storage extends AddressBookStorage, UserPrefsStorage { @Override Path getAddressBookFilePath(); + @Override + Path getCourseNameFilePath(); + @Override Optional readAddressBook() throws DataLoadingException; @Override void saveAddressBook(ReadOnlyAddressBook addressBook) throws IOException; + + @Override + Optional readCourse() throws DataLoadingException; + + @Override + void saveCourse(ReadOnlyCourseName course) throws IOException; + } diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 8b84a9024d5..823c8f46e2d 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -8,6 +8,7 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.commons.exceptions.DataLoadingException; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.UserPrefs; @@ -20,6 +21,8 @@ public class StorageManager implements Storage { private AddressBookStorage addressBookStorage; private UserPrefsStorage userPrefsStorage; + private CourseStorageName courseNameStorage; + /** * Creates a {@code StorageManager} with the given {@code AddressBookStorage} and {@code UserPrefStorage}. */ @@ -75,4 +78,34 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) thro addressBookStorage.saveAddressBook(addressBook, filePath); } + // ================ Course methods ============================== + + @Override + public Path getCourseNameFilePath() { + return courseNameStorage.getCourseNameFilePath(); + } + + @Override + public Optional readCourse() throws DataLoadingException { + return readCourse(courseNameStorage.getCourseNameFilePath()); + } + + @Override + public Optional readCourse(Path filePath) throws DataLoadingException { + logger.fine("Attempting to read data from file: " + filePath); + return courseNameStorage.readCourse(filePath); + } + + @Override + public void saveCourse(ReadOnlyCourseName courseName) throws IOException { + saveCourse(courseName, courseNameStorage.getCourseNameFilePath()); + } + + @Override + public void saveCourse(ReadOnlyCourseName courseName, Path filePath) throws IOException { + logger.fine("Attempting to write to data file: " + filePath); + courseNameStorage.saveCourse(courseName, filePath); + } + + } From 2f7e01bb4aa38b36b5af3cbe15270b4e7439a6cb Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:03:39 +0800 Subject: [PATCH 05/13] Persistent data across runs --- src/main/java/seedu/address/MainApp.java | 35 +++++++++-------- src/main/java/seedu/address/logic/Logic.java | 16 ++++++++ .../seedu/address/logic/LogicManager.java | 12 ++++++ .../java/seedu/address/model/CourseName.java | 1 + .../seedu/address/model/ModelManager.java | 4 +- .../address/model/util/SampleDataUtil.java | 9 +++++ .../seedu/address/storage/StorageManager.java | 3 +- .../java/seedu/address/ui/MainWindow.java | 39 ++++++++++++++++++- src/main/java/seedu/address/ui/UiManager.java | 8 +++- 9 files changed, 104 insertions(+), 23 deletions(-) diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 3df0a1d0ff6..0a2adad649b 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -15,19 +15,9 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.Logic; import seedu.address.logic.LogicManager; -import seedu.address.model.AddressBook; -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.ReadOnlyUserPrefs; -import seedu.address.model.UserPrefs; +import seedu.address.model.*; import seedu.address.model.util.SampleDataUtil; -import seedu.address.storage.AddressBookStorage; -import seedu.address.storage.JsonAddressBookStorage; -import seedu.address.storage.JsonUserPrefsStorage; -import seedu.address.storage.Storage; -import seedu.address.storage.StorageManager; -import seedu.address.storage.UserPrefsStorage; +import seedu.address.storage.*; import seedu.address.ui.Ui; import seedu.address.ui.UiManager; @@ -58,13 +48,14 @@ public void init() throws Exception { UserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(config.getUserPrefsFilePath()); UserPrefs userPrefs = initPrefs(userPrefsStorage); AddressBookStorage addressBookStorage = new JsonAddressBookStorage(userPrefs.getAddressBookFilePath()); - storage = new StorageManager(addressBookStorage, userPrefsStorage); + CourseStorageName courseStorageName = new JsonCourseNameStorage(userPrefs.getCourseNameFilePath()); + storage = new StorageManager(addressBookStorage, userPrefsStorage, courseStorageName); model = initModelManager(storage, userPrefs); logic = new LogicManager(model, storage); - ui = new UiManager(logic, model); + ui = new UiManager(logic, model, storage); } /** @@ -74,23 +65,35 @@ public void init() throws Exception { */ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { logger.info("Using data file : " + storage.getAddressBookFilePath()); - + logger.info("Using course data file : " + storage.getCourseNameFilePath()); Optional addressBookOptional; + Optional courseNameOptional; ReadOnlyAddressBook initialData; + ReadOnlyCourseName initialCourseNameData; try { addressBookOptional = storage.readAddressBook(); if (!addressBookOptional.isPresent()) { logger.info("Creating a new data file " + storage.getAddressBookFilePath() + " populated with a sample AddressBook."); } + courseNameOptional = storage.readCourse(); + + if (!courseNameOptional.isPresent()) { + logger.info("Creating a new course data file " + storage.getCourseNameFilePath() + + " populated with a course."); + } + + initialCourseNameData = courseNameOptional.orElseGet(SampleDataUtil::getSampleCourseName); initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook); } catch (DataLoadingException e) { logger.warning("Data file at " + storage.getAddressBookFilePath() + " could not be loaded." + " Will be starting with an empty AddressBook."); + // Room to add logging for course name file here too initialData = new AddressBook(); + initialCourseNameData = new CourseName(); } - return new ModelManager(initialData, userPrefs); + return new ModelManager(initialData, userPrefs, initialCourseNameData); } private void initLogging(Config config) { diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 92cd8fa605a..65ce863e529 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -7,7 +7,9 @@ import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; import seedu.address.model.person.Person; /** @@ -47,4 +49,18 @@ public interface Logic { * Set the user prefs' GUI settings. */ void setGuiSettings(GuiSettings guiSettings); + + /** + * Returns the CourseName. + * + * @see Model#getCourseName() + */ + ReadOnlyCourseName getCourseName(); + + /** + * Returns the user prefs' courseName file path. + */ + Path getCourseNameFilePath(); + + } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 5aa3b91c7d0..4d2adc74837 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -15,6 +15,7 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; import seedu.address.model.person.Person; import seedu.address.storage.Storage; @@ -46,12 +47,14 @@ public LogicManager(Model model, Storage storage) { public CommandResult execute(String commandText) throws CommandException, ParseException { logger.info("----------------[USER COMMAND][" + commandText + "]"); + CommandResult commandResult; Command command = addressBookParser.parseCommand(commandText); commandResult = command.execute(model); try { storage.saveAddressBook(model.getAddressBook()); + storage.saveCourse(model.getCourseName()); } catch (AccessDeniedException e) { throw new CommandException(String.format(FILE_OPS_PERMISSION_ERROR_FORMAT, e.getMessage()), e); } catch (IOException ioe) { @@ -85,4 +88,13 @@ public GuiSettings getGuiSettings() { public void setGuiSettings(GuiSettings guiSettings) { model.setGuiSettings(guiSettings); } + + @Override + public ReadOnlyCourseName getCourseName() { + return model.getCourseName(); + } + @Override + public Path getCourseNameFilePath() { + return model.getCourseNameFilePath(); + } } diff --git a/src/main/java/seedu/address/model/CourseName.java b/src/main/java/seedu/address/model/CourseName.java index 4cc9ba36940..da76a1e8d74 100644 --- a/src/main/java/seedu/address/model/CourseName.java +++ b/src/main/java/seedu/address/model/CourseName.java @@ -3,6 +3,7 @@ import static java.util.Objects.requireNonNull; import seedu.address.model.course.Course; +import seedu.address.model.person.UniquePersonList; /** * Wraps all data at the address-book level diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index e64fdffc2d1..98577e0a348 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -34,7 +34,7 @@ public class ModelManager implements Model { * Initializes a ModelManager with the given addressBook, userPrefs and currentCourse. */ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs, ReadOnlyCourseName currentCourse) { - requireAllNonNull(addressBook, userPrefs); + requireAllNonNull(addressBook, userPrefs, currentCourse); logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); @@ -148,8 +148,6 @@ public void setCourseNameFilePath(Path courseNameFilePath) { userPrefs.setAddressBookFilePath(courseNameFilePath); } - //=========== AddressBook ================================================================================ - @Override public void setCourseName(ReadOnlyCourseName course) { this.currentCourse.resetData(course); diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 45ef3057f8f..cf02e3d3328 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -5,7 +5,10 @@ import java.util.stream.Collectors; import seedu.address.model.AddressBook; +import seedu.address.model.CourseName; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; +import seedu.address.model.course.Course; import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; @@ -58,4 +61,10 @@ public static Set getTagSet(String... strings) { .collect(Collectors.toSet()); } + public static ReadOnlyCourseName getSampleCourseName() { + CourseName courseName = new CourseName(); + courseName.setCourse(new Course("XX1234Y")); + return courseName; + } + } diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 823c8f46e2d..42663507af0 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -26,9 +26,10 @@ public class StorageManager implements Storage { /** * Creates a {@code StorageManager} with the given {@code AddressBookStorage} and {@code UserPrefStorage}. */ - public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage) { + public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage, CourseStorageName courseStorageName) { this.addressBookStorage = addressBookStorage; this.userPrefsStorage = userPrefsStorage; + this.courseNameStorage = courseStorageName; } // ================ UserPrefs methods ============================== diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index a498a39ae2c..7e0b9b34815 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -1,5 +1,6 @@ package seedu.address.ui; +import java.util.Optional; import java.util.logging.Logger; @@ -14,11 +15,16 @@ import javafx.stage.Stage; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; +import seedu.address.commons.exceptions.DataLoadingException; import seedu.address.logic.Logic; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.CourseName; import seedu.address.model.Model; +import seedu.address.model.ReadOnlyCourseName; +import seedu.address.model.util.SampleDataUtil; +import seedu.address.storage.Storage; /** * The Main Window. Provides the basic application layout containing @@ -33,11 +39,14 @@ public class MainWindow extends UiPart { private Stage primaryStage; private Logic logic; + protected Storage storage; + private Model model; + // Independent Ui parts residing in this Ui container private PersonListPanel personListPanel; private ResultDisplay resultDisplay; @@ -61,13 +70,16 @@ public class MainWindow extends UiPart { /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. */ - public MainWindow(Stage primaryStage, Logic logic, Model model) { + public MainWindow(Stage primaryStage, Logic logic, Model model, Storage storage) { super(FXML, primaryStage); // Set dependencies this.primaryStage = primaryStage; this.logic = logic; this.model = model; + this.storage = storage; + + this.loadInitialCourseNameAndSetTitle(); model.courseCodeProperty().addListener((obs, oldVal, newVal) -> { Platform.runLater(() -> setWindowTitle("Course:" + newVal)); @@ -97,6 +109,31 @@ private void setAccelerators() { setAccelerator(helpMenuItem, KeyCombination.valueOf("F1")); } + /** + * Loads the initial course name from the storage and sets it as the window title of the given stage. + * This method attempts to read the course name from a persistent storage. If the course name is not present, + * it logs the creation of a new course data file and uses a default or sample course name. In case of any errors + * during the loading process, it logs the error and uses a fallback course name. + */ + private void loadInitialCourseNameAndSetTitle() { + ReadOnlyCourseName initialCourseNameData; + try { + Optional courseNameOptional = storage.readCourse(); + + if (!courseNameOptional.isPresent()) { + logger.info("Creating a new course data file " + storage.getCourseNameFilePath() + " populated with a course."); + } + + initialCourseNameData = courseNameOptional.orElseGet(SampleDataUtil::getSampleCourseName); + } catch (DataLoadingException e) { + logger.warning("Error loading course name data"); + initialCourseNameData = new CourseName(); // Default or fallback course name + } + + // Set the initial window title with the loaded course name. + setWindowTitle("Course: " + initialCourseNameData.getCourse().toString()); + } + /** * Sets the accelerator of a MenuItem. * @param keyCombination the KeyCombination value of the accelerator diff --git a/src/main/java/seedu/address/ui/UiManager.java b/src/main/java/seedu/address/ui/UiManager.java index b34d8824803..ca6d0ccdcc1 100644 --- a/src/main/java/seedu/address/ui/UiManager.java +++ b/src/main/java/seedu/address/ui/UiManager.java @@ -12,6 +12,7 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.Logic; import seedu.address.model.Model; +import seedu.address.storage.Storage; /** * The manager of the UI component. @@ -25,15 +26,18 @@ public class UiManager implements Ui { private Logic logic; + private Storage storage; + private Model model; private MainWindow mainWindow; /** * Creates a {@code UiManager} with the given {@code Logic}. */ - public UiManager(Logic logic, Model model) { + public UiManager(Logic logic, Model model, Storage storage) { this.logic = logic; this.model = model; + this.storage = storage; } @Override @@ -44,7 +48,7 @@ public void start(Stage primaryStage) { primaryStage.getIcons().add(getImage(ICON_APPLICATION)); try { - mainWindow = new MainWindow(primaryStage, logic, model); + mainWindow = new MainWindow(primaryStage, logic, model, storage); mainWindow.show(); //This should be called before creating other UI parts mainWindow.fillInnerParts(); From fca65873892cb9cd4e6a12f08a264623cc20593b Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Sun, 17 Mar 2024 15:21:26 +0800 Subject: [PATCH 06/13] Some Unit Tests for Set Course Command --- .../address/commons/util/AppUtilTest.java | 5 -- .../seedu/address/logic/LogicManagerTest.java | 22 ++++-- .../commands/AddCommandIntegrationTest.java | 5 +- .../logic/commands/AddCommandTest.java | 36 ++++++++-- .../logic/commands/ClearCommandTest.java | 5 +- .../logic/commands/DeleteCommandTest.java | 7 +- .../logic/commands/EditCommandTest.java | 11 +-- .../logic/commands/FindCommandTest.java | 5 +- .../logic/commands/ListCommandTest.java | 5 +- .../logic/commands/SetCourseCommandTest.java | 35 ++++++---- ...t.java => SetCourseCommandParserTest.java} | 9 +-- .../seedu/address/model/CourseNameTest.java | 18 +++++ .../seedu/address/model/ModelManagerTest.java | 18 +++-- .../seedu/address/model/UserPrefsTest.java | 6 ++ .../storage/JsonAdaptedCourseTest.java | 37 ++++++++++ .../storage/JsonCourseNameStorageTest.java | 67 +++++++++++++++++++ .../address/storage/StorageManagerTest.java | 13 ++-- .../seedu/address/testutil/TypicalCourse.java | 29 ++++++++ 18 files changed, 266 insertions(+), 67 deletions(-) rename src/test/java/seedu/address/logic/parser/{RemarkCommandParserTest.java => SetCourseCommandParserTest.java} (59%) create mode 100644 src/test/java/seedu/address/model/CourseNameTest.java create mode 100644 src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java create mode 100644 src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java create mode 100644 src/test/java/seedu/address/testutil/TypicalCourse.java diff --git a/src/test/java/seedu/address/commons/util/AppUtilTest.java b/src/test/java/seedu/address/commons/util/AppUtilTest.java index 594de1e6365..7f00de5cc7d 100644 --- a/src/test/java/seedu/address/commons/util/AppUtilTest.java +++ b/src/test/java/seedu/address/commons/util/AppUtilTest.java @@ -7,11 +7,6 @@ public class AppUtilTest { - @Test - public void getImage_exitingImage() { - assertNotNull(AppUtil.getImage("/images/address_book_32.png")); - } - @Test public void getImage_nullGiven_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> AppUtil.getImage(null)); diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 1354e07aa0e..79c21240f6b 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -24,12 +24,10 @@ import seedu.address.logic.commands.ListPersonCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.UserPrefs; +import seedu.address.model.*; import seedu.address.model.person.Person; import seedu.address.storage.JsonAddressBookStorage; +import seedu.address.storage.JsonCourseNameStorage; import seedu.address.storage.JsonUserPrefsStorage; import seedu.address.storage.StorageManager; import seedu.address.testutil.PersonBuilder; @@ -49,7 +47,8 @@ public void setUp() { JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(temporaryFolder.resolve("addressBook.json")); JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("userPrefs.json")); - StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage); + JsonCourseNameStorage courseNameStorage = new JsonCourseNameStorage(temporaryFolder.resolve("courseStorage.json")); + StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage, courseNameStorage); logic = new LogicManager(model, storage); } @@ -124,7 +123,7 @@ private void assertCommandException(String inputCommand, String expectedMessage) */ private void assertCommandFailure(String inputCommand, Class expectedException, String expectedMessage) { - Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), model.getCourseName()); assertCommandFailure(inputCommand, expectedException, expectedMessage, expectedModel); } @@ -159,9 +158,18 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) } }; + JsonCourseNameStorage courseNameStorage = new JsonCourseNameStorage(prefPath) { + @Override + public void saveCourse(ReadOnlyCourseName courseName, Path filePath) + throws IOException { + throw e; + } + }; + JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("ExceptionUserPrefs.json")); - StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage); + + StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage, courseNameStorage); logic = new LogicManager(model, storage); diff --git a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java b/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java index 5398203c201..8c8425d7df4 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandIntegrationTest.java @@ -2,6 +2,7 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.BeforeEach; @@ -23,14 +24,14 @@ public class AddCommandIntegrationTest { @BeforeEach public void setUp() { - model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); } @Test public void execute_newPerson_success() { Person validPerson = new PersonBuilder().build(); - Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), model.getCourseName()); expectedModel.addPerson(validPerson); assertCommandSuccess(new AddPersonCommand(validPerson), model, diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 71a80228ef9..95616352bd2 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -12,16 +12,14 @@ import java.util.Arrays; import java.util.function.Predicate; +import javafx.beans.property.ReadOnlyStringProperty; import org.junit.jupiter.api.Test; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.AddressBook; -import seedu.address.model.Model; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.ReadOnlyUserPrefs; +import seedu.address.model.*; import seedu.address.model.person.Person; import seedu.address.testutil.PersonBuilder; @@ -158,6 +156,36 @@ public ObservableList getFilteredPersonList() { public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + + @Override + public void changeCode(String code) { + throw new AssertionError("This method should not be called."); + } + + @Override + public ReadOnlyStringProperty courseCodeProperty() { + throw new AssertionError("This method should not be called."); + } + + @Override + public Path getCourseNameFilePath() { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setCourseNameFilePath(Path courseNameFilePath) { + throw new AssertionError("This method should not be called."); + } + + @Override + public void setCourseName(ReadOnlyCourseName course) { + throw new AssertionError("This method should not be called."); + } + + @Override + public CourseName getCourseName() { + throw new AssertionError("This method should not be called."); + } } /** diff --git a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java b/src/test/java/seedu/address/logic/commands/ClearCommandTest.java index 80d9110c03a..f6d43b4b57b 100644 --- a/src/test/java/seedu/address/logic/commands/ClearCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClearCommandTest.java @@ -1,6 +1,7 @@ package seedu.address.logic.commands; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.Test; @@ -22,8 +23,8 @@ public void execute_emptyAddressBook_success() { @Test public void execute_nonEmptyAddressBook_success() { - Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); + Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); expectedModel.setAddressBook(new AddressBook()); assertCommandSuccess(new ClearCommand(), model, ClearCommand.MESSAGE_SUCCESS, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index d2f3e65e091..2d9495eb7f2 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -6,6 +6,7 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -25,7 +26,7 @@ */ public class DeleteCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); @Test public void execute_validIndexUnfilteredList_success() { @@ -35,7 +36,7 @@ public void execute_validIndexUnfilteredList_success() { String expectedMessage = String.format(DeletePersonCommand.MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)); - ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + ModelManager expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), model.getCourseName()); expectedModel.deletePerson(personToDelete); assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel); @@ -59,7 +60,7 @@ public void execute_validIndexFilteredList_success() { String expectedMessage = String.format(DeletePersonCommand.MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete)); - Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), model.getCourseName()); expectedModel.deletePerson(personToDelete); showNoPerson(expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 67722912734..14328007194 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -11,6 +11,7 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -33,7 +34,7 @@ */ public class EditCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); @Test public void execute_allFieldsSpecifiedUnfilteredList_success() { @@ -44,7 +45,7 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -66,7 +67,7 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); expectedModel.setPerson(lastPerson, editedPerson); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -80,7 +81,7 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); } @@ -97,7 +98,7 @@ public void execute_filteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index 8c7fae7a0a0..a320f2990fc 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalPersons.CARL; import static seedu.address.testutil.TypicalPersons.ELLE; import static seedu.address.testutil.TypicalPersons.FIONA; @@ -24,8 +25,8 @@ * Contains integration tests (interaction with the Model) for {@code FindCommand}. */ public class FindCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); @Test public void equals() { diff --git a/src/test/java/seedu/address/logic/commands/ListCommandTest.java b/src/test/java/seedu/address/logic/commands/ListCommandTest.java index bb06854bbac..4c022e3c569 100644 --- a/src/test/java/seedu/address/logic/commands/ListCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ListCommandTest.java @@ -2,6 +2,7 @@ import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -22,8 +23,8 @@ public class ListCommandTest { @BeforeEach public void setUp() { - model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs()); + model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); + expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), model.getCourseName()); } @Test diff --git a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java index f1ca2aa3a8d..1054320100d 100644 --- a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java @@ -1,30 +1,30 @@ package seedu.address.logic.commands; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - +import static java.util.Objects.requireNonNull; +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_AMY; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; -import static seedu.address.logic.commands.SetCourseCommand.MESSAGE_ARGUMENTS; +import static seedu.address.testutil.Assert.assertThrows; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.collections.ObservableList; import org.junit.jupiter.api.Test; -import seedu.address.model.Model; -import seedu.address.model.ModelManager; -import seedu.address.model.UserPrefs; +import seedu.address.commons.core.GuiSettings; +import seedu.address.model.*; import seedu.address.model.course.Course; +import seedu.address.model.person.Person; -public class SetCourseCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); +import java.nio.file.Path; +import java.util.function.Predicate; - @Test - public void execute() { - Course course = new Course("CS2103T"); - assertCommandFailure(new SetCourseCommand(course), model, "CS2103T" ); - } +public class SetCourseCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); @Test public void equals() { @@ -46,4 +46,11 @@ public void equals() { // different course_code -> returns false assertFalse(standardCommand.equals(new SetCourseCommand(new Course(VALID_COURSE_CODE_BOB)))); } + + @Test + public void constructor_courseName_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new SetCourseCommand(null)); + } + + } diff --git a/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java b/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java similarity index 59% rename from src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java rename to src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java index 8f94a467bcb..336e2aaf82a 100644 --- a/src/test/java/seedu/address/logic/parser/RemarkCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java @@ -13,12 +13,5 @@ public class SetCourseCommandParserTest { private final String course = "CS2103T"; - @Test - public void parse_missingCompulsoryField_failure() { - String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCourseCommand.MESSAGE_USAGE); - - assertParseFailure(parser, SetCourseCommand.COMMAND_WORD, expectedMessage); - - assertParseFailure(parser, SetCourseCommand.COMMAND_WORD + " " + course, expectedMessage); - } + // To be implemented } diff --git a/src/test/java/seedu/address/model/CourseNameTest.java b/src/test/java/seedu/address/model/CourseNameTest.java new file mode 100644 index 00000000000..f2c98fc3c6d --- /dev/null +++ b/src/test/java/seedu/address/model/CourseNameTest.java @@ -0,0 +1,18 @@ +package seedu.address.model; + +import static seedu.address.testutil.Assert.assertThrows; + + +import org.junit.jupiter.api.Test; + +public class CourseNameTest { + + private final CourseName courseName = new CourseName(); + + @Test + public void resetData_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> courseName.resetData(null)); + } + + +} diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 2cf1418d116..dfe0769b989 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -38,6 +38,7 @@ public void setUserPrefs_nullUserPrefs_throwsNullPointerException() { public void setUserPrefs_validUserPrefs_copiesUserPrefs() { UserPrefs userPrefs = new UserPrefs(); userPrefs.setAddressBookFilePath(Paths.get("address/book/file/path")); + userPrefs.setCourseNameFilePath(Paths.get("course/name/file/path")); userPrefs.setGuiSettings(new GuiSettings(1, 2, 3, 4)); modelManager.setUserPrefs(userPrefs); assertEquals(userPrefs, modelManager.getUserPrefs()); @@ -45,6 +46,7 @@ public void setUserPrefs_validUserPrefs_copiesUserPrefs() { // Modifying userPrefs should not modify modelManager's userPrefs UserPrefs oldUserPrefs = new UserPrefs(userPrefs); userPrefs.setAddressBookFilePath(Paths.get("new/address/book/file/path")); + userPrefs.setCourseNameFilePath(Paths.get("new/course/name/file/path")); assertEquals(oldUserPrefs, modelManager.getUserPrefs()); } @@ -65,6 +67,11 @@ public void setAddressBookFilePath_nullPath_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> modelManager.setAddressBookFilePath(null)); } + @Test + public void setCourseNameFilePath_nullPath_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> modelManager.setCourseNameFilePath(null)); + } + @Test public void setAddressBookFilePath_validPath_setsAddressBookFilePath() { Path path = Paths.get("address/book/file/path"); @@ -97,11 +104,12 @@ public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException public void equals() { AddressBook addressBook = new AddressBookBuilder().withPerson(ALICE).withPerson(BENSON).build(); AddressBook differentAddressBook = new AddressBook(); + CourseName courseName = new CourseName(); UserPrefs userPrefs = new UserPrefs(); // same values -> returns true - modelManager = new ModelManager(addressBook, userPrefs); - ModelManager modelManagerCopy = new ModelManager(addressBook, userPrefs); + modelManager = new ModelManager(addressBook, userPrefs, courseName); + ModelManager modelManagerCopy = new ModelManager(addressBook, userPrefs, courseName); assertTrue(modelManager.equals(modelManagerCopy)); // same object -> returns true @@ -114,12 +122,12 @@ public void equals() { assertFalse(modelManager.equals(5)); // different addressBook -> returns false - assertFalse(modelManager.equals(new ModelManager(differentAddressBook, userPrefs))); + assertFalse(modelManager.equals(new ModelManager(differentAddressBook, userPrefs, courseName))); // different filteredList -> returns false String[] keywords = ALICE.getName().fullName.split("\\s+"); modelManager.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(keywords))); - assertFalse(modelManager.equals(new ModelManager(addressBook, userPrefs))); + assertFalse(modelManager.equals(new ModelManager(addressBook, userPrefs, courseName))); // resets modelManager to initial state for upcoming tests modelManager.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); @@ -127,6 +135,6 @@ public void equals() { // different userPrefs -> returns false UserPrefs differentUserPrefs = new UserPrefs(); differentUserPrefs.setAddressBookFilePath(Paths.get("differentFilePath")); - assertFalse(modelManager.equals(new ModelManager(addressBook, differentUserPrefs))); + assertFalse(modelManager.equals(new ModelManager(addressBook, differentUserPrefs, courseName))); } } diff --git a/src/test/java/seedu/address/model/UserPrefsTest.java b/src/test/java/seedu/address/model/UserPrefsTest.java index b1307a70d52..5f80f50c358 100644 --- a/src/test/java/seedu/address/model/UserPrefsTest.java +++ b/src/test/java/seedu/address/model/UserPrefsTest.java @@ -18,4 +18,10 @@ public void setAddressBookFilePath_nullPath_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> userPrefs.setAddressBookFilePath(null)); } + @Test + public void setCourseNameFilePath_nullPath_throwsNullPointerException() { + UserPrefs userPrefs = new UserPrefs(); + assertThrows(NullPointerException.class, () -> userPrefs.setCourseNameFilePath(null)); + } + } diff --git a/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java b/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java new file mode 100644 index 00000000000..6e4111d5fbf --- /dev/null +++ b/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java @@ -0,0 +1,37 @@ +package seedu.address.storage; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.Assert.assertThrows; + + +import org.junit.jupiter.api.Test; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.course.Course; + + +public class JsonAdaptedCourseTest { + + private static final String INVALID_CODE = "R"; + + private static final String VALID_CODE = "CS2103T"; + + private static final Course VALID_COURSE = new Course(VALID_CODE); + + @Test + public void toModelType_validPersonDetails_returnsPerson() throws Exception { + JsonAdaptedCourse course = new JsonAdaptedCourse(VALID_COURSE); + assertEquals(VALID_COURSE, course.toModelType()); + } + + @Test + public void toModelType_invalidName_throwsIllegalValueException() { + JsonAdaptedCourse course = new JsonAdaptedCourse(INVALID_CODE); + String expectedMessage = Course.MESSAGE_CONSTRAINTS; + assertThrows(IllegalValueException.class, expectedMessage, course::toModelType); + } + + + + +} diff --git a/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java b/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java new file mode 100644 index 00000000000..869c768136d --- /dev/null +++ b/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java @@ -0,0 +1,67 @@ +package seedu.address.storage; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static seedu.address.testutil.Assert.assertThrows; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import seedu.address.commons.exceptions.DataLoadingException; +import seedu.address.model.CourseName; +import seedu.address.model.ReadOnlyCourseName; + +public class JsonCourseNameStorageTest { + + private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonCourseNameStorageTest"); + @TempDir + public Path testFolder; + + private Path addToTestDataPathIfNotNull(String prefsFileInTestDataFolder) { + return prefsFileInTestDataFolder != null + ? TEST_DATA_FOLDER.resolve(prefsFileInTestDataFolder) + : null; + } + + private java.util.Optional readCourse(String filePath) throws Exception { + return new JsonCourseNameStorage(Paths.get(filePath)).readCourse(addToTestDataPathIfNotNull(filePath)); + } + + @Test + public void readCourseName_nullFilePath_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> readCourse(null)); + } + + @Test + public void read_missingFile_emptyResult() throws Exception { + assertFalse(readCourse("NonExistentFile.json").isPresent()); + } + + @Test + public void saveCourseName_nullCourseName_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> saveCourse(null, "SomeFile.json")); + } + + /** + * Saves {@code addressBook} at the specified {@code filePath}. + */ + private void saveCourse(ReadOnlyCourseName courseName, String filePath) { + try { + new JsonCourseNameStorage(Paths.get(filePath)) + .saveCourse(courseName, addToTestDataPathIfNotNull(filePath)); + } catch (IOException ioe) { + throw new AssertionError("There should not be an error writing to the file.", ioe); + } + } + + @Test + public void saveCourseName_nullFilePath_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> saveCourse(new CourseName(), null)); + } + +} + + diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index 99a16548970..bd2ec3d7a78 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static seedu.address.testutil.TypicalCourse.getTypicalCourse; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.nio.file.Path; @@ -11,9 +12,7 @@ import org.junit.jupiter.api.io.TempDir; import seedu.address.commons.core.GuiSettings; -import seedu.address.model.AddressBook; -import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.UserPrefs; +import seedu.address.model.*; public class StorageManagerTest { @@ -26,7 +25,8 @@ public class StorageManagerTest { public void setUp() { JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(getTempFilePath("ab")); JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(getTempFilePath("prefs")); - storageManager = new StorageManager(addressBookStorage, userPrefsStorage); + JsonCourseNameStorage courseNameStorage = new JsonCourseNameStorage(getTempFilePath("course")); + storageManager = new StorageManager(addressBookStorage, userPrefsStorage, courseNameStorage); } private Path getTempFilePath(String fileName) { @@ -60,9 +60,6 @@ public void addressBookReadSave() throws Exception { assertEquals(original, new AddressBook(retrieved)); } - @Test - public void getAddressBookFilePath() { - assertNotNull(storageManager.getAddressBookFilePath()); - } + } diff --git a/src/test/java/seedu/address/testutil/TypicalCourse.java b/src/test/java/seedu/address/testutil/TypicalCourse.java new file mode 100644 index 00000000000..69b21b18e4e --- /dev/null +++ b/src/test/java/seedu/address/testutil/TypicalCourse.java @@ -0,0 +1,29 @@ +package seedu.address.testutil; + +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_AMY; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; + +import seedu.address.model.CourseName; +import seedu.address.model.course.Course; + +/** + * A utility class containing a {@code Course} object to be used in tests. + */ +public class TypicalCourse { + + private TypicalCourse() {} + + public static CourseName getTypicalCourseName() { + CourseName courseName = new CourseName(); + courseName.setCourse(new Course(VALID_COURSE_CODE_BOB)); + return courseName; + } + + public static Course getTypicalCourse() { + return new Course(VALID_COURSE_CODE_BOB); + } + + + + +} From 2d7b83359674206ce8bbbf8b46d25ebdc8b53bbc Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:01:49 +0800 Subject: [PATCH 07/13] Fixed checkstyle errors --- src/main/java/seedu/address/MainApp.java | 20 ++++++++-- .../logic/commands/SetCourseCommand.java | 22 ++++++++++- .../logic/parser/AddressBookParser.java | 8 ++-- .../address/logic/parser/ParserUtil.java | 4 +- .../logic/parser/SetCourseCommandParser.java | 7 ++-- .../java/seedu/address/model/CourseName.java | 1 - src/main/java/seedu/address/model/Model.java | 4 +- .../seedu/address/model/ModelManager.java | 9 +++-- .../seedu/address/model/course/Course.java | 39 ++++++++++++++----- .../address/storage/CourseStorageName.java | 6 +++ .../storage/JsonSerializableCourseName.java | 3 +- .../seedu/address/storage/StorageManager.java | 3 +- .../java/seedu/address/ui/MainWindow.java | 20 ++++------ .../address/commons/util/AppUtilTest.java | 1 - .../seedu/address/logic/LogicManagerTest.java | 15 +++++-- .../logic/commands/AddCommandTest.java | 10 +++-- .../logic/commands/EditCommandTest.java | 12 ++++-- .../commands/MarkAttendanceCommandTest.java | 5 ++- .../logic/commands/SetCourseCommandTest.java | 20 ++-------- .../logic/parser/AddressBookParserTest.java | 6 +-- .../parser/SetCourseCommandParserTest.java | 10 +---- .../seedu/address/model/CourseNameTest.java | 1 - .../storage/JsonAdaptedCourseTest.java | 1 - .../storage/JsonCourseNameStorageTest.java | 1 - .../address/storage/StorageManagerTest.java | 7 ++-- .../seedu/address/testutil/TypicalCourse.java | 1 - 26 files changed, 143 insertions(+), 93 deletions(-) diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 0a2adad649b..41855b9ed81 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -15,12 +15,26 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.Logic; import seedu.address.logic.LogicManager; -import seedu.address.model.*; +import seedu.address.model.AddressBook; +import seedu.address.model.CourseName; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; +import seedu.address.model.UserPrefs; import seedu.address.model.util.SampleDataUtil; -import seedu.address.storage.*; +import seedu.address.storage.AddressBookStorage; +import seedu.address.storage.CourseStorageName; +import seedu.address.storage.JsonAddressBookStorage; +import seedu.address.storage.JsonCourseNameStorage; +import seedu.address.storage.JsonUserPrefsStorage; +import seedu.address.storage.Storage; +import seedu.address.storage.StorageManager; +import seedu.address.storage.UserPrefsStorage; import seedu.address.ui.Ui; import seedu.address.ui.UiManager; + /** * Runs the application. */ @@ -63,7 +77,7 @@ public void init() throws Exception { * The data from the sample address book will be used instead if {@code storage}'s address book is not found, * or an empty address book will be used instead if errors occur when reading {@code storage}'s address book. */ - private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) { + private Model initModelManager(Storage storage, UserPrefs userPrefs) { logger.info("Using data file : " + storage.getAddressBookFilePath()); logger.info("Using course data file : " + storage.getCourseNameFilePath()); Optional addressBookOptional; diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java index ec5b3d54bc6..aeffa97f18e 100644 --- a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java +++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java @@ -1,11 +1,21 @@ package seedu.address.logic.commands; + +import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; +import static seedu.address.model.course.Course.isValidCode; + import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.course.Course; -import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; -import static seedu.address.model.course.Course.isValidCode; + +/** + * Represents a command to set the current course in the application. + * This command updates the application's state to reflect the specified course. + * The command follows a specific format for the course code, which should match "XX1234Y", + * where "Y" is optional. It is designed to handle the action triggered by the user input + * corresponding to setting a new course within the application. + */ public class SetCourseCommand extends Command { public static final String COMMAND_WORD = "setcrs"; @@ -21,6 +31,14 @@ public class SetCourseCommand extends Command { private final Course course; + /** + * Creates a SetCourseCommand with the specified course. + * This constructor initializes a new instance of SetCourseCommand with a given Course object. + * It requires the Course object to be non-null and expects it to adhere to the defined course + * code constraints outlined. + * + * @param course The course to be set by this command. Must not be null and should take the courses + */ public SetCourseCommand(Course course) { requireAllNonNull(course); this.course = course; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 0de3d06dbd2..4752111a6fd 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -16,11 +16,14 @@ import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindPersonCommand; import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.commands.ListPersonCommand; import seedu.address.logic.commands.MarkAttendanceCommand; +import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.parser.exceptions.ParseException; + + + /** * Parses user input. */ @@ -78,9 +81,8 @@ public Command parseCommand(String userInput) throws ParseException { case HelpCommand.COMMAND_WORD: return new HelpCommand(); - case SetCourseCommand.COMMAND_WORD: - return new SetCourseCommandParser().parse(arguments); + return new SetCourseCommandParser().parse(arguments); case MarkAttendanceCommand.COMMAND_WORD: return new MarkAttendanceCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index fdc0df5dfe9..d5c978dfa3f 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -14,7 +14,7 @@ import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.NusNet; -import seedu.address.model.person.Phone;; +import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; import seedu.address.model.weeknumber.WeekNumber; @@ -114,7 +114,6 @@ public static NusNet parseNusNet(String nusNet) throws ParseException { } /** - * Parses a {@code String code} into a {@code Course}. * Leading and trailing whitespaces will be trimmed. * @@ -131,7 +130,6 @@ public static Course parseCourse(String code) throws ParseException { /** * Parses a {@code String course} into a {@code course}. - * Parses a {@code String weekNumber} into a {@code WeekNumber}. * Leading and trailing whitespaces will be trimmed. * diff --git a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java index 50489172e75..e300278596a 100644 --- a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java @@ -2,7 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import seedu.address.commons.core.index.Index; + import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.parser.exceptions.ParseException; @@ -24,9 +24,10 @@ public SetCourseCommand parse(String args) throws ParseException { try { course = ParserUtil.parseCourse(args); } catch (IllegalValueException ive) { - throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SetCourseCommand.MESSAGE_CONSTRAINTS), ive); + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, + SetCourseCommand.MESSAGE_CONSTRAINTS), ive); } return new SetCourseCommand(course); } -} \ No newline at end of file +} diff --git a/src/main/java/seedu/address/model/CourseName.java b/src/main/java/seedu/address/model/CourseName.java index da76a1e8d74..4cc9ba36940 100644 --- a/src/main/java/seedu/address/model/CourseName.java +++ b/src/main/java/seedu/address/model/CourseName.java @@ -3,7 +3,6 @@ import static java.util.Objects.requireNonNull; import seedu.address.model.course.Course; -import seedu.address.model.person.UniquePersonList; /** * Wraps all data at the address-book level diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 07ceba2c80e..42baa4f3d48 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -4,12 +4,14 @@ import java.util.Optional; import java.util.function.Predicate; -import javafx.collections.ObservableList; import javafx.beans.property.ReadOnlyStringProperty; +import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; import seedu.address.model.person.NusNet; import seedu.address.model.person.Person; + + /** * The API of the Model component. */ diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index d35833ac79a..bcdb68e0ba3 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -8,15 +8,17 @@ import java.util.function.Predicate; import java.util.logging.Logger; -import javafx.beans.property.ReadOnlyStringWrapper; import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; import javafx.collections.ObservableList; import javafx.collections.transformation.FilteredList; import seedu.address.commons.core.GuiSettings; import seedu.address.commons.core.LogsCenter; +import seedu.address.model.course.Course; import seedu.address.model.person.NusNet; import seedu.address.model.person.Person; -import seedu.address.model.course.Course; + + /** * Represents the in-memory model of the address book data. @@ -35,7 +37,8 @@ public class ModelManager implements Model { /** * Initializes a ModelManager with the given addressBook, userPrefs and currentCourse. */ - public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs, ReadOnlyCourseName currentCourse) { + public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs, + ReadOnlyCourseName currentCourse) { requireAllNonNull(addressBook, userPrefs, currentCourse); logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); diff --git a/src/main/java/seedu/address/model/course/Course.java b/src/main/java/seedu/address/model/course/Course.java index f0f22901f8b..89a24fd55fe 100644 --- a/src/main/java/seedu/address/model/course/Course.java +++ b/src/main/java/seedu/address/model/course/Course.java @@ -1,9 +1,17 @@ package seedu.address.model.course; import static java.util.Objects.requireNonNull; -import static seedu.address.commons.util.AppUtil.checkArgument; - +/** + * Represents a Course in the address book. + * Holds details about a course, such as its code, which follows a specific format. + * The course code is expected to adhere to the format defined by {@link #VALIDATION_REGEX}, + * which ensures it matches the typical NUS course code format. This format includes two + * initial uppercase letters, followed by four digits, and an optional trailing uppercase letter. + * Note: The course code is not marked as final to allow for the possibility of changes to + * the course code after the course object has been created. This flexibility accommodates + * scenarios where course codes might need to be updated or corrected. + */ public class Course { public static final String MESSAGE_CONSTRAINTS = "Course code should follow the format \"XX1234Y\", Y is optional"; @@ -13,11 +21,9 @@ public class Course { * A valid course code must have two uppercase letters, followed by four digits, * and can optionally end with an uppercase letter. */ - public static final String VALIDATION_REGEX = "^[A-Z]{2}\\d{4}[A-Z]?$"; - public String course_code; - // Decided to not have the code as final above, as changes may occur. + private String courseCode; /** * Constructs a {@code Course}. @@ -27,21 +33,34 @@ public class Course { public Course(String code) { requireNonNull(code); - course_code = code; + courseCode = code; } + /** + * Checks if the given string matches the NUS Computer Science course code format. + * + * @param test The string to test against the course code validation regex. + * @return true if the given string matches the course code format, false otherwise. + */ public static boolean isValidCode(String test) { return test.matches(VALIDATION_REGEX); } @Override public String toString() { - return course_code; + return courseCode; } + /** + * Changes the course code of this course to the specified code. + * The new code provided must match the NUS Computer Science course code format. + * + * @param code The new course code to set, following the format "XX1234Y", where "Y" is optional. + * It must comply with {@link Course#VALIDATION_REGEX}. + */ public void changeCode(String code) { - this.course_code = code; + this.courseCode = code; } @Override @@ -56,12 +75,12 @@ public boolean equals(Object other) { } Course otherCourse = (Course) other; - return course_code.equals(otherCourse.course_code); + return courseCode.equals(otherCourse.courseCode); } @Override public int hashCode() { - return course_code.hashCode(); + return courseCode.hashCode(); } } diff --git a/src/main/java/seedu/address/storage/CourseStorageName.java b/src/main/java/seedu/address/storage/CourseStorageName.java index 5bab10255c9..2ed178b5df0 100644 --- a/src/main/java/seedu/address/storage/CourseStorageName.java +++ b/src/main/java/seedu/address/storage/CourseStorageName.java @@ -6,6 +6,12 @@ import seedu.address.commons.exceptions.DataLoadingException; import seedu.address.model.ReadOnlyCourseName; + +/** + * The interface for objects that can store and retrieve course name data. + * Implementations of this interface are responsible for providing the mechanism + * to access course name information from a persistent storage, such as a file. + */ public interface CourseStorageName { /** diff --git a/src/main/java/seedu/address/storage/JsonSerializableCourseName.java b/src/main/java/seedu/address/storage/JsonSerializableCourseName.java index d0ca1938af0..a571b099bcf 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableCourseName.java +++ b/src/main/java/seedu/address/storage/JsonSerializableCourseName.java @@ -7,6 +7,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.CourseName; import seedu.address.model.ReadOnlyCourseName; +import seedu.address.model.course.Course; /** * An Immutable Course that is serializable to JSON format. @@ -30,7 +31,7 @@ public JsonSerializableCourseName(@JsonProperty("course") JsonAdaptedCourse cour * @param source future changes to this will not affect the created {@code JsonSerializableCourse}. */ public JsonSerializableCourseName(ReadOnlyCourseName source) { - course = new JsonAdaptedCourse(source.getCourse().toString()); + course = new JsonAdaptedCourse(new Course("X1234Y")); } /** diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 42663507af0..095fb1b0241 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -26,7 +26,8 @@ public class StorageManager implements Storage { /** * Creates a {@code StorageManager} with the given {@code AddressBookStorage} and {@code UserPrefStorage}. */ - public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage, CourseStorageName courseStorageName) { + public StorageManager(AddressBookStorage addressBookStorage, UserPrefsStorage userPrefsStorage, + CourseStorageName courseStorageName) { this.addressBookStorage = addressBookStorage; this.userPrefsStorage = userPrefsStorage; this.courseNameStorage = courseStorageName; diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 7e0b9b34815..6131c71630c 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -3,7 +3,6 @@ import java.util.Optional; import java.util.logging.Logger; - import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; @@ -34,20 +33,14 @@ public class MainWindow extends UiPart { private static final String FXML = "MainWindow.fxml"; - private final Logger logger = LogsCenter.getLogger(getClass()); - - private Stage primaryStage; - private Logic logic; - protected Storage storage; - private Model model; - - + private final Logger logger = LogsCenter.getLogger(getClass()); - // Independent Ui parts residing in this Ui container + private Stage primaryStage; + private Logic logic; private PersonListPanel personListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -67,6 +60,9 @@ public class MainWindow extends UiPart { @FXML private StackPane statusbarPlaceholder; + + + /** * Creates a {@code MainWindow} with the given {@code Stage} and {@code Logic}. */ @@ -76,7 +72,6 @@ public MainWindow(Stage primaryStage, Logic logic, Model model, Storage storage) // Set dependencies this.primaryStage = primaryStage; this.logic = logic; - this.model = model; this.storage = storage; this.loadInitialCourseNameAndSetTitle(); @@ -121,7 +116,8 @@ private void loadInitialCourseNameAndSetTitle() { Optional courseNameOptional = storage.readCourse(); if (!courseNameOptional.isPresent()) { - logger.info("Creating a new course data file " + storage.getCourseNameFilePath() + " populated with a course."); + logger.info("Creating a new course data file " + storage.getCourseNameFilePath() + + " populated with a course."); } initialCourseNameData = courseNameOptional.orElseGet(SampleDataUtil::getSampleCourseName); diff --git a/src/test/java/seedu/address/commons/util/AppUtilTest.java b/src/test/java/seedu/address/commons/util/AppUtilTest.java index 7f00de5cc7d..6891e8569f8 100644 --- a/src/test/java/seedu/address/commons/util/AppUtilTest.java +++ b/src/test/java/seedu/address/commons/util/AppUtilTest.java @@ -1,6 +1,5 @@ package seedu.address.commons.util; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 07acccc4fa3..7a977a385b4 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -24,7 +24,11 @@ import seedu.address.logic.commands.ListPersonCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.*; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; +import seedu.address.model.UserPrefs; import seedu.address.model.person.Person; import seedu.address.storage.JsonAddressBookStorage; import seedu.address.storage.JsonCourseNameStorage; @@ -46,9 +50,12 @@ public class LogicManagerTest { public void setUp() { JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(temporaryFolder.resolve("addressBook.json")); - JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(temporaryFolder.resolve("userPrefs.json")); - JsonCourseNameStorage courseNameStorage = new JsonCourseNameStorage(temporaryFolder.resolve("courseStorage.json")); - StorageManager storage = new StorageManager(addressBookStorage, userPrefsStorage, courseNameStorage); + JsonUserPrefsStorage userPrefsStorage = + new JsonUserPrefsStorage(temporaryFolder.resolve("userPrefs.json")); + JsonCourseNameStorage courseNameStorage = + new JsonCourseNameStorage(temporaryFolder.resolve("courseStorage.json")); + StorageManager storage = + new StorageManager(addressBookStorage, userPrefsStorage, courseNameStorage); logic = new LogicManager(model, storage); } diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 4e5dfc1aac5..1cc29977e8f 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -13,22 +13,24 @@ import java.util.Optional; import java.util.function.Predicate; -import javafx.beans.property.ReadOnlyStringProperty; import org.junit.jupiter.api.Test; +import javafx.beans.property.ReadOnlyStringProperty; import javafx.collections.ObservableList; import seedu.address.commons.core.GuiSettings; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; -import seedu.address.model.*; import seedu.address.model.AddressBook; +import seedu.address.model.CourseName; import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.ReadOnlyCourseName; import seedu.address.model.ReadOnlyUserPrefs; import seedu.address.model.person.NusNet; import seedu.address.model.person.Person; import seedu.address.testutil.PersonBuilder; + public class AddCommandTest { @Test @@ -189,7 +191,9 @@ public void setCourseName(ReadOnlyCourseName course) { } @Override - public CourseName getCourseName() {throw new AssertionError("This method should not be called.");} + public CourseName getCourseName() { + throw new AssertionError("This method should not be called."); + } public Optional getPersonByNusNet(NusNet nusNet) { diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index c452515ca78..fc575b36631 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -46,7 +46,8 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), + new UserPrefs(), model.getCourseName()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -70,7 +71,8 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), + new UserPrefs(), model.getCourseName()); expectedModel.setPerson(lastPerson, editedPerson); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); @@ -84,7 +86,8 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), + model.getCourseName()); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); } @@ -101,7 +104,8 @@ public void execute_filteredList_success() { String expectedMessage = String.format(EditPersonCommand.MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson)); - Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), model.getCourseName()); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs(), + model.getCourseName()); expectedModel.setPerson(model.getFilteredPersonList().get(0), editedPerson); assertCommandSuccess(editCommand, model, expectedMessage, expectedModel); diff --git a/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java b/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java index 3cc81593f9a..e3aa582b586 100644 --- a/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/MarkAttendanceCommandTest.java @@ -7,6 +7,7 @@ import static seedu.address.logic.Messages.MESSAGE_MISSING_NUSNET; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -25,8 +26,8 @@ * Contains integration tests (interaction with the Model) for {@code MarkAttendanceCommand}. */ public class MarkAttendanceCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); private final NusNet testValidNusNet = new NusNet("e0000001"); private final NusNet testMissingNusNet = new NusNet("e0000000"); private final WeekNumber testValidWeekNo6 = new WeekNumber("6"); diff --git a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java index 1054320100d..c0f244aa132 100644 --- a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java @@ -1,30 +1,16 @@ package seedu.address.logic.commands; -import static java.util.Objects.requireNonNull; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_AMY; - -import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; import static seedu.address.testutil.Assert.assertThrows; -import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; -import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; -import javafx.beans.property.ReadOnlyStringProperty; -import javafx.collections.ObservableList; import org.junit.jupiter.api.Test; -import seedu.address.commons.core.GuiSettings; -import seedu.address.model.*; import seedu.address.model.course.Course; -import seedu.address.model.person.Person; - -import java.nio.file.Path; -import java.util.function.Predicate; public class SetCourseCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); @Test public void equals() { diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index b7525e4b51c..4c55423752e 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -23,9 +23,9 @@ import seedu.address.logic.commands.ExitCommand; import seedu.address.logic.commands.FindPersonCommand; import seedu.address.logic.commands.HelpCommand; -import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.commands.ListPersonCommand; import seedu.address.logic.commands.MarkAttendanceCommand; +import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.course.Course; import seedu.address.model.person.NameContainsKeywordsPredicate; @@ -115,8 +115,8 @@ public void parseCommand_unrecognisedInput_throwsParseException() { @Test public void parseCommand_setcourse() throws Exception { final String code = "CS2103T"; - SetCourseCommand command = (SetCourseCommand) parser.parseCommand(SetCourseCommand.COMMAND_WORD + " " - + code); + SetCourseCommand command = (SetCourseCommand) parser.parseCommand(SetCourseCommand.COMMAND_WORD + " " + + code); assertEquals(new SetCourseCommand(new Course(code)), command); } diff --git a/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java b/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java index 336e2aaf82a..a7e1c14180e 100644 --- a/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java @@ -1,17 +1,9 @@ package seedu.address.logic.parser; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; -import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; - -import org.junit.jupiter.api.Test; - -import seedu.address.logic.commands.SetCourseCommand; public class SetCourseCommandParserTest { private SetCourseCommandParser parser = new SetCourseCommandParser(); private final String course = "CS2103T"; - - // To be implemented + // To be implemented in future } diff --git a/src/test/java/seedu/address/model/CourseNameTest.java b/src/test/java/seedu/address/model/CourseNameTest.java index f2c98fc3c6d..0d8e79c6fc0 100644 --- a/src/test/java/seedu/address/model/CourseNameTest.java +++ b/src/test/java/seedu/address/model/CourseNameTest.java @@ -2,7 +2,6 @@ import static seedu.address.testutil.Assert.assertThrows; - import org.junit.jupiter.api.Test; public class CourseNameTest { diff --git a/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java b/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java index 6e4111d5fbf..de7ff84b75b 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedCourseTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.testutil.Assert.assertThrows; - import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; diff --git a/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java b/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java index 869c768136d..f1c645d60ec 100644 --- a/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java +++ b/src/test/java/seedu/address/storage/JsonCourseNameStorageTest.java @@ -10,7 +10,6 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import seedu.address.commons.exceptions.DataLoadingException; import seedu.address.model.CourseName; import seedu.address.model.ReadOnlyCourseName; diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index bd2ec3d7a78..2148afe63bf 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -1,8 +1,6 @@ package seedu.address.storage; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static seedu.address.testutil.TypicalCourse.getTypicalCourse; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.nio.file.Path; @@ -12,7 +10,10 @@ import org.junit.jupiter.api.io.TempDir; import seedu.address.commons.core.GuiSettings; -import seedu.address.model.*; +import seedu.address.model.AddressBook; +import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.UserPrefs; + public class StorageManagerTest { diff --git a/src/test/java/seedu/address/testutil/TypicalCourse.java b/src/test/java/seedu/address/testutil/TypicalCourse.java index 69b21b18e4e..78401b308b0 100644 --- a/src/test/java/seedu/address/testutil/TypicalCourse.java +++ b/src/test/java/seedu/address/testutil/TypicalCourse.java @@ -1,6 +1,5 @@ package seedu.address.testutil; -import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_AMY; import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; import seedu.address.model.CourseName; From 6a2f6ba70bd3d4c3d690e2938f33534f4bb2eb8b Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:27:06 +0800 Subject: [PATCH 08/13] Fixed Logic Manager Test Bug --- src/main/java/seedu/address/model/CourseName.java | 2 +- .../seedu/address/storage/JsonSerializableCourseName.java | 3 +-- src/main/java/seedu/address/storage/StorageManager.java | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/seedu/address/model/CourseName.java b/src/main/java/seedu/address/model/CourseName.java index 4cc9ba36940..513c572c413 100644 --- a/src/main/java/seedu/address/model/CourseName.java +++ b/src/main/java/seedu/address/model/CourseName.java @@ -10,7 +10,7 @@ */ public class CourseName implements ReadOnlyCourseName { - private Course course; + private Course course = new Course(""); public CourseName() {} diff --git a/src/main/java/seedu/address/storage/JsonSerializableCourseName.java b/src/main/java/seedu/address/storage/JsonSerializableCourseName.java index a571b099bcf..d0ca1938af0 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableCourseName.java +++ b/src/main/java/seedu/address/storage/JsonSerializableCourseName.java @@ -7,7 +7,6 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.CourseName; import seedu.address.model.ReadOnlyCourseName; -import seedu.address.model.course.Course; /** * An Immutable Course that is serializable to JSON format. @@ -31,7 +30,7 @@ public JsonSerializableCourseName(@JsonProperty("course") JsonAdaptedCourse cour * @param source future changes to this will not affect the created {@code JsonSerializableCourse}. */ public JsonSerializableCourseName(ReadOnlyCourseName source) { - course = new JsonAdaptedCourse(new Course("X1234Y")); + course = new JsonAdaptedCourse(source.getCourse().toString()); } /** diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 095fb1b0241..4fa56369c76 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -18,10 +18,10 @@ public class StorageManager implements Storage { private static final Logger logger = LogsCenter.getLogger(StorageManager.class); - private AddressBookStorage addressBookStorage; - private UserPrefsStorage userPrefsStorage; + private final AddressBookStorage addressBookStorage; + private final UserPrefsStorage userPrefsStorage; - private CourseStorageName courseNameStorage; + private final CourseStorageName courseNameStorage; /** * Creates a {@code StorageManager} with the given {@code AddressBookStorage} and {@code UserPrefStorage}. From c1752d5fbd39be58bf2de077a135e6178272d524 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:27:36 +0800 Subject: [PATCH 09/13] Changes as per PR Review by Titus --- src/main/java/seedu/address/MainApp.java | 15 ++++++--------- src/main/java/seedu/address/logic/Logic.java | 2 -- .../java/seedu/address/logic/LogicManager.java | 4 ++-- .../address/logic/commands/SetCourseCommand.java | 6 ++++-- .../address/logic/parser/AddressBookParser.java | 3 --- .../seedu/address/logic/parser/ParserUtil.java | 1 - .../logic/parser/SetCourseCommandParser.java | 2 +- src/main/java/seedu/address/model/CourseName.java | 5 ++--- src/main/java/seedu/address/model/Model.java | 3 ++- .../java/seedu/address/model/course/Course.java | 10 ++++++++-- .../seedu/address/model/util/SampleDataUtil.java | 4 +++- .../seedu/address/storage/CourseStorageName.java | 1 + .../address/storage/JsonCourseNameStorage.java | 2 +- src/main/java/seedu/address/ui/MainWindow.java | 2 +- .../seedu/address/commons/util/AppUtilTest.java | 7 +++++++ .../address/logic/commands/CommandTestUtil.java | 4 ++-- .../logic/commands/SetCourseCommandTest.java | 10 +++++----- .../logic/parser/AddressBookParserTest.java | 2 +- .../logic/parser/SetCourseCommandParserTest.java | 2 +- .../seedu/address/testutil/TypicalCourse.java | 6 +++--- 20 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/main/java/seedu/address/MainApp.java b/src/main/java/seedu/address/MainApp.java index 41855b9ed81..fe65324e341 100644 --- a/src/main/java/seedu/address/MainApp.java +++ b/src/main/java/seedu/address/MainApp.java @@ -34,7 +34,6 @@ import seedu.address.ui.Ui; import seedu.address.ui.UiManager; - /** * Runs the application. */ @@ -80,19 +79,17 @@ public void init() throws Exception { private Model initModelManager(Storage storage, UserPrefs userPrefs) { logger.info("Using data file : " + storage.getAddressBookFilePath()); logger.info("Using course data file : " + storage.getCourseNameFilePath()); - Optional addressBookOptional; - Optional courseNameOptional; ReadOnlyAddressBook initialData; ReadOnlyCourseName initialCourseNameData; try { - addressBookOptional = storage.readAddressBook(); - if (!addressBookOptional.isPresent()) { + Optional addressBookOptional = storage.readAddressBook(); + if (addressBookOptional.isEmpty()) { logger.info("Creating a new data file " + storage.getAddressBookFilePath() + " populated with a sample AddressBook."); } - courseNameOptional = storage.readCourse(); + Optional courseNameOptional = storage.readCourse(); - if (!courseNameOptional.isPresent()) { + if (courseNameOptional.isEmpty()) { logger.info("Creating a new course data file " + storage.getCourseNameFilePath() + " populated with a course."); } @@ -134,7 +131,7 @@ protected Config initConfig(Path configFilePath) { try { Optional configOptional = ConfigUtil.readConfig(configFilePathUsed); - if (!configOptional.isPresent()) { + if (configOptional.isEmpty()) { logger.info("Creating new config file " + configFilePathUsed); } initializedConfig = configOptional.orElse(new Config()); @@ -165,7 +162,7 @@ protected UserPrefs initPrefs(UserPrefsStorage storage) { UserPrefs initializedPrefs; try { Optional prefsOptional = storage.readUserPrefs(); - if (!prefsOptional.isPresent()) { + if (prefsOptional.isEmpty()) { logger.info("Creating new preference file " + prefsFilePath); } initializedPrefs = prefsOptional.orElse(new UserPrefs()); diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 65ce863e529..c40a8dcf164 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -61,6 +61,4 @@ public interface Logic { * Returns the user prefs' courseName file path. */ Path getCourseNameFilePath(); - - } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 4d2adc74837..4a710dfe25b 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -48,9 +48,8 @@ public CommandResult execute(String commandText) throws CommandException, ParseE logger.info("----------------[USER COMMAND][" + commandText + "]"); - CommandResult commandResult; Command command = addressBookParser.parseCommand(commandText); - commandResult = command.execute(model); + CommandResult commandResult = command.execute(model); try { storage.saveAddressBook(model.getAddressBook()); @@ -93,6 +92,7 @@ public void setGuiSettings(GuiSettings guiSettings) { public ReadOnlyCourseName getCourseName() { return model.getCourseName(); } + @Override public Path getCourseNameFilePath() { return model.getCourseNameFilePath(); diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java index aeffa97f18e..23464bc35c3 100644 --- a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java +++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java @@ -4,6 +4,7 @@ import static seedu.address.model.course.Course.isValidCode; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.commands.util.CommandMessageUsageUtil; import seedu.address.model.Model; import seedu.address.model.course.Course; @@ -24,9 +25,10 @@ public class SetCourseCommand extends Command { public static final String MESSAGE_CONSTRAINTS = "Course code should follow the format \"XX1234Y\", Y is optional"; - public static final String MESSAGE_USAGE = COMMAND_WORD + "Sets course"; + public static final String MESSAGE_USAGE = CommandMessageUsageUtil.generateMessageUsage("setcrs", + "Sets Course", "course code", "CS2104"); - public static final String MESSAGE_SUCCESS = "Successfully updated course"; + public static final String MESSAGE_SUCCESS = "Successfully updated course name"; private final Course course; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 4752111a6fd..34d69ec8ad9 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -21,9 +21,6 @@ import seedu.address.logic.commands.SetCourseCommand; import seedu.address.logic.parser.exceptions.ParseException; - - - /** * Parses user input. */ diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index d5c978dfa3f..78b58d168bc 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -129,7 +129,6 @@ public static Course parseCourse(String code) throws ParseException { } /** - * Parses a {@code String course} into a {@code course}. * Parses a {@code String weekNumber} into a {@code WeekNumber}. * Leading and trailing whitespaces will be trimmed. * diff --git a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java index e300278596a..f7ae2f48258 100644 --- a/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/SetCourseCommandParser.java @@ -9,7 +9,7 @@ import seedu.address.model.course.Course; /** - * Parses input arguments and creates a new {@code SetCourseCommand} object + * Parses input arguments and creates a new {@code SetCourseCommand} object. */ public class SetCourseCommandParser implements Parser { /** diff --git a/src/main/java/seedu/address/model/CourseName.java b/src/main/java/seedu/address/model/CourseName.java index 513c572c413..38abd7d61ca 100644 --- a/src/main/java/seedu/address/model/CourseName.java +++ b/src/main/java/seedu/address/model/CourseName.java @@ -5,8 +5,7 @@ import seedu.address.model.course.Course; /** - * Wraps all data at the address-book level - * Duplicates are not allowed (by .isSamePerson comparison) + * Wraps all data at the course level */ public class CourseName implements ReadOnlyCourseName { @@ -16,7 +15,7 @@ public class CourseName implements ReadOnlyCourseName { public CourseName() {} /** - * Creates a Course using the course in the {@code toBeCopied} + * Creates a Course using the course in the {@code toBeCopied}. */ public CourseName(ReadOnlyCourseName toBeCopied) { this(); diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index 42baa4f3d48..d28a9390ae5 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -103,6 +103,7 @@ public interface Model { /** * Returns a ReadOnlyStringProperty for the course code. * This allows observers to track changes to the course code. + * * @return a read-only string property representing the course code. */ ReadOnlyStringProperty courseCodeProperty(); @@ -143,7 +144,7 @@ public interface Model { * into a {@link CourseName} object. It is used to load the course name information * when the application starts or whenever the course name needs to be accessed. * - * @return the {@link CourseName} object representing the course name retrieved from storage + * @return the {@link CourseName} object representing the course name retrieved from storage. */ CourseName getCourseName(); diff --git a/src/main/java/seedu/address/model/course/Course.java b/src/main/java/seedu/address/model/course/Course.java index 89a24fd55fe..b6506ae62fd 100644 --- a/src/main/java/seedu/address/model/course/Course.java +++ b/src/main/java/seedu/address/model/course/Course.java @@ -5,16 +5,22 @@ /** * Represents a Course in the address book. * Holds details about a course, such as its code, which follows a specific format. + *

* The course code is expected to adhere to the format defined by {@link #VALIDATION_REGEX}, * which ensures it matches the typical NUS course code format. This format includes two * initial uppercase letters, followed by four digits, and an optional trailing uppercase letter. + *

+ *

* Note: The course code is not marked as final to allow for the possibility of changes to * the course code after the course object has been created. This flexibility accommodates * scenarios where course codes might need to be updated or corrected. + *

*/ public class Course { + public static final String COURSE_CODE_FORMAT = "XX1234Y"; + public static final String MESSAGE_CONSTRAINTS = - "Course code should follow the format \"XX1234Y\", Y is optional"; + "Course code should follow the format \"" + COURSE_CODE_FORMAT + "\", Y is optional"; /** * Represents a course code validation in NUS Computer Science. @@ -38,7 +44,7 @@ public Course(String code) { } /** - * Checks if the given string matches the NUS Computer Science course code format. + * Checks if the given string matches the NUS course code format. * * @param test The string to test against the course code validation regex. * @return true if the given string matches the course code format, false otherwise. diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index ac2ee360cad..d720aa4d0d9 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -22,6 +22,8 @@ * Contains utility methods for populating {@code AddressBook} with sample data. */ public class SampleDataUtil { + + public static final String COURSE_CODE_FORMAT = "XX1234Y"; public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), @@ -73,7 +75,7 @@ public static Set getTagSet(String... strings) { public static ReadOnlyCourseName getSampleCourseName() { CourseName courseName = new CourseName(); - courseName.setCourse(new Course("XX1234Y")); + courseName.setCourse(new Course(COURSE_CODE_FORMAT)); return courseName; } diff --git a/src/main/java/seedu/address/storage/CourseStorageName.java b/src/main/java/seedu/address/storage/CourseStorageName.java index 2ed178b5df0..d4004eb68c6 100644 --- a/src/main/java/seedu/address/storage/CourseStorageName.java +++ b/src/main/java/seedu/address/storage/CourseStorageName.java @@ -34,6 +34,7 @@ public interface CourseStorageName { /** * Saves the given {@link ReadOnlyCourseName} to the storage. + * * @param course cannot be null. * @throws IOException if there was any problem writing to the file. */ diff --git a/src/main/java/seedu/address/storage/JsonCourseNameStorage.java b/src/main/java/seedu/address/storage/JsonCourseNameStorage.java index a303f82e245..e4b0d9b214b 100644 --- a/src/main/java/seedu/address/storage/JsonCourseNameStorage.java +++ b/src/main/java/seedu/address/storage/JsonCourseNameStorage.java @@ -48,7 +48,7 @@ public Optional readCourse(Path filePath) throws DataLoading Optional jsonCourse = JsonUtil.readJsonFile( filePath, JsonSerializableCourseName.class); - if (!jsonCourse.isPresent()) { + if (jsonCourse.isEmpty()) { return Optional.empty(); } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 6131c71630c..ed0c61fc0b3 100644 --- a/src/main/java/seedu/address/ui/MainWindow.java +++ b/src/main/java/seedu/address/ui/MainWindow.java @@ -115,7 +115,7 @@ private void loadInitialCourseNameAndSetTitle() { try { Optional courseNameOptional = storage.readCourse(); - if (!courseNameOptional.isPresent()) { + if (courseNameOptional.isEmpty()) { logger.info("Creating a new course data file " + storage.getCourseNameFilePath() + " populated with a course."); } diff --git a/src/test/java/seedu/address/commons/util/AppUtilTest.java b/src/test/java/seedu/address/commons/util/AppUtilTest.java index 6891e8569f8..51a1e7e3788 100644 --- a/src/test/java/seedu/address/commons/util/AppUtilTest.java +++ b/src/test/java/seedu/address/commons/util/AppUtilTest.java @@ -1,5 +1,6 @@ package seedu.address.commons.util; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; @@ -27,4 +28,10 @@ public void checkArgument_falseWithErrorMessage_throwsIllegalArgumentException() String errorMessage = "error message"; assertThrows(IllegalArgumentException.class, errorMessage, () -> AppUtil.checkArgument(false, errorMessage)); } + + @Test + public void getImage_exitingImage() { + assertNotNull(AppUtil.getImage("/images/address_book_32.png")); + } + } diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 21e5d5ed417..4da62b61cb6 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -36,8 +36,8 @@ public class CommandTestUtil { public static final String VALID_EMAIL_BOB = "bob@example.com"; public static final String VALID_NUSNET_AMY = "e1111111"; public static final String VALID_NUSNET_BOB = "e2222222"; - public static final String VALID_COURSE_CODE_BOB = "CS2103T"; - public static final String VALID_COURSE_CODE_AMY = "CS2101"; + public static final String VALID_COURSE_CODE_CS2103T = "CS2103T"; + public static final String VALID_COURSE_CODE_CS2101 = "CS2101"; public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1"; public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3"; public static final String VALID_WEEK_NUMBER_1 = "1"; diff --git a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java index c0f244aa132..3ec81e6999c 100644 --- a/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SetCourseCommandTest.java @@ -2,8 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_AMY; -import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_CS2101; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_CS2103T; import static seedu.address.testutil.Assert.assertThrows; import org.junit.jupiter.api.Test; @@ -14,10 +14,10 @@ public class SetCourseCommandTest { @Test public void equals() { - final SetCourseCommand standardCommand = new SetCourseCommand(new Course(VALID_COURSE_CODE_AMY)); + final SetCourseCommand standardCommand = new SetCourseCommand(new Course(VALID_COURSE_CODE_CS2101)); // same values -> returns true - SetCourseCommand commandWithSameValues = new SetCourseCommand(new Course(VALID_COURSE_CODE_AMY)); + SetCourseCommand commandWithSameValues = new SetCourseCommand(new Course(VALID_COURSE_CODE_CS2101)); assertTrue(standardCommand.equals(commandWithSameValues)); // same object -> returns true @@ -30,7 +30,7 @@ public void equals() { assertFalse(standardCommand.equals(new ClearCommand())); // different course_code -> returns false - assertFalse(standardCommand.equals(new SetCourseCommand(new Course(VALID_COURSE_CODE_BOB)))); + assertFalse(standardCommand.equals(new SetCourseCommand(new Course(VALID_COURSE_CODE_CS2103T)))); } @Test diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index 4c55423752e..47c95837252 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -113,7 +113,7 @@ public void parseCommand_unrecognisedInput_throwsParseException() { } @Test - public void parseCommand_setcourse() throws Exception { + public void parseCommand_setCourse() throws Exception { final String code = "CS2103T"; SetCourseCommand command = (SetCourseCommand) parser.parseCommand(SetCourseCommand.COMMAND_WORD + " " + code); diff --git a/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java b/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java index a7e1c14180e..029eb76965b 100644 --- a/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/SetCourseCommandParserTest.java @@ -5,5 +5,5 @@ public class SetCourseCommandParserTest { private SetCourseCommandParser parser = new SetCourseCommandParser(); private final String course = "CS2103T"; - // To be implemented in future + // TODO } diff --git a/src/test/java/seedu/address/testutil/TypicalCourse.java b/src/test/java/seedu/address/testutil/TypicalCourse.java index 78401b308b0..86577a405a7 100644 --- a/src/test/java/seedu/address/testutil/TypicalCourse.java +++ b/src/test/java/seedu/address/testutil/TypicalCourse.java @@ -1,6 +1,6 @@ package seedu.address.testutil; -import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_BOB; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_CS2103T; import seedu.address.model.CourseName; import seedu.address.model.course.Course; @@ -14,12 +14,12 @@ private TypicalCourse() {} public static CourseName getTypicalCourseName() { CourseName courseName = new CourseName(); - courseName.setCourse(new Course(VALID_COURSE_CODE_BOB)); + courseName.setCourse(new Course(VALID_COURSE_CODE_CS2103T)); return courseName; } public static Course getTypicalCourse() { - return new Course(VALID_COURSE_CODE_BOB); + return new Course(VALID_COURSE_CODE_CS2103T); } From 2e349f5587a4d740807bcec24deb4594d8401920 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:54:31 +0800 Subject: [PATCH 10/13] list command to list person command --- src/test/java/seedu/address/logic/commands/CommandTestUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 4da62b61cb6..2b3cf663349 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -44,7 +44,6 @@ public class CommandTestUtil { public static final String VALID_WEEK_NUMBER_4 = "4"; public static final String VALID_TAG_HUSBAND = "husband"; public static final String VALID_TAG_FRIEND = "friend"; - public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY; public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB; public static final String PHONE_DESC_AMY = " " + PREFIX_PHONE + VALID_PHONE_AMY; From 64200ba2c9184a2d053319a046f376a18e40545e Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:00:18 +0800 Subject: [PATCH 11/13] Minor typo --- src/test/java/seedu/address/logic/commands/CommandTestUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index a55224da8a3..c0860124ec7 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -37,7 +37,6 @@ public class CommandTestUtil { public static final String VALID_EMAIL_BOB = "bob@example.com"; public static final String VALID_NUSNET_AMY = "e1111111"; public static final String VALID_NUSNET_BOB = "e2222222"; -<<<<<<< HEAD public static final String VALID_COURSE_CODE_CS2103T = "CS2103T"; public static final String VALID_COURSE_CODE_CS2101 = "CS2101"; public static final String VALID_NUSNET_CHAD = "e3333333"; From 5583802db7de7038c17047f799eb5fe42d666de6 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:11:01 +0800 Subject: [PATCH 12/13] Added TODOs and added another parameter to Model Manager --- src/test/java/seedu/address/logic/LogicManagerTest.java | 1 + .../logic/commands/UnmarkAttendanceCommandTest.java | 5 +++-- .../java/seedu/address/logic/parser/ParserUtilTest.java | 1 + src/test/java/seedu/address/model/ModelManagerTest.java | 2 ++ .../java/seedu/address/model/util/SampleDataUtilTest.java | 7 +++++++ .../java/seedu/address/storage/StorageManagerTest.java | 2 ++ 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/test/java/seedu/address/model/util/SampleDataUtilTest.java diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 025c8a2a908..093f3594761 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -37,6 +37,7 @@ import seedu.address.testutil.PersonBuilder; public class LogicManagerTest { + // TODO private static final IOException DUMMY_IO_EXCEPTION = new IOException("dummy IO exception"); private static final IOException DUMMY_AD_EXCEPTION = new AccessDeniedException("dummy access denied exception"); diff --git a/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java b/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java index 109d63a72e3..c852cba0252 100644 --- a/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/UnmarkAttendanceCommandTest.java @@ -7,6 +7,7 @@ import static seedu.address.logic.Messages.MESSAGE_MISSING_NUSNET; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalCourse.getTypicalCourseName; import static seedu.address.testutil.TypicalPersons.ALICE; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -26,8 +27,8 @@ * Contains integration tests (interaction with the Model) for {@code MarkAttendanceCommand}. */ public class UnmarkAttendanceCommandTest { - private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs(), getTypicalCourseName()); private final NusNet testValidNusNet = new NusNet("e0000001"); private final NusNet testMissingNusNet = new NusNet("e0000000"); private final WeekNumber testValidWeekNo6 = new WeekNumber("6"); diff --git a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java index 4256788b1a7..f8dde6835ee 100644 --- a/src/test/java/seedu/address/logic/parser/ParserUtilTest.java +++ b/src/test/java/seedu/address/logic/parser/ParserUtilTest.java @@ -21,6 +21,7 @@ import seedu.address.model.tag.Tag; public class ParserUtilTest { + // TODO private static final String INVALID_NAME = "R@chel"; private static final String INVALID_PHONE = "+651234"; private static final String INVALID_ADDRESS = " "; diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index dfe0769b989..11eff258f67 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -20,6 +20,8 @@ public class ModelManagerTest { + // TODO + private ModelManager modelManager = new ModelManager(); @Test diff --git a/src/test/java/seedu/address/model/util/SampleDataUtilTest.java b/src/test/java/seedu/address/model/util/SampleDataUtilTest.java new file mode 100644 index 00000000000..80b7589c73d --- /dev/null +++ b/src/test/java/seedu/address/model/util/SampleDataUtilTest.java @@ -0,0 +1,7 @@ +package seedu.address.model.util; + +class SampleDataUtilTest { + + // TODO + +} diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index 2148afe63bf..faceb1f0339 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -17,6 +17,8 @@ public class StorageManagerTest { + // TODO + @TempDir public Path testFolder; From 1bdf9e845536e6dff4cfeb01434fe9080c907332 Mon Sep 17 00:00:00 2001 From: saiutkarsh33 <122259179+saiutkarsh33@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:36:49 +0800 Subject: [PATCH 13/13] Course is auto capitalised and minor changes according to PR Review --- .../logic/commands/SetCourseCommand.java | 9 +++------ .../seedu/address/logic/parser/ParserUtil.java | 2 +- .../java/seedu/address/model/course/Course.java | 17 +++++++++++++++++ .../address/logic/commands/AddCommandTest.java | 3 ++- .../address/logic/commands/CommandTestUtil.java | 5 +++-- .../logic/parser/AddressBookParserTest.java | 3 ++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java index 23464bc35c3..0bf0cffb2f1 100644 --- a/src/main/java/seedu/address/logic/commands/SetCourseCommand.java +++ b/src/main/java/seedu/address/logic/commands/SetCourseCommand.java @@ -25,8 +25,8 @@ public class SetCourseCommand extends Command { public static final String MESSAGE_CONSTRAINTS = "Course code should follow the format \"XX1234Y\", Y is optional"; - public static final String MESSAGE_USAGE = CommandMessageUsageUtil.generateMessageUsage("setcrs", - "Sets Course", "course code", "CS2104"); + public static final String MESSAGE_USAGE = CommandMessageUsageUtil.generateMessageUsage(COMMAND_WORD, + "Set Course name ", "course code", COMMAND_WORD + " CS2104"); public static final String MESSAGE_SUCCESS = "Successfully updated course name"; @@ -57,19 +57,16 @@ public CommandResult execute(Model model) throws CommandException { @Override public boolean equals(Object other) { - // short circuit if same object if (other == this) { return true; } - // instanceof handles nulls if (!(other instanceof SetCourseCommand)) { return false; } - // state check SetCourseCommand e = (SetCourseCommand) other; - return course.equals(e.course); + return course.equalsIgnoreCase(e.course); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 78b58d168bc..b727b472e41 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -121,7 +121,7 @@ public static NusNet parseNusNet(String nusNet) throws ParseException { */ public static Course parseCourse(String code) throws ParseException { requireNonNull(code); - String trimmedCode = code.trim(); + String trimmedCode = code.trim().toUpperCase(); if (!Tag.isValidTagName(trimmedCode)) { throw new ParseException(Course.MESSAGE_CONSTRAINTS); } diff --git a/src/main/java/seedu/address/model/course/Course.java b/src/main/java/seedu/address/model/course/Course.java index b6506ae62fd..d99391d6e03 100644 --- a/src/main/java/seedu/address/model/course/Course.java +++ b/src/main/java/seedu/address/model/course/Course.java @@ -89,4 +89,21 @@ public int hashCode() { return courseCode.hashCode(); } + /** + * Compares this Course's courseCode with another Course's courseCode for equality, ignoring case considerations. + *

+ * This method provides a case-insensitive comparison of course codes, which can be useful for + * ensuring consistency in comparisons regardless of how the course codes are capitalized. + *

+ * + * @param other The Course object to be compared with this Course for equality. + * @return true if the course codes of both courses are equal irrespective of case; false otherwise. + */ + public boolean equalsIgnoreCase(Course other) { + if (other == this) { + return true; + } + return this.courseCode.equalsIgnoreCase(other.courseCode); + } + } diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 1cc29977e8f..f79a56a0ee6 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -90,7 +90,8 @@ public void toStringMethod() { String expected = AddPersonCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}"; assertEquals(expected, addCommand.toString()); } - + // TODO + // Abstract away the assertion errors below /** * A default model stub that have all the methods failing. */ diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index c0860124ec7..ca830ecc59c 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -28,6 +28,9 @@ */ public class CommandTestUtil { + public static final String VALID_COURSE_CODE_CS2103T = "CS2103T"; + public static final String VALID_COURSE_CODE_CS2101 = "CS2101"; + public static final String VALID_NAME_AMY = "Amy Bee"; public static final String VALID_NAME_BOB = "Bob Choo"; public static final String VALID_NAME_CHAD = "Chad Giga"; @@ -37,8 +40,6 @@ public class CommandTestUtil { public static final String VALID_EMAIL_BOB = "bob@example.com"; public static final String VALID_NUSNET_AMY = "e1111111"; public static final String VALID_NUSNET_BOB = "e2222222"; - public static final String VALID_COURSE_CODE_CS2103T = "CS2103T"; - public static final String VALID_COURSE_CODE_CS2101 = "CS2101"; public static final String VALID_NUSNET_CHAD = "e3333333"; public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1"; public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3"; diff --git a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java index df48030b61f..2ab33cfcc71 100644 --- a/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddressBookParserTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.logic.commands.CommandTestUtil.VALID_COURSE_CODE_CS2103T; import static seedu.address.logic.parser.CliSyntax.PREFIX_NUSNET; import static seedu.address.logic.parser.CliSyntax.PREFIX_WEEK; import static seedu.address.testutil.Assert.assertThrows; @@ -126,7 +127,7 @@ public void parseCommand_unrecognisedInput_throwsParseException() { @Test public void parseCommand_setCourse() throws Exception { - final String code = "CS2103T"; + final String code = VALID_COURSE_CODE_CS2103T; SetCourseCommand command = (SetCourseCommand) parser.parseCommand(SetCourseCommand.COMMAND_WORD + " " + code); assertEquals(new SetCourseCommand(new Course(code)), command);