From 4f89837175b44924d983805b11f204842765b3ff Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 12:41:54 +0800 Subject: [PATCH 1/3] Modify boolean parse expression in Archive --- src/main/java/seedu/address/model/person/Archive.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/seedu/address/model/person/Archive.java b/src/main/java/seedu/address/model/person/Archive.java index 875db268b75..373babef0ae 100644 --- a/src/main/java/seedu/address/model/person/Archive.java +++ b/src/main/java/seedu/address/model/person/Archive.java @@ -41,7 +41,7 @@ public static boolean isValidArchive(String test) { * Returns true if a given string is a valid archive. */ public boolean isArchived() { - return this.value.equals("true"); + return Boolean.parseBoolean(this.value); } From 923072c4a0616f89329177915bd7210ab5990104 Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 12:56:09 +0800 Subject: [PATCH 2/3] Resolve inspect command bug --- src/main/java/seedu/address/logic/Messages.java | 13 ++++++++----- .../address/logic/commands/InspectCommand.java | 6 ++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 5f50d47de40..5eae27d006a 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -17,15 +17,18 @@ public class Messages { public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command"; public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; - public static final String MESSAGE_ARCHIVED_PERSON_DISPLAYED_INDEX = "The person index provided refers to " - + "an archived person." + "\nUnarchive the person to continue"; + public static final String MESSAGE_ARCHIVED_PERSON_DISPLAYED_INDEX = + "The person index provided refers to an archived person.\n" + + "Unarchive the person to continue"; public static final String MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX = "The delivery index provided is invalid"; - public static final String MESSAGE_ARCHIVED_DELIVERY_DISPLAYED_INDEX = "The delivery index provided refers to " - + "an archived delivery." + "\n Unarchive the delivery to continue."; + public static final String MESSAGE_ARCHIVED_DELIVERY_DISPLAYED_INDEX = + "The delivery index provided refers to an archived delivery.\n" + + "Unarchive the delivery to continue."; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; - + public static final String MESSAGE_INVALID_WINDOW = "This command could not be executed in the inspection window.\n" + + "Navigate back to the main window to continue."; /** * Returns an error message indicating the duplicate prefixes. */ diff --git a/src/main/java/seedu/address/logic/commands/InspectCommand.java b/src/main/java/seedu/address/logic/commands/InspectCommand.java index 79afc1e8257..c49f6df0ee0 100644 --- a/src/main/java/seedu/address/logic/commands/InspectCommand.java +++ b/src/main/java/seedu/address/logic/commands/InspectCommand.java @@ -7,6 +7,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.logic.parser.AddressBookParser; import seedu.address.model.Model; import seedu.address.model.person.Person; @@ -23,6 +24,7 @@ public class InspectCommand extends Command { + "Example: " + COMMAND_WORD + " 1"; public static final String MESSAGE_INSPECT_SUCCESS = "Inspected person: %1$s"; + public static final String MESSAGE_INSPECT_INVALID = "Inspected person: %1$s"; private final Index index; /** @@ -46,6 +48,10 @@ public CommandResult execute(Model model) throws CommandException { throw new CommandException(Messages.MESSAGE_ARCHIVED_PERSON_DISPLAYED_INDEX); } + if (AddressBookParser.getInspect()) { + throw new CommandException(Messages.MESSAGE_INVALID_WINDOW); + } + Person personToInspect = lastShownList.get(index.getZeroBased()); return new CommandResult(generateSuccessMessage(personToInspect), personToInspect, false, From 635ff75dad0d7a01a752403612a553e9000e18c1 Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 13:08:19 +0800 Subject: [PATCH 3/3] Add testcase for InspectCommandTest --- .../logic/commands/InspectCommandTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/test/java/seedu/address/logic/commands/InspectCommandTest.java diff --git a/src/test/java/seedu/address/logic/commands/InspectCommandTest.java b/src/test/java/seedu/address/logic/commands/InspectCommandTest.java new file mode 100644 index 00000000000..28adbce530f --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/InspectCommandTest.java @@ -0,0 +1,31 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST; +import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND; + +import org.junit.jupiter.api.Test; +public class InspectCommandTest { + @Test + public void equals() { + InspectCommand inspectFirstCommand = new InspectCommand(INDEX_FIRST); + InspectCommand inspectSecondCommand = new InspectCommand(INDEX_SECOND); + + // same object -> returns true + assertTrue(inspectFirstCommand.equals(inspectFirstCommand)); + + // same values -> returns true + InspectCommand inspectFirstCommandCopy = new InspectCommand(INDEX_FIRST); + assertTrue(inspectFirstCommand.equals(inspectFirstCommandCopy)); + + // different types -> returns false + assertFalse(inspectFirstCommand.equals(1)); + + // null -> returns false + assertFalse(inspectSecondCommand.equals(null)); + + // different person -> returns false + assertFalse(inspectFirstCommand.equals(inspectSecondCommand)); + } +}