From fe80e5dafc7c455e90d8f6fdded84e9975f5e438 Mon Sep 17 00:00:00 2001 From: feifeiraindrops Date: Mon, 13 Nov 2023 20:08:39 +0800 Subject: [PATCH] Add test to listAll --- .../logic/commands/ListAllCommand.java | 13 +++++ .../logic/commands/ListAllCommandTest.java | 55 +++++++++++++++++++ .../parser/ListAllCommandParserTest.java | 22 ++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/test/java/seedu/modulight/logic/commands/ListAllCommandTest.java create mode 100644 src/test/java/seedu/modulight/logic/parser/ListAllCommandParserTest.java diff --git a/src/main/java/seedu/modulight/logic/commands/ListAllCommand.java b/src/main/java/seedu/modulight/logic/commands/ListAllCommand.java index 99e87ac6a19..80b95668e4b 100644 --- a/src/main/java/seedu/modulight/logic/commands/ListAllCommand.java +++ b/src/main/java/seedu/modulight/logic/commands/ListAllCommand.java @@ -27,4 +27,17 @@ public CommandResult execute(Model model) { model.updateFilteredStudentScoreList(PREDICATE_SHOW_ALL_STUDENT_SCORES); return new CommandResult(MESSAGE_SUCCESS); } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof ListAllCommand)) { + return false; + } + return true; + } } diff --git a/src/test/java/seedu/modulight/logic/commands/ListAllCommandTest.java b/src/test/java/seedu/modulight/logic/commands/ListAllCommandTest.java new file mode 100644 index 00000000000..8bb95dbe23f --- /dev/null +++ b/src/test/java/seedu/modulight/logic/commands/ListAllCommandTest.java @@ -0,0 +1,55 @@ +package seedu.modulight.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.modulight.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.modulight.testutil.TypicalStudents.getTypicalComponentBook; +import static seedu.modulight.testutil.TypicalStudents.getTypicalScoreBook; +import static seedu.modulight.testutil.TypicalStudents.getTypicalStudentBook; + +import org.junit.jupiter.api.Test; + +import seedu.modulight.model.Model; +import seedu.modulight.model.ModelManager; +import seedu.modulight.model.UserPrefs; + +public class ListAllCommandTest { + private Model model = new ModelManager(getTypicalStudentBook(), getTypicalScoreBook(), getTypicalComponentBook(), + new UserPrefs()); + private Model expectedModel = new ModelManager(getTypicalStudentBook(), getTypicalScoreBook(), + getTypicalComponentBook(), new UserPrefs()); + @Test + public void excute_nonFiltered_success() { + ListAllCommand command = new ListAllCommand(); + String expectedMessage = "Listed all students, student scores and graded components"; + assertCommandSuccess(command, model, expectedMessage, expectedModel); + } + + @Test + public void excute_filtered_success() { + ListAllCommand command = new ListAllCommand(); + model.updateFilteredStudentList(Model.PREDICATE_SHOW_NO_STUDENTS); + model.updateFilteredGradedComponentList(Model.PREDICATE_SHOW_NO_COMPONENT); + String expectedMessage = "Listed all students, student scores and graded components"; + assertCommandSuccess(command, model, expectedMessage, expectedModel); + } + + @Test + public void equals() { + + ListAllCommand firstCommand = new ListAllCommand(); + ListAllCommand secondCommand = new ListAllCommand(); + + // same object -> returns true + assertTrue(firstCommand.equals(firstCommand)); + + // same type -> returns true + assertTrue(firstCommand.equals(secondCommand)); + + // different types -> returns false + assertFalse(firstCommand.equals(1)); + + // null -> returns false + assertFalse(firstCommand.equals(null)); + } +} diff --git a/src/test/java/seedu/modulight/logic/parser/ListAllCommandParserTest.java b/src/test/java/seedu/modulight/logic/parser/ListAllCommandParserTest.java new file mode 100644 index 00000000000..c3ae8724c48 --- /dev/null +++ b/src/test/java/seedu/modulight/logic/parser/ListAllCommandParserTest.java @@ -0,0 +1,22 @@ +package seedu.modulight.logic.parser; + +import static seedu.modulight.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.modulight.logic.commands.ListAllCommand; + +public class ListAllCommandParserTest { + private ListAllCommandParser parser = new ListAllCommandParser(); + @Test + public void parse_noInput_success() { + ListAllCommand expectedCommand = new ListAllCommand(); + assertParseSuccess(parser, " ", expectedCommand); + } + + @Test + public void parse_withInput_success() { + ListAllCommand expectedCommand = new ListAllCommand(); + assertParseSuccess(parser, " t/t01 ", expectedCommand); + } +}