From c0f2260aad17ed3283e27b5ae9a54948b18e29ac Mon Sep 17 00:00:00 2001 From: qinxutan Date: Sun, 17 Mar 2024 16:37:40 +0800 Subject: [PATCH 01/21] Update UI of Module List --- src/main/java/seedu/address/logic/Logic.java | 1 + .../seedu/address/logic/LogicManager.java | 6 +++ .../logic/parser/AddClassCommandParser.java | 2 +- .../java/seedu/address/model/AddressBook.java | 3 ++ .../seedu/address/model/ModelManager.java | 1 - .../address/model/ReadOnlyAddressBook.java | 2 + .../seedu/address/storage/StorageManager.java | 12 ++++- .../java/seedu/address/ui/MainWindow.java | 43 +++++++++++++++++- .../java/seedu/address/ui/ModuleCard.java | 34 ++++++++++++++ .../seedu/address/ui/ModuleListPanel.java | 45 +++++++++++++++++++ src/main/resources/view/MainWindow.fxml | 11 ++--- src/main/resources/view/ModuleCard.fxml | 45 ++++++++++++------- .../seedu/address/model/AddressBookTest.java | 9 ++++ 13 files changed, 189 insertions(+), 25 deletions(-) create mode 100644 src/main/java/seedu/address/ui/ModuleCard.java create mode 100644 src/main/java/seedu/address/ui/ModuleListPanel.java diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index bee758078f0..321aee8712c 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -46,4 +46,5 @@ public interface Logic { * Set the user prefs' GUI settings. */ void setGuiSettings(GuiSettings guiSettings); + boolean isInitialModuleListPanelDisplayed(); } diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 5aa3b91c7d0..88030fea5f0 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -85,4 +85,10 @@ public GuiSettings getGuiSettings() { public void setGuiSettings(GuiSettings guiSettings) { model.setGuiSettings(guiSettings); } + + @Override + public boolean isInitialModuleListPanelDisplayed() { + // Check if there are any modules in the address book + return !model.getAddressBook().getModuleList().isEmpty(); + } } diff --git a/src/main/java/seedu/address/logic/parser/AddClassCommandParser.java b/src/main/java/seedu/address/logic/parser/AddClassCommandParser.java index 91db403f30a..109513a4e03 100644 --- a/src/main/java/seedu/address/logic/parser/AddClassCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddClassCommandParser.java @@ -28,7 +28,7 @@ public AddClassCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS); if (!arePrefixesPresent(argMultimap, PREFIX_MODULECODE, PREFIX_TUTORIALCLASS) - || !argMultimap.getPreamble().isEmpty()) { + || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddClassCommand.MESSAGE_USAGE)); } diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 1cf2ba9487e..74ebfef7e2a 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -82,6 +82,7 @@ public void addPerson(Person p) { /** * Returns true if a module with the same identity as {@code module} exists in the address book. */ + @Override public boolean hasModule(ModuleCode module) { requireNonNull(module); return modules.contains(module); @@ -106,6 +107,7 @@ public ModuleCode findModuleFromList(ModuleCode module) { * Adds a module to the address book. * The module must not already exist in the address book. (TODO) */ + @Override public void addModule(ModuleCode m) { modules.add(m); } @@ -143,6 +145,7 @@ public ObservableList getPersonList() { return persons.asUnmodifiableObservableList(); } + @Override public List getModuleList() { return modules; } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 82caacc26be..1e9f004466b 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -162,5 +162,4 @@ public boolean equals(Object other) { && userPrefs.equals(otherModelManager.userPrefs) && filteredPersons.equals(otherModelManager.filteredPersons); } - } diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index d1397db1fa6..ed3f6b6afb2 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -18,4 +18,6 @@ public interface ReadOnlyAddressBook { ObservableList getPersonList(); List getModuleList(); + boolean hasModule(ModuleCode moduleCode); + void addModule(ModuleCode moduleCode); } diff --git a/src/main/java/seedu/address/storage/StorageManager.java b/src/main/java/seedu/address/storage/StorageManager.java index 8b84a9024d5..d3bb8d385c9 100644 --- a/src/main/java/seedu/address/storage/StorageManager.java +++ b/src/main/java/seedu/address/storage/StorageManager.java @@ -61,7 +61,17 @@ public Optional readAddressBook() throws DataLoadingExcepti @Override public Optional readAddressBook(Path filePath) throws DataLoadingException { logger.fine("Attempting to read data from file: " + filePath); - return addressBookStorage.readAddressBook(filePath); + Optional addressBookOptional = addressBookStorage.readAddressBook(filePath); + + addressBookOptional.ifPresent(addressBook -> { + addressBook.getModuleList().forEach(moduleCode -> { + if (!addressBook.hasModule(moduleCode)) { + addressBook.addModule(moduleCode); + } + }); + }); + + return addressBookOptional; } @Override diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index 08c733e2693..bd54605911e 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.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.MenuItem; @@ -14,8 +16,10 @@ import seedu.address.commons.core.LogsCenter; import seedu.address.logic.Logic; import seedu.address.logic.commands.CommandResult; +import seedu.address.logic.commands.ListClassesCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.module.ModuleCode; /** * The Main Window. Provides the basic application layout containing @@ -32,6 +36,7 @@ public class MainWindow extends UiPart { // Independent Ui parts residing in this Ui container private PersonListPanel personListPanel; + private ModuleListPanel moduleListPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -43,6 +48,8 @@ public class MainWindow extends UiPart { @FXML private StackPane personListPanelPlaceholder; + @FXML + private StackPane moduleListPanelPlaceholder; @FXML private StackPane resultDisplayPlaceholder; @@ -110,8 +117,11 @@ private void setAccelerator(MenuItem menuItem, KeyCombination keyCombination) { * Fills up all the placeholders of this window. */ void fillInnerParts() { - personListPanel = new PersonListPanel(logic.getFilteredPersonList()); - personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + if (initiallyDisplayModuleListPanel()) { + switchToModuleListPanel(); + } else { + switchToPersonListPanel(); + } resultDisplay = new ResultDisplay(); resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); @@ -123,6 +133,22 @@ void fillInnerParts() { commandBoxPlaceholder.getChildren().add(commandBox.getRoot()); } + private boolean initiallyDisplayModuleListPanel() { + return logic.isInitialModuleListPanelDisplayed(); + } + + private void switchToPersonListPanel() { + personListPanel = new PersonListPanel(logic.getFilteredPersonList()); + personListPanelPlaceholder.getChildren().add(personListPanel.getRoot()); + } + + private void switchToModuleListPanel() { + ObservableList moduleObservableList = FXCollections + .observableList(logic.getAddressBook().getModuleList()); + moduleListPanel = new ModuleListPanel(moduleObservableList); + moduleListPanelPlaceholder.getChildren().add(moduleListPanel.getRoot()); + } + /** * Sets the default size based on {@code guiSettings}. */ @@ -186,6 +212,14 @@ private CommandResult executeCommand(String commandText) throws CommandException handleExit(); } + clearPanels(); + + if (commandText.equals(ListClassesCommand.COMMAND_WORD)) { + switchToModuleListPanel(); + } else { + switchToPersonListPanel(); + } + return commandResult; } catch (CommandException | ParseException e) { logger.info("An error occurred while executing command: " + commandText); @@ -193,4 +227,9 @@ private CommandResult executeCommand(String commandText) throws CommandException throw e; } } + + private void clearPanels() { + personListPanelPlaceholder.getChildren().clear(); + moduleListPanelPlaceholder.getChildren().clear(); + } } diff --git a/src/main/java/seedu/address/ui/ModuleCard.java b/src/main/java/seedu/address/ui/ModuleCard.java new file mode 100644 index 00000000000..fa98fda17d2 --- /dev/null +++ b/src/main/java/seedu/address/ui/ModuleCard.java @@ -0,0 +1,34 @@ +package seedu.address.ui; + +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; +import javafx.scene.layout.Region; +import seedu.address.model.module.ModuleCode; + +/** + * An UI component that displays information of a {@code Module}. + */ +public class ModuleCard extends UiPart { + + private static final String FXML = "ModuleCard.fxml"; + + public final ModuleCode moduleCode; + + @FXML + private HBox cardPane; + @FXML + private Label moduleCodeLabel; + @FXML + private Label tutorialClassLabel; + + /** + * Creates a {@code ModuleCard} with the given {@code Module}. + */ + public ModuleCard(ModuleCode moduleCode) { + super(FXML); + this.moduleCode = moduleCode; + moduleCodeLabel.setText(moduleCode.value); + tutorialClassLabel.setText(moduleCode.getTutorialClasses().toString()); + } +} diff --git a/src/main/java/seedu/address/ui/ModuleListPanel.java b/src/main/java/seedu/address/ui/ModuleListPanel.java new file mode 100644 index 00000000000..4d5a8679131 --- /dev/null +++ b/src/main/java/seedu/address/ui/ModuleListPanel.java @@ -0,0 +1,45 @@ +package seedu.address.ui; + +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.layout.Region; +import seedu.address.model.module.ModuleCode; + +/** + * Panel containing the list of module codes. + */ +public class ModuleListPanel extends UiPart { + private static final String FXML = "ModuleListPanel.fxml"; + + @FXML + private ListView moduleListView; + + /** + * Creates a {@code ModuleListPanel} with the given {@code ObservableList}. + */ + public ModuleListPanel(ObservableList moduleCodeList) { + super(FXML); + moduleListView.setItems(moduleCodeList); + moduleListView.setCellFactory(listView -> new ModuleListViewCell()); + } + + /** + * Custom {@code ListCell} that displays the graphics of a {@code ModuleCode} using a {@code ModuleCard}. + */ + class ModuleListViewCell extends ListCell { + @Override + protected void updateItem(ModuleCode moduleCode, boolean empty) { + super.updateItem(moduleCode, empty); + + if (empty || moduleCode == null) { + setGraphic(null); + setText(null); + } else { + setGraphic(new ModuleCard(moduleCode).getRoot()); + } + } + } +} + diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index 76080047eff..a8e267da287 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -26,7 +26,7 @@ - + @@ -53,16 +53,17 @@ - - + + - - + + + diff --git a/src/main/resources/view/ModuleCard.fxml b/src/main/resources/view/ModuleCard.fxml index f80e658d03d..c6df151db9a 100644 --- a/src/main/resources/view/ModuleCard.fxml +++ b/src/main/resources/view/ModuleCard.fxml @@ -1,23 +1,38 @@ + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 9b09cf986f1..8944db59efc 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -108,5 +108,14 @@ public ObservableList getPersonList() { public List getModuleList() { return null; } + + @Override + public boolean hasModule(ModuleCode moduleCode) { + return false; + } + + @Override + public void addModule(ModuleCode moduleCode) { + } } } From 17abb234442969b307fdb1734e6a08946d677380 Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 01:51:40 +0800 Subject: [PATCH 02/21] Update UI --- src/main/java/seedu/address/Main.java | 3 +- src/main/java/seedu/address/logic/Logic.java | 4 ++ .../seedu/address/logic/LogicManager.java | 6 ++- .../java/seedu/address/model/AddressBook.java | 19 +++++----- src/main/java/seedu/address/model/Model.java | 6 ++- .../seedu/address/model/ModelManager.java | 21 +++++++++- .../address/model/ReadOnlyAddressBook.java | 5 +-- .../address/model/module/ModuleCode.java | 15 ++++++++ .../address/model/module/TutorialClass.java | 38 ++++++++++++++++--- .../storage/JsonSerializableAddressBook.java | 25 ++++++++++-- .../java/seedu/address/ui/MainWindow.java | 7 +--- .../logic/commands/AddCommandTest.java | 10 +++++ .../seedu/address/model/AddressBookTest.java | 2 +- .../JsonSerializableAddressBookTest.java | 32 +++++++++------- 14 files changed, 146 insertions(+), 47 deletions(-) diff --git a/src/main/java/seedu/address/Main.java b/src/main/java/seedu/address/Main.java index ec1b7958746..11cd91183b5 100644 --- a/src/main/java/seedu/address/Main.java +++ b/src/main/java/seedu/address/Main.java @@ -26,7 +26,8 @@ public class Main { public static void main(String[] args) { - // As per https://github.com/openjdk/jfx/blob/master/doc-files/release-notes-16.md + // As per https://github.com/ope + // njdk/jfx/blob/master/doc-files/release-notes-16.md // JavaFX 16 (or later) runtime logs a warning at startup if JavaFX classes are loaded from // the classpath instead of a module. // Our application does not use Java modules yet. Even if it did, modules are ignored when diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 321aee8712c..3d14c2766f4 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -8,6 +8,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; /** @@ -32,6 +33,9 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); + + ObservableList getFilteredModuleList(); + /** * Returns the user prefs' address book file path. */ diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 88030fea5f0..9b34f80bc95 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.module.ModuleCode; import seedu.address.model.person.Person; import seedu.address.storage.Storage; @@ -70,7 +71,10 @@ public ReadOnlyAddressBook getAddressBook() { public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } - + @Override + public ObservableList getFilteredModuleList() { + return model.getFilteredModuleList(); + } @Override public Path getAddressBookFilePath() { return model.getAddressBookFilePath(); diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index 74ebfef7e2a..e903bc1c542 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -2,9 +2,9 @@ import static java.util.Objects.requireNonNull; -import java.util.ArrayList; import java.util.List; +import javafx.collections.FXCollections; import javafx.collections.ObservableList; import seedu.address.commons.util.ToStringBuilder; import seedu.address.model.module.ModuleCode; @@ -18,7 +18,7 @@ public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; - private final ArrayList modules; + private final ObservableList modules; /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication @@ -29,7 +29,7 @@ public class AddressBook implements ReadOnlyAddressBook { */ { persons = new UniquePersonList(); - modules = new ArrayList<>(); + modules = FXCollections.observableArrayList(); } public AddressBook() {} @@ -57,8 +57,8 @@ public void setPersons(List persons) { */ public void resetData(ReadOnlyAddressBook newData) { requireNonNull(newData); - setPersons(newData.getPersonList()); + setModules(newData.getModuleList()); } //// person-level operations @@ -82,7 +82,6 @@ public void addPerson(Person p) { /** * Returns true if a module with the same identity as {@code module} exists in the address book. */ - @Override public boolean hasModule(ModuleCode module) { requireNonNull(module); return modules.contains(module); @@ -107,7 +106,6 @@ public ModuleCode findModuleFromList(ModuleCode module) { * Adds a module to the address book. * The module must not already exist in the address book. (TODO) */ - @Override public void addModule(ModuleCode m) { modules.add(m); } @@ -119,10 +117,14 @@ public void addModule(ModuleCode m) { */ public void setPerson(Person target, Person editedPerson) { requireNonNull(editedPerson); - persons.setPerson(target, editedPerson); } + public void setModules(List modules) { + this.modules.setAll(modules); + } + + /** * Removes {@code key} from this {@code AddressBook}. * {@code key} must exist in the address book. @@ -145,8 +147,7 @@ public ObservableList getPersonList() { return persons.asUnmodifiableObservableList(); } - @Override - public List getModuleList() { + public ObservableList getModuleList() { return modules; } diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index cf6dd97aefc..c5cead4f47c 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -14,7 +14,7 @@ public interface Model { /** {@code Predicate} that always evaluate to true */ Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; - + Predicate PREDICATE_SHOW_ALL_MODULES = unused -> true; /** * Replaces user prefs data with the data in {@code userPrefs}. */ @@ -99,9 +99,13 @@ public interface Model { /** Returns an unmodifiable view of the filtered person list */ ObservableList getFilteredPersonList(); + ObservableList getFilteredModuleList(); + /** * Updates the filter of the filtered person list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredPersonList(Predicate predicate); + + void updateFilteredModuleList(Predicate predicate); } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 1e9f004466b..c90013aafb6 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -24,6 +24,7 @@ public class ModelManager implements Model { private final AddressBook addressBook; private final UserPrefs userPrefs; private final FilteredList filteredPersons; + private final FilteredList filteredModules; /** * Initializes a ModelManager with the given addressBook and userPrefs. @@ -36,6 +37,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs this.addressBook = new AddressBook(addressBook); this.userPrefs = new UserPrefs(userPrefs); filteredPersons = new FilteredList<>(this.addressBook.getPersonList()); + filteredModules = new FilteredList<>(this.addressBook.getModuleList()); } public ModelManager() { @@ -120,12 +122,13 @@ public void addPerson(Person person) { @Override public void addModule(ModuleCode module) { addressBook.addModule(module); + updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES); } + @Override public void setPerson(Person target, Person editedPerson) { requireAllNonNull(target, editedPerson); - addressBook.setPerson(target, editedPerson); } @@ -140,12 +143,25 @@ public ObservableList getFilteredPersonList() { return filteredPersons; } + @Override + public ObservableList getFilteredModuleList() { + return filteredModules; + } + + @Override public void updateFilteredPersonList(Predicate predicate) { requireNonNull(predicate); filteredPersons.setPredicate(predicate); } + @Override + public void updateFilteredModuleList(Predicate predicate) { + requireNonNull(predicate); + filteredModules.setPredicate(predicate); + } + + @Override public boolean equals(Object other) { if (other == this) { @@ -160,6 +176,7 @@ public boolean equals(Object other) { ModelManager otherModelManager = (ModelManager) other; return addressBook.equals(otherModelManager.addressBook) && userPrefs.equals(otherModelManager.userPrefs) - && filteredPersons.equals(otherModelManager.filteredPersons); + && filteredPersons.equals(otherModelManager.filteredPersons) + && filteredModules.equals(otherModelManager.filteredModules); } } diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index ed3f6b6afb2..98f06b01a5d 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -1,7 +1,5 @@ package seedu.address.model; -import java.util.List; - import javafx.collections.ObservableList; import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; @@ -17,7 +15,8 @@ public interface ReadOnlyAddressBook { */ ObservableList getPersonList(); - List getModuleList(); + ObservableList getModuleList(); + boolean hasModule(ModuleCode moduleCode); void addModule(ModuleCode moduleCode); } diff --git a/src/main/java/seedu/address/model/module/ModuleCode.java b/src/main/java/seedu/address/model/module/ModuleCode.java index 7f14742f20c..1b2e428e694 100644 --- a/src/main/java/seedu/address/model/module/ModuleCode.java +++ b/src/main/java/seedu/address/model/module/ModuleCode.java @@ -4,6 +4,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.util.ArrayList; +import java.util.List; /** * Represents a Module's module code. @@ -34,6 +35,20 @@ public ModuleCode(String name) { this.value = name; this.tutorialClasses = new ArrayList(); } + /** + * Constructs a ModuleCode object with the given name and list of tutorial classes. + * + * @param name The name or code of the module. + * @param tutorialClasses The list of tutorial classes associated with the module. + * @throws NullPointerException If the name is null. + * @throws IllegalArgumentException If the provided name does not adhere to the constraints. + */ + public ModuleCode(String name, List tutorialClasses) { + requireAllNonNull(name); + checkArgument(isValidModuleCode(name), MESSAGE_CONSTRAINTS); + this.value = name; + this.tutorialClasses = (tutorialClasses != null) ? new ArrayList<>(tutorialClasses) : new ArrayList<>(); + } /** * A constructor for Module. Used to initialise a new module with the tutorial class specified. diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index 4279a5ec062..2c83eb70a18 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -4,6 +4,7 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.util.ArrayList; +import java.util.List; import seedu.address.model.person.Person; @@ -24,16 +25,23 @@ public class TutorialClass { public final String value; private final ArrayList students; + /** + * Constructs an empty TutorialClass object with no assigned value and an empty list of students. + */ + public TutorialClass() { + this.value = null; + this.students = new ArrayList<>(); + } /** * A constructor for TutorialClass. Creates an empty tutorial class with no students. * - * @param name of tutorial to be added + * @param value of tutorial to be added */ - public TutorialClass(String name) { - requireAllNonNull(name); - checkArgument(isValidTutorialClass(name), MESSAGE_CONSTRAINTS); - this.value = name; + public TutorialClass(String value) { + requireAllNonNull(value); + checkArgument(isValidTutorialClass(value), MESSAGE_CONSTRAINTS); + this.value = value; this.students = new ArrayList<>(); } @@ -49,7 +57,20 @@ public TutorialClass(String name, ArrayList students) { this.value = name; this.students = students; } - + /** + * Constructs a TutorialClass object with the given name and list of students. + * + * @param name The name or value of the tutorial class. + * @param students The list of students enrolled in the tutorial class. + * @throws NullPointerException If either the name or the list of students is null. + * @throws IllegalArgumentException If the provided name does not adhere to the constraints. + */ + public TutorialClass(String name, List students) { + requireAllNonNull(name, students); + checkArgument(isValidTutorialClass(name), MESSAGE_CONSTRAINTS); + this.value = name; + this.students = new ArrayList<>(students); + } /** * Returns true if a given string is a valid tutorial class code. */ @@ -62,6 +83,11 @@ public String toString() { return value; } + public List getStudents() { + return List.copyOf(students); + } + + @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index 5efd834091d..eb8bb074532 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -11,24 +11,34 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; +import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; /** * An Immutable AddressBook that is serializable to JSON format. */ @JsonRootName(value = "addressbook") -class JsonSerializableAddressBook { +public class JsonSerializableAddressBook { public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; + public static final String MESSAGE_DUPLICATE_MODULE = "Modules list contains duplicate module(s)."; + private final List persons = new ArrayList<>(); + private final List modules = new ArrayList<>(); /** * Constructs a {@code JsonSerializableAddressBook} with the given persons. */ @JsonCreator - public JsonSerializableAddressBook(@JsonProperty("persons") List persons) { - this.persons.addAll(persons); + public JsonSerializableAddressBook(@JsonProperty("persons") List persons, + @JsonProperty("modules") List modules) { + if (persons != null) { + this.persons.addAll(persons); + } + if (modules != null) { + this.modules.addAll(modules); + } } /** @@ -38,6 +48,7 @@ public JsonSerializableAddressBook(@JsonProperty("persons") List moduleObservableList = FXCollections - .observableList(logic.getAddressBook().getModuleList()); - moduleListPanel = new ModuleListPanel(moduleObservableList); + moduleListPanel = new ModuleListPanel(logic.getFilteredModuleList()); moduleListPanelPlaceholder.getChildren().add(moduleListPanel.getRoot()); } diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index 4dd039ab076..35bfb0ea2a9 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -168,10 +168,20 @@ public ObservableList getFilteredPersonList() { throw new AssertionError("This method should not be called."); } + @Override + public ObservableList getFilteredModuleList() { + throw new AssertionError("This method should not be called."); + } + @Override public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } + + @Override + public void updateFilteredModuleList(Predicate predicate) { + throw new AssertionError("This method should not be called."); + } } /** diff --git a/src/test/java/seedu/address/model/AddressBookTest.java b/src/test/java/seedu/address/model/AddressBookTest.java index 8944db59efc..72a9540497a 100644 --- a/src/test/java/seedu/address/model/AddressBookTest.java +++ b/src/test/java/seedu/address/model/AddressBookTest.java @@ -105,7 +105,7 @@ public ObservableList getPersonList() { } @Override - public List getModuleList() { + public ObservableList getModuleList() { return null; } diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index 188c9058d20..91ba0a8f1e8 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -5,43 +5,49 @@ import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.JsonUtil; import seedu.address.model.AddressBook; +import seedu.address.model.module.ModuleCode; import seedu.address.testutil.TypicalPersons; public class JsonSerializableAddressBookTest { private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableAddressBookTest"); private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); - private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); - private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); @Test public void toModelType_typicalPersonsFile_success() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE, - JsonSerializableAddressBook.class).get(); + JsonSerializableAddressBook.class).get(); AddressBook addressBookFromFile = dataFromFile.toModelType(); AddressBook typicalPersonsAddressBook = TypicalPersons.getTypicalAddressBook(); assertEquals(addressBookFromFile, typicalPersonsAddressBook); } @Test - public void toModelType_invalidPersonFile_throwsIllegalValueException() throws Exception { - JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(INVALID_PERSON_FILE, - JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, dataFromFile::toModelType); + public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { + List validPersons = new ArrayList<>(); + validPersons.add(new JsonAdaptedPerson(TypicalPersons.ALICE)); + validPersons.add(new JsonAdaptedPerson(TypicalPersons.ALICE)); // Duplicate person + JsonSerializableAddressBook data = new JsonSerializableAddressBook(validPersons, new ArrayList<>()); + assertThrows(IllegalValueException.class, JsonSerializableAddressBook + .MESSAGE_DUPLICATE_PERSON, data::toModelType); } @Test - public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { - JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE, - JsonSerializableAddressBook.class).get(); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, - dataFromFile::toModelType); + public void toModelType_duplicateModules_throwsIllegalValueException() throws Exception { + List validModules = new ArrayList<>(); + validModules.add(new JsonAdaptedModule(new ModuleCode("CS1010"))); + validModules.add(new JsonAdaptedModule(new ModuleCode("CS1010"))); // Duplicate module + JsonSerializableAddressBook data = new JsonSerializableAddressBook(new ArrayList<>(), validModules); + assertThrows(IllegalValueException.class, JsonSerializableAddressBook + .MESSAGE_DUPLICATE_MODULE, data::toModelType); } - } + From ba928236931be5cf419e7b32563ec215f0e97fbd Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 16:08:15 +0800 Subject: [PATCH 03/21] Test cases --- src/main/java/seedu/address/model/Model.java | 6 ---- .../seedu/address/model/ModelManager.java | 7 ---- .../address/model/module/ModuleCode.java | 15 -------- .../address/model/module/TutorialClass.java | 34 ------------------- .../logic/commands/AddCommandTest.java | 5 --- .../seedu/address/model/ModelManagerTest.java | 6 ++++ .../address/storage/StorageManagerTest.java | 20 +++++++++++ 7 files changed, 26 insertions(+), 67 deletions(-) diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index d325f51f14d..de9f4b26ae0 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -57,12 +57,6 @@ public interface Model { * Returns true if a person with the same identity as {@code person} exists in the address book. */ boolean hasPerson(Person person); - - /** - * Returns true if a module with the same identity as {@code module} exists in the address book. - */ - boolean hasModule(ModuleCode module); - /** * Finds the module object from the list if it exists. Else, returns null. * diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index 6b69fa3311e..ef26f11de1e 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -96,13 +96,6 @@ public boolean hasPerson(Person person) { requireNonNull(person); return addressBook.hasPerson(person); } - - @Override - public boolean hasModule(ModuleCode module) { - requireNonNull(module); - return addressBook.hasModule(module); - } - @Override public ModuleCode findModuleFromList(ModuleCode module) { requireNonNull(module); diff --git a/src/main/java/seedu/address/model/module/ModuleCode.java b/src/main/java/seedu/address/model/module/ModuleCode.java index 1b2e428e694..7f14742f20c 100644 --- a/src/main/java/seedu/address/model/module/ModuleCode.java +++ b/src/main/java/seedu/address/model/module/ModuleCode.java @@ -4,7 +4,6 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.util.ArrayList; -import java.util.List; /** * Represents a Module's module code. @@ -35,20 +34,6 @@ public ModuleCode(String name) { this.value = name; this.tutorialClasses = new ArrayList(); } - /** - * Constructs a ModuleCode object with the given name and list of tutorial classes. - * - * @param name The name or code of the module. - * @param tutorialClasses The list of tutorial classes associated with the module. - * @throws NullPointerException If the name is null. - * @throws IllegalArgumentException If the provided name does not adhere to the constraints. - */ - public ModuleCode(String name, List tutorialClasses) { - requireAllNonNull(name); - checkArgument(isValidModuleCode(name), MESSAGE_CONSTRAINTS); - this.value = name; - this.tutorialClasses = (tutorialClasses != null) ? new ArrayList<>(tutorialClasses) : new ArrayList<>(); - } /** * A constructor for Module. Used to initialise a new module with the tutorial class specified. diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index 2c83eb70a18..ba9293c186a 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -25,13 +25,6 @@ public class TutorialClass { public final String value; private final ArrayList students; - /** - * Constructs an empty TutorialClass object with no assigned value and an empty list of students. - */ - public TutorialClass() { - this.value = null; - this.students = new ArrayList<>(); - } /** * A constructor for TutorialClass. Creates an empty tutorial class with no students. @@ -44,33 +37,6 @@ public TutorialClass(String value) { this.value = value; this.students = new ArrayList<>(); } - - /** - * A constructor for TutorialClass. Creates a tutorial with the list of students specified. - * - * @param name of tutorial to be added - * @param students to be in the added tutorial - */ - public TutorialClass(String name, ArrayList students) { - requireAllNonNull(name); - checkArgument(isValidTutorialClass(name), MESSAGE_CONSTRAINTS); - this.value = name; - this.students = students; - } - /** - * Constructs a TutorialClass object with the given name and list of students. - * - * @param name The name or value of the tutorial class. - * @param students The list of students enrolled in the tutorial class. - * @throws NullPointerException If either the name or the list of students is null. - * @throws IllegalArgumentException If the provided name does not adhere to the constraints. - */ - public TutorialClass(String name, List students) { - requireAllNonNull(name, students); - checkArgument(isValidTutorialClass(name), MESSAGE_CONSTRAINTS); - this.value = name; - this.students = new ArrayList<>(students); - } /** * Returns true if a given string is a valid tutorial class code. */ diff --git a/src/test/java/seedu/address/logic/commands/AddCommandTest.java b/src/test/java/seedu/address/logic/commands/AddCommandTest.java index e73ba638e14..c72568729da 100644 --- a/src/test/java/seedu/address/logic/commands/AddCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/AddCommandTest.java @@ -149,11 +149,6 @@ public void addModule(ModuleCode module) { throw new AssertionError("This method should not be called."); } - @Override - public boolean hasModule(ModuleCode module) { - throw new AssertionError("This method should not be called."); - } - @Override public ModuleCode findModuleFromList(ModuleCode module) { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/seedu/address/model/ModelManagerTest.java b/src/test/java/seedu/address/model/ModelManagerTest.java index 2cf1418d116..3600d57323f 100644 --- a/src/test/java/seedu/address/model/ModelManagerTest.java +++ b/src/test/java/seedu/address/model/ModelManagerTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_MODULES; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import static seedu.address.testutil.Assert.assertThrows; import static seedu.address.testutil.TypicalPersons.ALICE; @@ -92,6 +93,10 @@ public void hasPerson_personInAddressBook_returnsTrue() { public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException() { assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredPersonList().remove(0)); } + @Test + public void getFilteredModuleList_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> modelManager.getFilteredModuleList().remove(0)); + } @Test public void equals() { @@ -123,6 +128,7 @@ public void equals() { // resets modelManager to initial state for upcoming tests modelManager.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + modelManager.updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES); // different userPrefs -> returns false UserPrefs differentUserPrefs = new UserPrefs(); diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index 99a16548970..8a28214409f 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 org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import java.nio.file.Path; @@ -64,5 +65,24 @@ public void addressBookReadSave() throws Exception { public void getAddressBookFilePath() { assertNotNull(storageManager.getAddressBookFilePath()); } + @Test + public void getUserPrefsFilePath() { + assertNotNull(storageManager.getUserPrefsFilePath()); + } + + @Test + public void readAddressBook_withModulesWithoutModuleList_addsModulesToList() throws Exception { + AddressBook addressBook = getTypicalAddressBook(); + JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(getTempFilePath("ab")); + StorageManager storageManager = new StorageManager(addressBookStorage, + new JsonUserPrefsStorage(getTempFilePath("prefs"))); + storageManager.saveAddressBook(addressBook); + + // Modify the storage file to remove module list + addressBookStorage.saveAddressBook(new AddressBook(), addressBookStorage.getAddressBookFilePath()); + + ReadOnlyAddressBook retrieved = storageManager.readAddressBook().get(); + assertTrue(retrieved.getModuleList().isEmpty()); + } } From 2de2a10cce3afab8835b8e58531364074f389ffe Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 17:02:16 +0800 Subject: [PATCH 04/21] Fix syntax --- src/main/java/seedu/address/Main.java | 3 +- src/main/java/seedu/address/logic/Logic.java | 4 --- .../seedu/address/logic/LogicManager.java | 6 +--- .../java/seedu/address/model/AddressBook.java | 22 +++++++----- src/main/java/seedu/address/model/Model.java | 4 ++- .../seedu/address/model/ModelManager.java | 7 ++-- .../address/model/ReadOnlyAddressBook.java | 3 +- .../address/model/module/ModuleCode.java | 1 + .../address/model/module/TutorialClass.java | 35 +++++++++++++------ .../storage/JsonSerializableAddressBook.java | 4 +-- .../java/seedu/address/ui/MainWindow.java | 7 +++- .../JsonSerializableAddressBookTest.java | 32 +++++++---------- 12 files changed, 69 insertions(+), 59 deletions(-) diff --git a/src/main/java/seedu/address/Main.java b/src/main/java/seedu/address/Main.java index 11cd91183b5..ec1b7958746 100644 --- a/src/main/java/seedu/address/Main.java +++ b/src/main/java/seedu/address/Main.java @@ -26,8 +26,7 @@ public class Main { public static void main(String[] args) { - // As per https://github.com/ope - // njdk/jfx/blob/master/doc-files/release-notes-16.md + // As per https://github.com/openjdk/jfx/blob/master/doc-files/release-notes-16.md // JavaFX 16 (or later) runtime logs a warning at startup if JavaFX classes are loaded from // the classpath instead of a module. // Our application does not use Java modules yet. Even if it did, modules are ignored when diff --git a/src/main/java/seedu/address/logic/Logic.java b/src/main/java/seedu/address/logic/Logic.java index 3d14c2766f4..321aee8712c 100644 --- a/src/main/java/seedu/address/logic/Logic.java +++ b/src/main/java/seedu/address/logic/Logic.java @@ -8,7 +8,6 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; /** @@ -33,9 +32,6 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); - - ObservableList getFilteredModuleList(); - /** * Returns the user prefs' address book file path. */ diff --git a/src/main/java/seedu/address/logic/LogicManager.java b/src/main/java/seedu/address/logic/LogicManager.java index 9b34f80bc95..88030fea5f0 100644 --- a/src/main/java/seedu/address/logic/LogicManager.java +++ b/src/main/java/seedu/address/logic/LogicManager.java @@ -15,7 +15,6 @@ import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.Model; import seedu.address.model.ReadOnlyAddressBook; -import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; import seedu.address.storage.Storage; @@ -71,10 +70,7 @@ public ReadOnlyAddressBook getAddressBook() { public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } - @Override - public ObservableList getFilteredModuleList() { - return model.getFilteredModuleList(); - } + @Override public Path getAddressBookFilePath() { return model.getAddressBookFilePath(); diff --git a/src/main/java/seedu/address/model/AddressBook.java b/src/main/java/seedu/address/model/AddressBook.java index e903bc1c542..dd520856e22 100644 --- a/src/main/java/seedu/address/model/AddressBook.java +++ b/src/main/java/seedu/address/model/AddressBook.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; +import java.util.ArrayList; import java.util.List; import javafx.collections.FXCollections; @@ -18,7 +19,7 @@ public class AddressBook implements ReadOnlyAddressBook { private final UniquePersonList persons; - private final ObservableList modules; + private final ArrayList modules; /* * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication @@ -29,7 +30,7 @@ public class AddressBook implements ReadOnlyAddressBook { */ { persons = new UniquePersonList(); - modules = FXCollections.observableArrayList(); + modules = new ArrayList<>(); } public AddressBook() {} @@ -52,11 +53,17 @@ public void setPersons(List persons) { this.persons.setPersons(persons); } + public void setModules(List modules) { + requireNonNull(modules); + this.modules.clear(); + this.modules.addAll(modules); + } /** * Resets the existing data of this {@code AddressBook} with {@code newData}. */ public void resetData(ReadOnlyAddressBook newData) { requireNonNull(newData); + setPersons(newData.getPersonList()); setModules(newData.getModuleList()); } @@ -82,6 +89,7 @@ public void addPerson(Person p) { /** * Returns true if a module with the same identity as {@code module} exists in the address book. */ + @Override public boolean hasModule(ModuleCode module) { requireNonNull(module); return modules.contains(module); @@ -106,6 +114,7 @@ public ModuleCode findModuleFromList(ModuleCode module) { * Adds a module to the address book. * The module must not already exist in the address book. (TODO) */ + @Override public void addModule(ModuleCode m) { modules.add(m); } @@ -117,14 +126,10 @@ public void addModule(ModuleCode m) { */ public void setPerson(Person target, Person editedPerson) { requireNonNull(editedPerson); - persons.setPerson(target, editedPerson); - } - public void setModules(List modules) { - this.modules.setAll(modules); + persons.setPerson(target, editedPerson); } - /** * Removes {@code key} from this {@code AddressBook}. * {@code key} must exist in the address book. @@ -147,8 +152,9 @@ public ObservableList getPersonList() { return persons.asUnmodifiableObservableList(); } + @Override public ObservableList getModuleList() { - return modules; + return FXCollections.observableList(modules); } @Override diff --git a/src/main/java/seedu/address/model/Model.java b/src/main/java/seedu/address/model/Model.java index de9f4b26ae0..4e023b3e8f3 100644 --- a/src/main/java/seedu/address/model/Model.java +++ b/src/main/java/seedu/address/model/Model.java @@ -15,6 +15,8 @@ public interface Model { /** {@code Predicate} that always evaluate to true */ Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; Predicate PREDICATE_SHOW_ALL_MODULES = unused -> true; + + /** * Replaces user prefs data with the data in {@code userPrefs}. */ @@ -92,7 +94,6 @@ public interface Model { /** Returns an unmodifiable view of the filtered person list */ ObservableList getFilteredPersonList(); - ObservableList getFilteredModuleList(); /** @@ -105,4 +106,5 @@ public interface Model { * Search for person by a given {@code predicate}. */ Person searchPersonByPredicate(Predicate predicate); + } diff --git a/src/main/java/seedu/address/model/ModelManager.java b/src/main/java/seedu/address/model/ModelManager.java index ef26f11de1e..abc0bc8823e 100644 --- a/src/main/java/seedu/address/model/ModelManager.java +++ b/src/main/java/seedu/address/model/ModelManager.java @@ -115,13 +115,12 @@ public void addPerson(Person person) { @Override public void addModule(ModuleCode module) { addressBook.addModule(module); - updateFilteredModuleList(PREDICATE_SHOW_ALL_MODULES); } - @Override public void setPerson(Person target, Person editedPerson) { requireAllNonNull(target, editedPerson); + addressBook.setPerson(target, editedPerson); } @@ -141,7 +140,6 @@ public ObservableList getFilteredModuleList() { return filteredModules; } - @Override public void updateFilteredPersonList(Predicate predicate) { requireNonNull(predicate); @@ -179,7 +177,6 @@ public boolean equals(Object other) { ModelManager otherModelManager = (ModelManager) other; return addressBook.equals(otherModelManager.addressBook) && userPrefs.equals(otherModelManager.userPrefs) - && filteredPersons.equals(otherModelManager.filteredPersons) - && filteredModules.equals(otherModelManager.filteredModules); + && filteredPersons.equals(otherModelManager.filteredPersons); } } diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index 98f06b01a5d..46ce73328bd 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -1,5 +1,7 @@ package seedu.address.model; +import java.util.List; + import javafx.collections.ObservableList; import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; @@ -16,7 +18,6 @@ public interface ReadOnlyAddressBook { ObservableList getPersonList(); ObservableList getModuleList(); - boolean hasModule(ModuleCode moduleCode); void addModule(ModuleCode moduleCode); } diff --git a/src/main/java/seedu/address/model/module/ModuleCode.java b/src/main/java/seedu/address/model/module/ModuleCode.java index 7f14742f20c..ad41ea442ee 100644 --- a/src/main/java/seedu/address/model/module/ModuleCode.java +++ b/src/main/java/seedu/address/model/module/ModuleCode.java @@ -120,6 +120,7 @@ public boolean hasTutorialClass(TutorialClass tutorialString) { return false; } + /** * Adds an empty tutorial with the given name into the module. * diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index ba9293c186a..5288e6a59ca 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -4,7 +4,6 @@ import static seedu.address.commons.util.CollectionUtil.requireAllNonNull; import java.util.ArrayList; -import java.util.List; import seedu.address.model.person.Person; @@ -26,17 +25,36 @@ public class TutorialClass { public final String value; private final ArrayList students; + public TutorialClass() { + this.value = ""; // Default value for 'value' + this.students = new ArrayList<>(); // Initialize students list + } + + /** * A constructor for TutorialClass. Creates an empty tutorial class with no students. * - * @param value of tutorial to be added + * @param name of tutorial to be added */ - public TutorialClass(String value) { - requireAllNonNull(value); - checkArgument(isValidTutorialClass(value), MESSAGE_CONSTRAINTS); - this.value = value; + public TutorialClass(String name) { + requireAllNonNull(name); + checkArgument(isValidTutorialClass(name), MESSAGE_CONSTRAINTS); + this.value = name; this.students = new ArrayList<>(); } + + /** + * A constructor for TutorialClass. Creates a tutorial with the list of students specified. + * + * @param name of tutorial to be added + * @param students to be in the added tutorial + */ + public TutorialClass(String name, ArrayList students) { + requireAllNonNull(name); + checkArgument(isValidTutorialClass(name), MESSAGE_CONSTRAINTS); + this.value = name; + this.students = students; + } /** * Returns true if a given string is a valid tutorial class code. */ @@ -49,11 +67,6 @@ public String toString() { return value; } - public List getStudents() { - return List.copyOf(students); - } - - @Override public boolean equals(Object other) { if (other == this) { diff --git a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java index eb8bb074532..3b66418affb 100644 --- a/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java +++ b/src/main/java/seedu/address/storage/JsonSerializableAddressBook.java @@ -18,12 +18,11 @@ * An Immutable AddressBook that is serializable to JSON format. */ @JsonRootName(value = "addressbook") -public class JsonSerializableAddressBook { +class JsonSerializableAddressBook { public static final String MESSAGE_DUPLICATE_PERSON = "Persons list contains duplicate person(s)."; public static final String MESSAGE_DUPLICATE_MODULE = "Modules list contains duplicate module(s)."; - private final List persons = new ArrayList<>(); private final List modules = new ArrayList<>(); @@ -74,4 +73,5 @@ public AddressBook toModelType() throws IllegalValueException { } return addressBook; } + } diff --git a/src/main/java/seedu/address/ui/MainWindow.java b/src/main/java/seedu/address/ui/MainWindow.java index d74acfebc5a..bd54605911e 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.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.MenuItem; @@ -17,6 +19,7 @@ import seedu.address.logic.commands.ListClassesCommand; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.module.ModuleCode; /** * The Main Window. Provides the basic application layout containing @@ -140,7 +143,9 @@ private void switchToPersonListPanel() { } private void switchToModuleListPanel() { - moduleListPanel = new ModuleListPanel(logic.getFilteredModuleList()); + ObservableList moduleObservableList = FXCollections + .observableList(logic.getAddressBook().getModuleList()); + moduleListPanel = new ModuleListPanel(moduleObservableList); moduleListPanelPlaceholder.getChildren().add(moduleListPanel.getRoot()); } diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index 91ba0a8f1e8..188c9058d20 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -5,49 +5,43 @@ import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.JsonUtil; import seedu.address.model.AddressBook; -import seedu.address.model.module.ModuleCode; import seedu.address.testutil.TypicalPersons; public class JsonSerializableAddressBookTest { private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonSerializableAddressBookTest"); private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); + private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); + private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); @Test public void toModelType_typicalPersonsFile_success() throws Exception { JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE, - JsonSerializableAddressBook.class).get(); + JsonSerializableAddressBook.class).get(); AddressBook addressBookFromFile = dataFromFile.toModelType(); AddressBook typicalPersonsAddressBook = TypicalPersons.getTypicalAddressBook(); assertEquals(addressBookFromFile, typicalPersonsAddressBook); } @Test - public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { - List validPersons = new ArrayList<>(); - validPersons.add(new JsonAdaptedPerson(TypicalPersons.ALICE)); - validPersons.add(new JsonAdaptedPerson(TypicalPersons.ALICE)); // Duplicate person - JsonSerializableAddressBook data = new JsonSerializableAddressBook(validPersons, new ArrayList<>()); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook - .MESSAGE_DUPLICATE_PERSON, data::toModelType); + public void toModelType_invalidPersonFile_throwsIllegalValueException() throws Exception { + JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(INVALID_PERSON_FILE, + JsonSerializableAddressBook.class).get(); + assertThrows(IllegalValueException.class, dataFromFile::toModelType); } @Test - public void toModelType_duplicateModules_throwsIllegalValueException() throws Exception { - List validModules = new ArrayList<>(); - validModules.add(new JsonAdaptedModule(new ModuleCode("CS1010"))); - validModules.add(new JsonAdaptedModule(new ModuleCode("CS1010"))); // Duplicate module - JsonSerializableAddressBook data = new JsonSerializableAddressBook(new ArrayList<>(), validModules); - assertThrows(IllegalValueException.class, JsonSerializableAddressBook - .MESSAGE_DUPLICATE_MODULE, data::toModelType); + public void toModelType_duplicatePersons_throwsIllegalValueException() throws Exception { + JsonSerializableAddressBook dataFromFile = JsonUtil.readJsonFile(DUPLICATE_PERSON_FILE, + JsonSerializableAddressBook.class).get(); + assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, + dataFromFile::toModelType); } -} +} From f5322720a8d22d4599c285cc7b4d282f828340c3 Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 17:06:17 +0800 Subject: [PATCH 05/21] Checkstyle --- .../java/seedu/address/model/ReadOnlyAddressBook.java | 2 -- .../java/seedu/address/model/module/TutorialClass.java | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java index 46ce73328bd..1b7eb6e50cb 100644 --- a/src/main/java/seedu/address/model/ReadOnlyAddressBook.java +++ b/src/main/java/seedu/address/model/ReadOnlyAddressBook.java @@ -1,7 +1,5 @@ package seedu.address.model; -import java.util.List; - import javafx.collections.ObservableList; import seedu.address.model.module.ModuleCode; import seedu.address.model.person.Person; diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index 5288e6a59ca..3d885afd4a7 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -24,10 +24,13 @@ public class TutorialClass { public final String value; private final ArrayList students; - + /** + * Constructs a {@code TutorialClass} with default values. + * Initializes the {@code value} field to an empty string and creates an empty list for {@code students}. + */ public TutorialClass() { - this.value = ""; // Default value for 'value' - this.students = new ArrayList<>(); // Initialize students list + this.value = ""; + this.students = new ArrayList<>(); } From 1cacf2ba9e3e9900b233ff090d677dc97587206b Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 17:41:16 +0800 Subject: [PATCH 06/21] Add test classes --- .../address/model/module/TutorialClass.java | 4 ++ .../typicalModuleAddressBook.json | 17 ++++++ .../seedu/address/logic/LogicManagerTest.java | 34 +++++++++++ .../model/module/TutorialClassTest.java | 56 ++++++++++++++++++- .../JsonSerializableAddressBookTest.java | 18 ++++++ 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index 3d885afd4a7..30121adf719 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -89,4 +89,8 @@ public boolean equals(Object other) { public int hashCode() { return value.hashCode(); } + + public ArrayList getStudents() { + return students; + } } diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json new file mode 100644 index 00000000000..fba68ad519f --- /dev/null +++ b/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json @@ -0,0 +1,17 @@ +{ + "_comment": "AddressBook save file which contains the same Module values as in TypicalModules#getTypicalAddressBook()", + "modules": [ + { + "moduleCode": "CS2103T", + "tutorialClass": "T01" + }, + { + "moduleCode": "CS2101", + "tutorialClass": "T02" + }, + { + "moduleCode": "MA1521", + "tutorialClass": "T03" + } + ] +} \ No newline at end of file diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 0869b083347..7eed67bb7c3 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -1,6 +1,8 @@ package seedu.address.logic; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; @@ -19,6 +21,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import seedu.address.commons.core.GuiSettings; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.ListCommand; @@ -172,4 +175,35 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath) expectedModel.addPerson(expectedPerson); assertCommandFailure(addCommand, CommandException.class, expectedMessage, expectedModel); } + @Test + public void getAddressBook_modifyList_throwsUnsupportedOperationException() { + assertThrows(UnsupportedOperationException.class, () -> logic.getAddressBook().getPersonList().remove(0)); + } + + @Test + public void getAddressBookFilePath() { + assertEquals(model.getAddressBookFilePath(), logic.getAddressBookFilePath()); + } + + @Test + public void getGuiSettings() { + assertEquals(model.getGuiSettings(), logic.getGuiSettings()); + } + + @Test + public void setGuiSettings() { + GuiSettings newGuiSettings = new GuiSettings(1000, 600, 0, 0); + logic.setGuiSettings(newGuiSettings); + assertEquals(newGuiSettings, logic.getGuiSettings()); + } + + @Test + public void isInitialModuleListPanelDisplayed_emptyAddressBook_returnsFalse() { + assertFalse(logic.isInitialModuleListPanelDisplayed()); + } + @Test + public void isInitialModuleListPanelDisplayed_nonEmptyAddressBook_returnsTrue() { + model.addPerson(new PersonBuilder().build()); + assertFalse(logic.isInitialModuleListPanelDisplayed()); + } } diff --git a/src/test/java/seedu/address/model/module/TutorialClassTest.java b/src/test/java/seedu/address/model/module/TutorialClassTest.java index 0bcb356330d..84cc04ed723 100644 --- a/src/test/java/seedu/address/model/module/TutorialClassTest.java +++ b/src/test/java/seedu/address/model/module/TutorialClassTest.java @@ -3,9 +3,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static seedu.address.model.module.TutorialClass.isValidTutorialClass; - +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; import org.junit.jupiter.api.Test; +import seedu.address.model.person.Email; +import seedu.address.model.person.Name; +import seedu.address.model.person.Person; +import seedu.address.model.person.StudentId; +import seedu.address.model.tag.Tag; public class TutorialClassTest { @@ -48,4 +57,49 @@ void testToString_success() { TutorialClass tutorial = new TutorialClass(VALID_TUTORIAL); assertEquals(tutorial.toString(), VALID_TUTORIAL); } + + @Test + void testEmptyConstructor() { + TutorialClass tutorialClass = new TutorialClass(); + assertEquals("", tutorialClass.value); + try { + Field field = TutorialClass.class.getDeclaredField("students"); + field.setAccessible(true); // Allow access to private field + Object value = field.get(tutorialClass); // Get the value of the field + assertTrue(((ArrayList) value).isEmpty()); // Check if it's empty + } catch (NoSuchFieldException | IllegalAccessException e) { + fail("Exception thrown while accessing private field: " + e.getMessage()); + } + } + + @Test + void testConstructorWithStudents() { + ArrayList students = new ArrayList<>(); + + // Creating Person objects + Name name1 = new Name("John"); + Email email1 = new Email("john@example.com"); + StudentId stuId1 = new StudentId("A0213333J"); + ModuleCode module1 = new ModuleCode("CS2103"); + TutorialClass tutorial1 = new TutorialClass("T01"); + Set tags1 = new HashSet<>(); + Person student1 = new Person(name1, email1, stuId1, module1, tutorial1, tags1); + + Name name2 = new Name("Alice"); + Email email2 = new Email("alice@example.com"); + StudentId stuId2 = new StudentId("A0145678A"); + ModuleCode module2 = new ModuleCode("CS2101"); + TutorialClass tutorial2 = new TutorialClass("T02"); + Set tags2 = new HashSet<>(); + Person student2 = new Person(name2, email2, stuId2, module2, tutorial2, tags2); + + students.add(student1); + students.add(student2); + + TutorialClass tutorialClass = new TutorialClass(VALID_TUTORIAL, students); + assertEquals(VALID_TUTORIAL, tutorialClass.value); + assertEquals(2, tutorialClass.getStudents().size()); // Accessing students via getter + assertTrue(tutorialClass.getStudents().contains(student1)); + assertTrue(tutorialClass.getStudents().contains(student2)); + } } diff --git a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java index 188c9058d20..f93c54f3416 100644 --- a/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java +++ b/src/test/java/seedu/address/storage/JsonSerializableAddressBookTest.java @@ -1,16 +1,20 @@ package seedu.address.storage; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.testutil.Assert.assertThrows; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import org.junit.jupiter.api.Test; import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.commons.util.JsonUtil; import seedu.address.model.AddressBook; +import seedu.address.model.module.ModuleCode; import seedu.address.testutil.TypicalPersons; public class JsonSerializableAddressBookTest { @@ -19,6 +23,7 @@ public class JsonSerializableAddressBookTest { private static final Path TYPICAL_PERSONS_FILE = TEST_DATA_FOLDER.resolve("typicalPersonsAddressBook.json"); private static final Path INVALID_PERSON_FILE = TEST_DATA_FOLDER.resolve("invalidPersonAddressBook.json"); private static final Path DUPLICATE_PERSON_FILE = TEST_DATA_FOLDER.resolve("duplicatePersonAddressBook.json"); + private static final Path TYPICAL_MODULES_FILE = TEST_DATA_FOLDER.resolve("typicalModulesAddressBook.json"); @Test public void toModelType_typicalPersonsFile_success() throws Exception { @@ -43,5 +48,18 @@ public void toModelType_duplicatePersons_throwsIllegalValueException() throws Ex assertThrows(IllegalValueException.class, JsonSerializableAddressBook.MESSAGE_DUPLICATE_PERSON, dataFromFile::toModelType); } + @Test + public void toModelType_nullModuleList_throwsIllegalValueException() { + JsonSerializableAddressBook data = new JsonSerializableAddressBook(new ArrayList<>(), null); + assertDoesNotThrow(data::toModelType); + } + @Test + public void toModelType_duplicateModules_throwsIllegalValueException() { + List modules = new ArrayList<>(); + modules.add(new JsonAdaptedModule(new ModuleCode("CS1010"))); + modules.add(new JsonAdaptedModule(new ModuleCode("CS1010"))); + JsonSerializableAddressBook data = new JsonSerializableAddressBook(new ArrayList<>(), modules); + assertThrows(IllegalValueException.class, data::toModelType); + } } From 7db9c7c33f910ea29e9dd76839c7812cd9188a3f Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 17:43:38 +0800 Subject: [PATCH 07/21] Checkstyle --- src/test/java/seedu/address/logic/LogicManagerTest.java | 1 - .../java/seedu/address/model/module/TutorialClassTest.java | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index 7eed67bb7c3..ebcce7b8af2 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -2,7 +2,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY; diff --git a/src/test/java/seedu/address/model/module/TutorialClassTest.java b/src/test/java/seedu/address/model/module/TutorialClassTest.java index 84cc04ed723..0e17471381a 100644 --- a/src/test/java/seedu/address/model/module/TutorialClassTest.java +++ b/src/test/java/seedu/address/model/module/TutorialClassTest.java @@ -5,11 +5,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static seedu.address.model.module.TutorialClass.isValidTutorialClass; + import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; + import org.junit.jupiter.api.Test; + import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; From bf17b5f4446c97323d141da7da7e5f4c500f2fd4 Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 17:48:52 +0800 Subject: [PATCH 08/21] Checkstyle --- .../typicalModuleAddressBook.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json b/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json index fba68ad519f..421452adbb7 100644 --- a/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json +++ b/src/test/data/JsonSerializableAddressBookTest/typicalModuleAddressBook.json @@ -11,7 +11,7 @@ }, { "moduleCode": "MA1521", - "tutorialClass": "T03" + "tutorialClass": "T04" } ] -} \ No newline at end of file +} From 041a83b66956a2aca53b3c1e3cb6b3b17916129a Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 18:04:56 +0800 Subject: [PATCH 09/21] Add Test Case --- .../address/storage/StorageManagerTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/test/java/seedu/address/storage/StorageManagerTest.java b/src/test/java/seedu/address/storage/StorageManagerTest.java index 8a28214409f..8b1025ee576 100644 --- a/src/test/java/seedu/address/storage/StorageManagerTest.java +++ b/src/test/java/seedu/address/storage/StorageManagerTest.java @@ -15,6 +15,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.UserPrefs; +import seedu.address.model.module.ModuleCode; public class StorageManagerTest { @@ -85,4 +86,22 @@ public void readAddressBook_withModulesWithoutModuleList_addsModulesToList() thr assertTrue(retrieved.getModuleList().isEmpty()); } + @Test + public void readAddressBook_addsModulesToListIfNotPresent() throws Exception { + AddressBook addressBook = new AddressBook(); + // Add some modules to the address book + addressBook.addModule(new ModuleCode("CS1010")); + addressBook.addModule(new ModuleCode("MA1505")); + + JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(getTempFilePath("ab")); + StorageManager storageManager = new StorageManager(addressBookStorage, + new JsonUserPrefsStorage(getTempFilePath("prefs"))); + storageManager.saveAddressBook(addressBook); + + ReadOnlyAddressBook retrieved = storageManager.readAddressBook().get(); + // Check if modules are added correctly + assertTrue(retrieved.hasModule(new ModuleCode("CS1010"))); + assertTrue(retrieved.hasModule(new ModuleCode("MA1505"))); + } + } From 3fb66d56cdedb698475f82591aa800de58cc7ce8 Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 18:21:57 +0800 Subject: [PATCH 10/21] More test cases --- .../java/seedu/address/ui/ModuleCard.java | 7 ++- .../seedu/address/ui/ModuleListPanel.java | 2 +- .../java/seedu/address/ui/ModuleCardTest.java | 39 +++++++++++++++ .../seedu/address/ui/ModuleListPanelTest.java | 48 +++++++++++++++++++ 4 files changed, 91 insertions(+), 5 deletions(-) create mode 100644 src/test/java/seedu/address/ui/ModuleCardTest.java create mode 100644 src/test/java/seedu/address/ui/ModuleListPanelTest.java diff --git a/src/main/java/seedu/address/ui/ModuleCard.java b/src/main/java/seedu/address/ui/ModuleCard.java index fa98fda17d2..88e30bd7fa8 100644 --- a/src/main/java/seedu/address/ui/ModuleCard.java +++ b/src/main/java/seedu/address/ui/ModuleCard.java @@ -14,13 +14,12 @@ public class ModuleCard extends UiPart { private static final String FXML = "ModuleCard.fxml"; public final ModuleCode moduleCode; - @FXML - private HBox cardPane; + protected Label moduleCodeLabel; @FXML - private Label moduleCodeLabel; + protected Label tutorialClassLabel; @FXML - private Label tutorialClassLabel; + private HBox cardPane; /** * Creates a {@code ModuleCard} with the given {@code Module}. diff --git a/src/main/java/seedu/address/ui/ModuleListPanel.java b/src/main/java/seedu/address/ui/ModuleListPanel.java index 4d5a8679131..5e9e03e9bf4 100644 --- a/src/main/java/seedu/address/ui/ModuleListPanel.java +++ b/src/main/java/seedu/address/ui/ModuleListPanel.java @@ -14,7 +14,7 @@ public class ModuleListPanel extends UiPart { private static final String FXML = "ModuleListPanel.fxml"; @FXML - private ListView moduleListView; + protected ListView moduleListView; /** * Creates a {@code ModuleListPanel} with the given {@code ObservableList}. diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java new file mode 100644 index 00000000000..a3069e5e41c --- /dev/null +++ b/src/test/java/seedu/address/ui/ModuleCardTest.java @@ -0,0 +1,39 @@ +package seedu.address.ui; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javafx.embed.swing.JFXPanel; +import seedu.address.model.module.ModuleCode; + +public class ModuleCardTest { + + private ModuleCode moduleCode; + private ModuleCard moduleCard; + + @BeforeAll + public static void initJavaFX() { + // Initialize JavaFX toolkit + new JFXPanel(); + } + + @BeforeEach + public void setUp() { + moduleCode = new ModuleCode("CS2103"); + moduleCard = new ModuleCard(moduleCode); + } + + @Test + public void constructor_validModuleCode_displayCorrectModuleCode() { + assertEquals("CS2103", moduleCard.moduleCodeLabel.getText()); + } + + @Test + public void constructor_validModuleCode_displayCorrectTutorialClass() { + assertEquals("[]", moduleCard.tutorialClassLabel.getText()); + } +} + diff --git a/src/test/java/seedu/address/ui/ModuleListPanelTest.java b/src/test/java/seedu/address/ui/ModuleListPanelTest.java new file mode 100644 index 00000000000..7843469e551 --- /dev/null +++ b/src/test/java/seedu/address/ui/ModuleListPanelTest.java @@ -0,0 +1,48 @@ +package seedu.address.ui; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.embed.swing.JFXPanel; +import seedu.address.model.module.ModuleCode; + +public class ModuleListPanelTest { + + private ModuleListPanel moduleListPanel; + private ObservableList moduleCodes; + + @BeforeAll + public static void initToolkit() { + new JFXPanel(); // Initializes the JavaFX Toolkit + } + @BeforeEach + public void setUp() { + moduleCodes = FXCollections.observableArrayList(); + moduleListPanel = new ModuleListPanel(moduleCodes); + } + + @Test + public void constructor_withListOfModuleCodes_initializesListView() { + assertNotNull(moduleListPanel.moduleListView); + } + + @Test + public void constructor_withListOfModuleCodes_setsCellFactory() { + assertNotNull(moduleListPanel.moduleListView.getCellFactory()); + } + + @Test + public void constructor_withListOfModuleCodes_displaysCorrectModuleCards() { + moduleCodes.add(new ModuleCode("CS2103")); + assertEquals(1, moduleListPanel.moduleListView.getItems().size()); + // Add more assertions as needed + } + + // Add more test cases as needed +} From 80b5bf2c3cad7429df45b40fc304a9bb2c2118fe Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 21:17:42 +0800 Subject: [PATCH 11/21] Remove test case causing build to slow down --- .../java/seedu/address/ui/ModuleCardTest.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/test/java/seedu/address/ui/ModuleCardTest.java diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java deleted file mode 100644 index a3069e5e41c..00000000000 --- a/src/test/java/seedu/address/ui/ModuleCardTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package seedu.address.ui; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import javafx.embed.swing.JFXPanel; -import seedu.address.model.module.ModuleCode; - -public class ModuleCardTest { - - private ModuleCode moduleCode; - private ModuleCard moduleCard; - - @BeforeAll - public static void initJavaFX() { - // Initialize JavaFX toolkit - new JFXPanel(); - } - - @BeforeEach - public void setUp() { - moduleCode = new ModuleCode("CS2103"); - moduleCard = new ModuleCard(moduleCode); - } - - @Test - public void constructor_validModuleCode_displayCorrectModuleCode() { - assertEquals("CS2103", moduleCard.moduleCodeLabel.getText()); - } - - @Test - public void constructor_validModuleCode_displayCorrectTutorialClass() { - assertEquals("[]", moduleCard.tutorialClassLabel.getText()); - } -} - From d3d0542117ef7bb61de9df850749c7216d5b232a Mon Sep 17 00:00:00 2001 From: qinxutan Date: Mon, 18 Mar 2024 21:31:07 +0800 Subject: [PATCH 12/21] Remove test class causing build to slow down --- .../seedu/address/ui/ModuleListPanel.java | 1 - .../seedu/address/ui/ModuleListPanelTest.java | 48 ------------------- 2 files changed, 49 deletions(-) delete mode 100644 src/test/java/seedu/address/ui/ModuleListPanelTest.java diff --git a/src/main/java/seedu/address/ui/ModuleListPanel.java b/src/main/java/seedu/address/ui/ModuleListPanel.java index 5e9e03e9bf4..db01e7be98d 100644 --- a/src/main/java/seedu/address/ui/ModuleListPanel.java +++ b/src/main/java/seedu/address/ui/ModuleListPanel.java @@ -42,4 +42,3 @@ protected void updateItem(ModuleCode moduleCode, boolean empty) { } } } - diff --git a/src/test/java/seedu/address/ui/ModuleListPanelTest.java b/src/test/java/seedu/address/ui/ModuleListPanelTest.java deleted file mode 100644 index 7843469e551..00000000000 --- a/src/test/java/seedu/address/ui/ModuleListPanelTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package seedu.address.ui; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.embed.swing.JFXPanel; -import seedu.address.model.module.ModuleCode; - -public class ModuleListPanelTest { - - private ModuleListPanel moduleListPanel; - private ObservableList moduleCodes; - - @BeforeAll - public static void initToolkit() { - new JFXPanel(); // Initializes the JavaFX Toolkit - } - @BeforeEach - public void setUp() { - moduleCodes = FXCollections.observableArrayList(); - moduleListPanel = new ModuleListPanel(moduleCodes); - } - - @Test - public void constructor_withListOfModuleCodes_initializesListView() { - assertNotNull(moduleListPanel.moduleListView); - } - - @Test - public void constructor_withListOfModuleCodes_setsCellFactory() { - assertNotNull(moduleListPanel.moduleListView.getCellFactory()); - } - - @Test - public void constructor_withListOfModuleCodes_displaysCorrectModuleCards() { - moduleCodes.add(new ModuleCode("CS2103")); - assertEquals(1, moduleListPanel.moduleListView.getItems().size()); - // Add more assertions as needed - } - - // Add more test cases as needed -} From 7f76907db4ae372129ff6d884012f3f263b94c0b Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 09:44:23 +0800 Subject: [PATCH 13/21] Add ModuleCardTest class --- .../java/seedu/address/ui/ModuleCardTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/test/java/seedu/address/ui/ModuleCardTest.java diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java new file mode 100644 index 00000000000..17d5c388814 --- /dev/null +++ b/src/test/java/seedu/address/ui/ModuleCardTest.java @@ -0,0 +1,25 @@ +package seedu.address.ui; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import javafx.embed.swing.JFXPanel; +import seedu.address.model.module.ModuleCode; + +public class ModuleCardTest { + + @BeforeAll + public static void initializeJavaFX() { + // Initialize JavaFX toolkit + new JFXPanel(); + } + + @Test + public void constructor_validModuleCode_setsModuleCodeAndTutorialClasses() { + ModuleCode moduleCode = new ModuleCode("CS2103"); + ModuleCard moduleCard = new ModuleCard(moduleCode); + assertEquals(moduleCode, moduleCard.moduleCode); + assertEquals(moduleCode.value, moduleCard.moduleCodeLabel.getText()); + assertEquals(moduleCode.getTutorialClasses().toString(), moduleCard.tutorialClassLabel.getText()); + } +} From d580f748e2c135e7dc6edbf7930437b257d2312b Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 11:01:06 +0800 Subject: [PATCH 14/21] Update test case --- build.gradle | 4 +++- src/main/java/seedu/address/ui/ModuleCard.java | 1 - .../java/seedu/address/ui/JavaFxInitializer.java | 15 +++++++++++++++ .../java/seedu/address/ui/ModuleCardTest.java | 10 +--------- 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 src/test/java/seedu/address/ui/JavaFxInitializer.java diff --git a/build.gradle b/build.gradle index a2951cc709e..0d5f70093ad 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ task coverage(type: JacocoReport) { dependencies { String jUnitVersion = '5.4.0' String javaFxVersion = '17.0.7' + String mockitoVersion = '5.11.0' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' @@ -61,8 +62,9 @@ dependencies { implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: jUnitVersion - testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion + + testImplementation "org.mockito:mockito-core:$mockitoVersion" } shadowJar { diff --git a/src/main/java/seedu/address/ui/ModuleCard.java b/src/main/java/seedu/address/ui/ModuleCard.java index 88e30bd7fa8..6edd16cf214 100644 --- a/src/main/java/seedu/address/ui/ModuleCard.java +++ b/src/main/java/seedu/address/ui/ModuleCard.java @@ -20,7 +20,6 @@ public class ModuleCard extends UiPart { protected Label tutorialClassLabel; @FXML private HBox cardPane; - /** * Creates a {@code ModuleCard} with the given {@code Module}. */ diff --git a/src/test/java/seedu/address/ui/JavaFxInitializer.java b/src/test/java/seedu/address/ui/JavaFxInitializer.java new file mode 100644 index 00000000000..8f606099c96 --- /dev/null +++ b/src/test/java/seedu/address/ui/JavaFxInitializer.java @@ -0,0 +1,15 @@ +package seedu.address.ui; + +import org.junit.jupiter.api.BeforeAll; + +import javafx.embed.swing.JFXPanel; +/** + * The JavaFxInitializer class provides a method to initialize the JavaFX environment + * before running any JavaFX-related tests. + */ +public class JavaFxInitializer { + @BeforeAll + public static void initializeJavaFX() { + new JFXPanel(); // Initializes JavaFX environment + } +} diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java index 24d5085a03d..e2960adc202 100644 --- a/src/test/java/seedu/address/ui/ModuleCardTest.java +++ b/src/test/java/seedu/address/ui/ModuleCardTest.java @@ -2,19 +2,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import javafx.embed.swing.JFXPanel; import seedu.address.model.module.ModuleCode; -public class ModuleCardTest { - - @BeforeAll - public static void initializeJavaFX() { - // Initialize JavaFX toolkit - new JFXPanel(); - } +public class ModuleCardTest extends JavaFxInitializer { @Test public void constructor_validModuleCode_setsModuleCodeAndTutorialClasses() { From 6accac4f034d6c810cdda0f24312b0d16501893e Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 11:14:25 +0800 Subject: [PATCH 15/21] Update workflow to support test case --- .github/workflows/gradle.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 6ff220b5196..027bda12ce1 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -29,6 +29,18 @@ jobs: - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 + - name: Install Xvfb + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y xvfb + + - name: Start Xvfb + if: runner.os == 'Linux' + run: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & + + - name: Set DISPLAY variable + if: runner.os == 'Linux' + run: export DISPLAY=:99 + - name: Setup JDK 11 uses: actions/setup-java@v1 with: From c9455be1314ec6db5d28829b56531e3d67378c8d Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 11:50:25 +0800 Subject: [PATCH 16/21] Update workflow to support test case --- .github/workflows/gradle.yml | 36 ++++++++----------- build.gradle | 3 ++ .../java/seedu/address/ui/ModuleCardTest.java | 11 +++++- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 027bda12ce1..370d832ce0b 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -13,39 +13,31 @@ jobs: - name: Set up repository uses: actions/checkout@main - - name: Set up repository - uses: actions/checkout@main + - name: Set up JDK 11 + uses: actions/setup-java@v1 with: - ref: master - - - name: Merge to master - run: git checkout --progress --force ${{ github.sha }} - - - name: Run repository-wide tests - if: runner.os == 'Linux' - working-directory: ${{ github.workspace }}/.github - run: ./run-checks.sh - - - name: Validate Gradle Wrapper - uses: gradle/wrapper-validation-action@v1 + java-version: '11' + java-package: jdk+fx - - name: Install Xvfb + - name: Install Xvfb (for Linux only) if: runner.os == 'Linux' run: sudo apt-get update && sudo apt-get install -y xvfb - - name: Start Xvfb + - name: Start Xvfb (for Linux only) if: runner.os == 'Linux' run: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & - - name: Set DISPLAY variable + - name: Set DISPLAY environment variable (for Linux only) if: runner.os == 'Linux' run: export DISPLAY=:99 - - name: Setup JDK 11 - uses: actions/setup-java@v1 - with: - java-version: '11' - java-package: jdk+fx + - name: Run repository-wide tests + if: runner.os == 'Linux' + working-directory: ${{ github.workspace }}/.github + run: ./run-checks.sh + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 - name: Build and check with Gradle run: ./gradlew check coverage diff --git a/build.gradle b/build.gradle index 0d5f70093ad..997495b6ade 100644 --- a/build.gradle +++ b/build.gradle @@ -65,6 +65,9 @@ dependencies { testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: jUnitVersion testImplementation "org.mockito:mockito-core:$mockitoVersion" + + testImplementation 'org.testfx:testfx-junit5:4.0.16-alpha' + testImplementation 'org.testfx:testfx-core:4.0.16-alpha' } shadowJar { diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java index e2960adc202..aef056cee79 100644 --- a/src/test/java/seedu/address/ui/ModuleCardTest.java +++ b/src/test/java/seedu/address/ui/ModuleCardTest.java @@ -3,15 +3,24 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; +import org.testfx.framework.junit5.ApplicationTest; +import javafx.scene.layout.StackPane; import seedu.address.model.module.ModuleCode; -public class ModuleCardTest extends JavaFxInitializer { +public class ModuleCardTest extends ApplicationTest { @Test public void constructor_validModuleCode_setsModuleCodeAndTutorialClasses() { ModuleCode moduleCode = new ModuleCode("CS2103"); ModuleCard moduleCard = new ModuleCard(moduleCode); + + // Simulate adding the ModuleCard to a JavaFX scene + StackPane root = new StackPane(); + root.getChildren().add(moduleCard.getRoot()); + + // Interact with the JavaFX application on the JavaFX Application Thread + // Check if the UI components are initialized correctly assertEquals(moduleCode, moduleCard.moduleCode); assertEquals(moduleCode.value, moduleCard.moduleCodeLabel.getText()); assertEquals(moduleCode.getTutorialClasses().toString(), moduleCard.tutorialClassLabel.getText()); From b26b17f5abe9222175b66f0e3e095d84c63a186e Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 11:58:17 +0800 Subject: [PATCH 17/21] Update workflow to speed up test case --- .github/workflows/gradle.yml | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 370d832ce0b..96d80563736 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -13,32 +13,28 @@ jobs: - name: Set up repository uses: actions/checkout@main - - name: Set up JDK 11 - uses: actions/setup-java@v1 + - name: Set up repository + uses: actions/checkout@main with: - java-version: '11' - java-package: jdk+fx + ref: master - - name: Install Xvfb (for Linux only) - if: runner.os == 'Linux' - run: sudo apt-get update && sudo apt-get install -y xvfb - - - name: Start Xvfb (for Linux only) - if: runner.os == 'Linux' - run: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & - - - name: Set DISPLAY environment variable (for Linux only) - if: runner.os == 'Linux' - run: export DISPLAY=:99 + - name: Merge to master + run: git checkout --progress --force ${{ github.sha }} - name: Run repository-wide tests if: runner.os == 'Linux' - working-directory: ${{ github.workspace }}/.github + working-directory: ${{ github.workspace }}/.github run: ./run-checks.sh - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 + - name: Setup JDK 11 + uses: actions/setup-java@v1 + with: + java-version: '11' + java-package: jdk+fx + - name: Build and check with Gradle run: ./gradlew check coverage @@ -47,3 +43,5 @@ jobs: uses: codecov/codecov-action@v3 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + From af9021d207c8c7f5f87d4b575d2c431eeb6d8faa Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 12:05:33 +0800 Subject: [PATCH 18/21] Remove test case that is not running on linux --- .../java/seedu/address/ui/ModuleCardTest.java | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 src/test/java/seedu/address/ui/ModuleCardTest.java diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java deleted file mode 100644 index aef056cee79..00000000000 --- a/src/test/java/seedu/address/ui/ModuleCardTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package seedu.address.ui; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; -import org.testfx.framework.junit5.ApplicationTest; - -import javafx.scene.layout.StackPane; -import seedu.address.model.module.ModuleCode; - -public class ModuleCardTest extends ApplicationTest { - - @Test - public void constructor_validModuleCode_setsModuleCodeAndTutorialClasses() { - ModuleCode moduleCode = new ModuleCode("CS2103"); - ModuleCard moduleCard = new ModuleCard(moduleCode); - - // Simulate adding the ModuleCard to a JavaFX scene - StackPane root = new StackPane(); - root.getChildren().add(moduleCard.getRoot()); - - // Interact with the JavaFX application on the JavaFX Application Thread - // Check if the UI components are initialized correctly - assertEquals(moduleCode, moduleCard.moduleCode); - assertEquals(moduleCode.value, moduleCard.moduleCodeLabel.getText()); - assertEquals(moduleCode.getTutorialClasses().toString(), moduleCard.tutorialClassLabel.getText()); - } -} From 72e63f428e18510e90f1bcb1b55081e940e3d905 Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 13:16:42 +0800 Subject: [PATCH 19/21] Update Test Case --- .../java/seedu/address/ui/ModuleCardTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/java/seedu/address/ui/ModuleCardTest.java diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java new file mode 100644 index 00000000000..20f7cb545d3 --- /dev/null +++ b/src/test/java/seedu/address/ui/ModuleCardTest.java @@ -0,0 +1,26 @@ +package seedu.address.ui; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import javafx.embed.swing.JFXPanel; +import seedu.address.model.module.ModuleCode; + +public class ModuleCardTest { + + @BeforeAll + public static void initializeJavaFX() { + new JFXPanel(); + } + + @Test + public void constructor_validModuleCode_setsModuleCodeAndTutorialClasses() { + ModuleCode moduleCode = new ModuleCode("CS2103"); + ModuleCard moduleCard = new ModuleCard(moduleCode); + assertEquals(moduleCode, moduleCard.moduleCode); + assertEquals(moduleCode.value, moduleCard.moduleCodeLabel.getText()); + assertEquals(moduleCode.getTutorialClasses().toString(), moduleCard.tutorialClassLabel.getText()); + } +} From 32514cd5f9cf470152443a689c91e8ff7b40420f Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 13:20:32 +0800 Subject: [PATCH 20/21] Delete test cases --- .../java/seedu/address/ui/ModuleCardTest.java | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 src/test/java/seedu/address/ui/ModuleCardTest.java diff --git a/src/test/java/seedu/address/ui/ModuleCardTest.java b/src/test/java/seedu/address/ui/ModuleCardTest.java deleted file mode 100644 index 20f7cb545d3..00000000000 --- a/src/test/java/seedu/address/ui/ModuleCardTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package seedu.address.ui; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import javafx.embed.swing.JFXPanel; -import seedu.address.model.module.ModuleCode; - -public class ModuleCardTest { - - @BeforeAll - public static void initializeJavaFX() { - new JFXPanel(); - } - - @Test - public void constructor_validModuleCode_setsModuleCodeAndTutorialClasses() { - ModuleCode moduleCode = new ModuleCode("CS2103"); - ModuleCard moduleCard = new ModuleCard(moduleCode); - assertEquals(moduleCode, moduleCard.moduleCode); - assertEquals(moduleCode.value, moduleCard.moduleCodeLabel.getText()); - assertEquals(moduleCode.getTutorialClasses().toString(), moduleCard.tutorialClassLabel.getText()); - } -} From 1488ea149ed280add77246cd12ab4370c96160f1 Mon Sep 17 00:00:00 2001 From: qinxutan Date: Tue, 19 Mar 2024 15:06:46 +0800 Subject: [PATCH 21/21] Resolve merge conflict --- src/main/java/seedu/address/model/module/TutorialClass.java | 2 +- src/main/java/seedu/address/ui/ModuleCard.java | 2 +- .../java/seedu/address/model/module/TutorialClassTest.java | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/seedu/address/model/module/TutorialClass.java b/src/main/java/seedu/address/model/module/TutorialClass.java index bac5d00d98f..2598f4386a7 100644 --- a/src/main/java/seedu/address/model/module/TutorialClass.java +++ b/src/main/java/seedu/address/model/module/TutorialClass.java @@ -29,7 +29,7 @@ public class TutorialClass { * Initializes the {@code value} field to an empty string and creates an empty list for {@code students}. */ public TutorialClass() { - this.value = ""; + this.tutorialName = ""; this.students = new ArrayList<>(); } diff --git a/src/main/java/seedu/address/ui/ModuleCard.java b/src/main/java/seedu/address/ui/ModuleCard.java index 6edd16cf214..521b5938f54 100644 --- a/src/main/java/seedu/address/ui/ModuleCard.java +++ b/src/main/java/seedu/address/ui/ModuleCard.java @@ -26,7 +26,7 @@ public class ModuleCard extends UiPart { public ModuleCard(ModuleCode moduleCode) { super(FXML); this.moduleCode = moduleCode; - moduleCodeLabel.setText(moduleCode.value); + moduleCodeLabel.setText(moduleCode.getModule().toString()); tutorialClassLabel.setText(moduleCode.getTutorialClasses().toString()); } } diff --git a/src/test/java/seedu/address/model/module/TutorialClassTest.java b/src/test/java/seedu/address/model/module/TutorialClassTest.java index 4b014b199a5..3ffa1438963 100644 --- a/src/test/java/seedu/address/model/module/TutorialClassTest.java +++ b/src/test/java/seedu/address/model/module/TutorialClassTest.java @@ -105,7 +105,7 @@ void testToString_success() { @Test void testEmptyConstructor() { TutorialClass tutorialClass = new TutorialClass(); - assertEquals("", tutorialClass.value); + assertEquals("", tutorialClass.getTutorialClass().toString()); try { Field field = TutorialClass.class.getDeclaredField("students"); field.setAccessible(true); // Allow access to private field @@ -137,7 +137,7 @@ void testConstructorWithStudents() { students.add(student2); TutorialClass tutorialClass = new TutorialClass(VALID_TUTORIAL, students); - assertEquals(VALID_TUTORIAL, tutorialClass.value); + assertEquals(VALID_TUTORIAL, tutorialClass.getTutorialClass().toString()); assertEquals(2, tutorialClass.getStudents().size()); // Accessing students via getter assertTrue(tutorialClass.getStudents().contains(student1)); assertTrue(tutorialClass.getStudents().contains(student2));