From 59f8e7b7f73fd0ea77e20a127bf54b8662e494bd Mon Sep 17 00:00:00 2001 From: "LAPTOP-NQHH6Q7K\\Juanpa" Date: Tue, 14 Nov 2023 01:47:44 +0800 Subject: [PATCH] Add test cases for List, Sort, and Reminder --- .../logic/commands/ReminderCommandTest.java | 53 +++++++++++++++++++ .../logic/commands/SortCommandTest.java | 46 +++++++++++++++- .../logic/parser/ListCommandParserTest.java | 6 +++ .../parser/ReminderCommandParserTest.java | 39 ++++++++++++++ .../logic/parser/SortCommandParserTest.java | 43 +++++++++++++++ 5 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/test/java/seedu/address/logic/commands/ReminderCommandTest.java create mode 100644 src/test/java/seedu/address/logic/parser/ReminderCommandParserTest.java create mode 100644 src/test/java/seedu/address/logic/parser/SortCommandParserTest.java diff --git a/src/test/java/seedu/address/logic/commands/ReminderCommandTest.java b/src/test/java/seedu/address/logic/commands/ReminderCommandTest.java new file mode 100644 index 00000000000..010f386e1db --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ReminderCommandTest.java @@ -0,0 +1,53 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalContacts.getTypicalAddressBook; + +import java.util.ArrayList; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.jobapplication.JobApplication; + +class ReminderCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void equals() { + ReminderCommand r = new ReminderCommand(true); + ReminderCommand r2 = new ReminderCommand(true); + ReminderCommand r3 = new ReminderCommand(false); + + assertEquals(r, r); + assertEquals(r, r2); + assertNotEquals(r, r3); + } + + @Test + public void execute_remindEarliest_applicationsSorted() { + String expectedMessage = ReminderCommand.MESSAGE_REMINDED_EARLIEST; + ReminderCommand command = new ReminderCommand(true); + expectedModel.updateSortedApplicationList(JobApplication.DEADLINE_COMPARATOR); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + ArrayList arrayList1 = new ArrayList<>(model.getDisplayedApplicationList()); + ArrayList arrayList2 = new ArrayList<>(expectedModel.getDisplayedApplicationList()); + assertEquals(arrayList1, arrayList2); + } + + @Test + public void execute_sortTitle_applicationsSorted() { + String expectedMessage = ReminderCommand.MESSAGE_REMINDED_LATEST; + ReminderCommand command = new ReminderCommand(false); + expectedModel.updateSortedApplicationList(JobApplication.DEADLINE_COMPARATOR.reversed()); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + ArrayList arrayList1 = new ArrayList<>(model.getDisplayedApplicationList()); + ArrayList arrayList2 = new ArrayList<>(expectedModel.getDisplayedApplicationList()); + assertEquals(arrayList1, arrayList2); + } +} diff --git a/src/test/java/seedu/address/logic/commands/SortCommandTest.java b/src/test/java/seedu/address/logic/commands/SortCommandTest.java index 727a2033043..ed453d8dcbc 100644 --- a/src/test/java/seedu/address/logic/commands/SortCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/SortCommandTest.java @@ -2,17 +2,25 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalContacts.getTypicalAddressBook; +import java.util.ArrayList; import java.util.Comparator; import org.junit.jupiter.api.Test; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; import seedu.address.model.contact.Contact; import seedu.address.model.jobapplication.JobApplication; class SortCommandTest { + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private Model unsortedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - // TODO: tech debt - lousy tests @Test public void equals() { Comparator a = (c, b) -> c.getType().compareTo(b.getType()); @@ -34,4 +42,40 @@ public void equals() { assertNotEquals(s, new SortCommand(d, j, false)); assertNotEquals(s, new SortCommand(a, j, true)); } + + @Test + public void execute_sortName_contactsSorted() { + String expectedMessage = SortCommand.MESSAGE_SORTED_CONTACTS; + SortCommand command = new SortCommand(Model.COMPARATOR_NAME, null, false); + expectedModel.updateSortedContactList(Model.COMPARATOR_NAME); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + ArrayList arrayList1 = new ArrayList<>(model.getDisplayedContactList()); + ArrayList arrayList2 = new ArrayList<>(expectedModel.getDisplayedContactList()); + assertEquals(arrayList1, arrayList2); + } + + @Test + public void execute_sortTitle_applicationsSorted() { + String expectedMessage = SortCommand.MESSAGE_SORTED_APPLICATIONS; + SortCommand command = new SortCommand(null, JobApplication.JOB_TITLE_COMPARATOR, + false); + expectedModel.updateSortedApplicationList(JobApplication.JOB_TITLE_COMPARATOR); + assertCommandSuccess(command, model, expectedMessage, expectedModel); + ArrayList arrayList1 = new ArrayList<>(model.getDisplayedApplicationList()); + ArrayList arrayList2 = new ArrayList<>(expectedModel.getDisplayedApplicationList()); + assertEquals(arrayList1, arrayList2); + } + + @Test + public void execute_sortNone_applicationsUnsorted() { + String expectedMessage = SortCommand.MESSAGE_RESET_SORTING; + SortCommand command = new SortCommand(null, null, true); + assertCommandSuccess(command, model, expectedMessage, unsortedModel); + ArrayList arrayListContact1 = new ArrayList<>(model.getDisplayedContactList()); + ArrayList arrayListContact2 = new ArrayList<>(unsortedModel.getDisplayedContactList()); + ArrayList arrayListApp1 = new ArrayList<>(model.getDisplayedApplicationList()); + ArrayList arrayListApp2 = new ArrayList<>(unsortedModel.getDisplayedApplicationList()); + assertEquals(arrayListApp1, arrayListApp2); + assertEquals(arrayListContact1, arrayListContact2); + } } diff --git a/src/test/java/seedu/address/logic/parser/ListCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ListCommandParserTest.java index 5e218051b41..daca4f46401 100644 --- a/src/test/java/seedu/address/logic/parser/ListCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ListCommandParserTest.java @@ -2,6 +2,9 @@ import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CONTACTS; +import static seedu.address.model.Model.PREDICATE_SHOW_NOT_APPLIED_ORGANIZATIONS; +import static seedu.address.model.Model.PREDICATE_SHOW_ONLY_ORGANIZATIONS; +import static seedu.address.model.Model.PREDICATE_SHOW_ONLY_RECRUITERS; import org.junit.jupiter.api.Test; @@ -14,5 +17,8 @@ public class ListCommandParserTest { @Test public void parse_validArgs_returnsListCommand() { assertParseSuccess(parser, "", new ListCommand(PREDICATE_SHOW_ALL_CONTACTS)); + assertParseSuccess(parser, "--org", new ListCommand(PREDICATE_SHOW_ONLY_ORGANIZATIONS)); + assertParseSuccess(parser, "--rec", new ListCommand(PREDICATE_SHOW_ONLY_RECRUITERS)); + assertParseSuccess(parser, "--toapply", new ListCommand(PREDICATE_SHOW_NOT_APPLIED_ORGANIZATIONS)); } } diff --git a/src/test/java/seedu/address/logic/parser/ReminderCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ReminderCommandParserTest.java new file mode 100644 index 00000000000..5a58119fce9 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/ReminderCommandParserTest.java @@ -0,0 +1,39 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_EXTRA_FIELDS; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.ReminderCommand; + +public class ReminderCommandParserTest { + + private ReminderCommandParser parser = new ReminderCommandParser(); + + @Test + public void parse_emptyArg_throwsParseException() { + assertParseFailure(parser, " ", + String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderCommand.MESSAGE_USAGE)); + } + + @Test + public void parse_invalidArg_throwsParseException() { + assertParseFailure(parser, "--org", + MESSAGE_EXTRA_FIELDS + "--org"); + assertParseFailure(parser, "--by", + MESSAGE_EXTRA_FIELDS + "--by"); + } + + @Test + public void parse_validArgs_returnsReminderCommand() { + ReminderCommand expectedReminderCommand = + new ReminderCommand(true); + assertParseSuccess(parser, "--earliest", expectedReminderCommand); + ReminderCommand expectedReminderCommand2 = + new ReminderCommand(false); + assertParseSuccess(parser, "--latest", expectedReminderCommand2); + } +} diff --git a/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java b/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java new file mode 100644 index 00000000000..c7b94642c6b --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/SortCommandParserTest.java @@ -0,0 +1,43 @@ +package seedu.address.logic.parser; + +import static seedu.address.logic.Messages.MESSAGE_EXTRA_FIELDS; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.Messages.MESSAGE_SIMULTANEOUS_USE_DISALLOWED_FIELDS; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; + +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.SortCommand; +import seedu.address.model.Model; + +public class SortCommandParserTest { + + private SortCommandParser parser = new SortCommandParser(); + + @Test + public void parse_emptyArg_throwsParseException() { + assertParseFailure(parser, " ", + String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE)); + } + + @Test + public void parse_invalidArg_throwsParseException() { + assertParseFailure(parser, "--title --name", + MESSAGE_SIMULTANEOUS_USE_DISALLOWED_FIELDS + "--name, --title"); + assertParseFailure(parser, "--none --descending", + MESSAGE_SIMULTANEOUS_USE_DISALLOWED_FIELDS + "--descending, --none"); + assertParseFailure(parser, "--org", + MESSAGE_EXTRA_FIELDS + "--org"); + } + + @Test + public void parse_validArgs_returnsSortCommand() { + SortCommand expectedSortCommand = + new SortCommand(Model.COMPARATOR_ADDRESS, null, false); + assertParseSuccess(parser, "--address", expectedSortCommand); + SortCommand expectedSortCommand2 = + new SortCommand(Model.COMPARATOR_ADDRESS, null, true); + assertParseSuccess(parser, "--none", expectedSortCommand2); + } +}