diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index f40979b9e57..9e33a96bd61 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -1,5 +1,6 @@ package seedu.address.logic.commands; +import static java.util.Objects.requireNonNull; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -11,6 +12,7 @@ import static seedu.address.testutil.TypicalModules.getTypicalModuleData; import static seedu.address.testutil.TypicalModules.getTypicalModulePlan; +import java.util.ArrayList; import java.util.Arrays; import org.junit.jupiter.api.Test; @@ -21,9 +23,9 @@ import seedu.address.model.UserPrefs; import seedu.address.model.module.Module; import seedu.address.model.module.ModuleCode; +import seedu.address.model.module.exceptions.DuplicateModuleException; import seedu.address.model.module.exceptions.ModuleNotFoundException; -import seedu.address.testutil.ModelStubAcceptingModuleAdded; -import seedu.address.testutil.ModelStubWithModule; +import seedu.address.testutil.ModelStub; import seedu.address.testutil.ModuleBuilder; import seedu.address.testutil.TypicalModules; @@ -59,7 +61,7 @@ public void execute_moduleAcceptedByModel_deleteSuccessful() { @Test public void execute_moduleInDataAndInPlan_deleteSuccessful() throws Exception { //In both ModuleData and ModulePlan -> Success - ModelStubAcceptingModuleAdded modelStub = new ModelStubAcceptingModuleAdded(); + ModelStubAcceptingModuleAddedAndDelete modelStub = new ModelStubAcceptingModuleAddedAndDelete(); modelStub.addModule(CS2030S); Module validModule = modelStub.getModuleFromDb(CS2030S.getModuleCode()); @@ -83,7 +85,7 @@ public void execute_moduleNotInModuleDataNotInModulePlan_throwsModuleNoteFoundEx @Test public void execute_missingModule_throwsModuleNotFoundException() { //In ModuleData and not in ModulePlan -> Fail - ModelStubAcceptingModuleAdded modelStub = new ModelStubAcceptingModuleAdded(); + ModelStubAcceptingModuleAddedAndDelete modelStub = new ModelStubAcceptingModuleAddedAndDelete(); modelStub.addModule(CS2100); Module validModule = modelStub.getModuleFromDb(CS2030S.getModuleCode()); @@ -126,4 +128,92 @@ public void toStringMethod() { String expected = DeleteCommand.class.getCanonicalName() + "{toDelete=" + code + "}"; assertEquals(expected, deleteCommand.toString()); } + + /** + * A Model stub that contains a single module. + */ + private class ModelStubWithModule extends ModelStub { + private final Module module; + + /** + * Initializes a ModelStubWithModule with the given module. + * + * @param module The module to be associated with the ModelStubWithModule. + */ + ModelStubWithModule(Module module) { + requireNonNull(module); + this.module = module; + } + + @Override + public boolean hasModule(Module module) { + requireNonNull(module); + return this.module.isSameModule(module); + } + + @Override + public boolean checkDbValidModuleCode(ModuleCode moduleCode) { + return getTypicalModuleData().checkDbValidModuleCode(moduleCode); + } + + @Override + public Module getModuleFromDb(ModuleCode moduleCode) { + return getTypicalModuleData().getModule(moduleCode); + } + } + + /** + * A Model stub that always accept the module being added. + */ + private class ModelStubAcceptingModuleAddedAndDelete extends ModelStub { + private final ArrayList modulesAdded = new ArrayList<>(); + + @Override + public void addModule(Module module) { + requireNonNull(module); + if (modulesAdded.contains(module)) { + throw new DuplicateModuleException(); + } + modulesAdded.add(module); + } + + @Override + public Module getModule(ModuleCode code) { + requireNonNull(code); + for (int i = 0; i < modulesAdded.size(); i++) { + if (modulesAdded.get(i).getModuleCode().equals(code)) { + return modulesAdded.get(i); + } + } + return null; + } + + @Override + public void deleteModule(Module module) { + if (!modulesAdded.contains(module)) { + throw new ModuleNotFoundException(); + } + modulesAdded.remove(module); + } + + @Override + public boolean hasModule(Module module) { + requireNonNull(module); + return modulesAdded.stream().anyMatch(module::isSameModule); + } + + @Override + public boolean checkDbValidModuleCode(ModuleCode moduleCode) { + return getTypicalModuleData().checkDbValidModuleCode(moduleCode); + } + + @Override + public Module getModuleFromDb(ModuleCode moduleCode) { + return getTypicalModuleData().getModule(moduleCode); + } + + public ArrayList getModulesAdded() { + return this.modulesAdded; + } + } } diff --git a/src/test/java/seedu/address/testutil/ModelStub.java b/src/test/java/seedu/address/testutil/ModelStub.java index d19703dd2fc..e4e0baca836 100644 --- a/src/test/java/seedu/address/testutil/ModelStub.java +++ b/src/test/java/seedu/address/testutil/ModelStub.java @@ -1,7 +1,5 @@ package seedu.address.testutil; -import static seedu.address.testutil.TypicalModules.getTypicalModuleData; - import java.nio.file.Path; import javafx.collections.ObservableList; @@ -110,11 +108,12 @@ public boolean checkDbValidModule(Module module) { @Override public boolean checkDbValidModuleCode(ModuleCode moduleCode) { - return getTypicalModuleData().checkDbValidModuleCode(moduleCode); + throw new AssertionError("This method should not be called."); } + @Override public Module getModuleFromDb(ModuleCode moduleCode) { - return getTypicalModuleData().getModule(moduleCode); + throw new AssertionError("This method should not be called."); } @Override diff --git a/src/test/java/seedu/address/testutil/ModelStubAcceptingModuleAdded.java b/src/test/java/seedu/address/testutil/ModelStubAcceptingModuleAdded.java deleted file mode 100644 index 4e39d2437d0..00000000000 --- a/src/test/java/seedu/address/testutil/ModelStubAcceptingModuleAdded.java +++ /dev/null @@ -1,55 +0,0 @@ -package seedu.address.testutil; - -import static java.util.Objects.requireNonNull; - -import java.util.ArrayList; - -import seedu.address.model.module.Module; -import seedu.address.model.module.ModuleCode; -import seedu.address.model.module.exceptions.DuplicateModuleException; -import seedu.address.model.module.exceptions.ModuleNotFoundException; - -/** - * A Model stub that always accept the module being added. - */ -public class ModelStubAcceptingModuleAdded extends ModelStub { - private final ArrayList modulesAdded = new ArrayList<>(); - - @Override - public void addModule(Module module) { - requireNonNull(module); - if (modulesAdded.contains(module)) { - throw new DuplicateModuleException(); - } - modulesAdded.add(module); - } - - @Override - public Module getModule(ModuleCode code) { - requireNonNull(code); - for (int i = 0; i < modulesAdded.size(); i++) { - if (modulesAdded.get(i).getModuleCode().equals(code)) { - return modulesAdded.get(i); - } - } - return null; - } - - @Override - public void deleteModule(Module module) { - if (!modulesAdded.contains(module)) { - throw new ModuleNotFoundException(); - } - modulesAdded.remove(module); - } - - @Override - public boolean hasModule(Module module) { - requireNonNull(module); - return modulesAdded.stream().anyMatch(module::isSameModule); - } - - public ArrayList getModulesAdded() { - return this.modulesAdded; - } -} diff --git a/src/test/java/seedu/address/testutil/ModelStubWithModule.java b/src/test/java/seedu/address/testutil/ModelStubWithModule.java deleted file mode 100644 index 13d932c5d71..00000000000 --- a/src/test/java/seedu/address/testutil/ModelStubWithModule.java +++ /dev/null @@ -1,28 +0,0 @@ -package seedu.address.testutil; - -import static java.util.Objects.requireNonNull; - -import seedu.address.model.module.Module; - -/** - * A Model stub that contains a single module. - */ -public class ModelStubWithModule extends ModelStub { - private final Module module; - - /** - * Initializes a ModelStubWithModule with the given module. - * - * @param module The module to be associated with the ModelStubWithModule. - */ - public ModelStubWithModule(Module module) { - requireNonNull(module); - this.module = module; - } - - @Override - public boolean hasModule(Module module) { - requireNonNull(module); - return this.module.isSameModule(module); - } -}