From 28a617fcf0ce152eea96e7ae05b7b4ddb6f8d433 Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 14:20:45 +0800 Subject: [PATCH 1/5] Add index of invalid person or delivery for delete command --- src/main/java/seedu/address/logic/Messages.java | 6 ++++-- .../address/logic/commands/DeleteCommand.java | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 5eae27d006a..d97f1feca61 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -16,11 +16,13 @@ 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_INVALID_PERSON_DISPLAYED_INDEX = "The person index %1$s provided is invalid"; + public static final String MESSAGE_INVALID_DUPLICATED_INDEX = "Duplicated index %1$s is not allowed"; 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_INVALID_DELIVERY_DISPLAYED_INDEX = + "The delivery index [%1$s] 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."; diff --git a/src/main/java/seedu/address/logic/commands/DeleteCommand.java b/src/main/java/seedu/address/logic/commands/DeleteCommand.java index 31edcfc0b5a..220720478ea 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteCommand.java @@ -108,13 +108,23 @@ private CommandResult handleDeliveryDeletion(Model model) throws CommandExceptio private void validateIndexes(int listSize, List indexList, boolean isPersonIndex) throws CommandException { boolean duplicate = hasDuplicates(indexList); for (Index targetIndex : indexList) { - if (targetIndex.getZeroBased() >= listSize || duplicate) { + if (targetIndex.getZeroBased() >= listSize) { if (isPersonIndex) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + targetIndex.getOneBased())); } else { - throw new CommandException(Messages.MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + targetIndex.getOneBased())); } } + + if (duplicate) { + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_DUPLICATED_INDEX, + targetIndex.getOneBased())); + } } } From d3e53898ba10813d8d677dde616603be291a1100 Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 15:35:45 +0800 Subject: [PATCH 2/5] Modify help message for invalid or duplicate person or delivery --- src/main/java/seedu/address/logic/Messages.java | 4 ++-- .../address/logic/commands/ArchiveCommand.java | 16 +++++++++++++--- .../address/logic/commands/EditCommand.java | 3 ++- .../address/logic/commands/InspectCommand.java | 3 ++- .../address/logic/commands/UnarchiveCommand.java | 16 +++++++++++++--- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index d97f1feca61..aa9106192b7 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -17,12 +17,12 @@ 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 %1$s provided is invalid"; + public static final String MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX = + "The delivery index %1$s provided is invalid"; public static final String MESSAGE_INVALID_DUPLICATED_INDEX = "Duplicated index %1$s is not allowed"; 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 [%1$s] 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."; diff --git a/src/main/java/seedu/address/logic/commands/ArchiveCommand.java b/src/main/java/seedu/address/logic/commands/ArchiveCommand.java index 2d4689b07e7..0f88e42a3c2 100644 --- a/src/main/java/seedu/address/logic/commands/ArchiveCommand.java +++ b/src/main/java/seedu/address/logic/commands/ArchiveCommand.java @@ -132,13 +132,23 @@ private CommandResult handlePersonArchive(Model model) throws CommandException { private void validateIndexes(int listSize, List indexList, boolean isDelivery) throws CommandException { boolean hasDuplicate = hasDuplicates(indexList); for (Index targetIndex : indexList) { - if (targetIndex.getZeroBased() >= listSize || hasDuplicate) { + if (targetIndex.getZeroBased() >= listSize) { if (isDelivery) { - throw new CommandException(Messages.MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX, + targetIndex.getOneBased())); } else { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + targetIndex.getOneBased())); } } + + if (hasDuplicate) { + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_DUPLICATED_INDEX, + targetIndex.getOneBased())); + } } } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 515b62bef96..ef9eb63b8a7 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -150,7 +150,8 @@ private CommandResult editPerson(Model model) throws CommandException { List lastShownList = model.getFilteredPersonList(); if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, index.getOneBased())); } if (index.getZeroBased() >= model.getFirstArchivedIndex().getZeroBased()) { diff --git a/src/main/java/seedu/address/logic/commands/InspectCommand.java b/src/main/java/seedu/address/logic/commands/InspectCommand.java index c49f6df0ee0..36d63f16f9f 100644 --- a/src/main/java/seedu/address/logic/commands/InspectCommand.java +++ b/src/main/java/seedu/address/logic/commands/InspectCommand.java @@ -41,7 +41,8 @@ public CommandResult execute(Model model) throws CommandException { List lastShownList = model.getFilteredPersonList(); if (index.getZeroBased() >= lastShownList.size()) { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, index.getOneBased())); } if (index.getZeroBased() >= model.getFirstArchivedIndex().getZeroBased()) { diff --git a/src/main/java/seedu/address/logic/commands/UnarchiveCommand.java b/src/main/java/seedu/address/logic/commands/UnarchiveCommand.java index e23da0b9e62..4ed0afcf7bb 100644 --- a/src/main/java/seedu/address/logic/commands/UnarchiveCommand.java +++ b/src/main/java/seedu/address/logic/commands/UnarchiveCommand.java @@ -222,13 +222,23 @@ private boolean hasDuplicates(List indexList) { private void validateIndexes(int listSize, List indexList, boolean isDelivery) throws CommandException { boolean hasDuplicate = hasDuplicates(indexList); for (Index targetIndex : indexList) { - if (targetIndex.getZeroBased() >= listSize || hasDuplicate) { + if (targetIndex.getZeroBased() >= listSize) { if (isDelivery) { - throw new CommandException(Messages.MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_DELIVERY_DISPLAYED_INDEX, + targetIndex.getOneBased())); } else { - throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + targetIndex.getOneBased())); } } + + if (hasDuplicate) { + throw new CommandException( + String.format(Messages.MESSAGE_INVALID_DUPLICATED_INDEX, + targetIndex.getOneBased())); + } } } From d1c15de20351422f0accc587ee5ac22c5b64404f Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 15:39:20 +0800 Subject: [PATCH 3/5] Modify testcases to check for new help message --- .../seedu/address/logic/LogicManagerTest.java | 3 +- .../logic/commands/DeleteCommandTest.java | 41 +++++++++++++------ .../logic/commands/EditCommandTest.java | 10 ++++- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/test/java/seedu/address/logic/LogicManagerTest.java b/src/test/java/seedu/address/logic/LogicManagerTest.java index baf8ce336a2..735e1ad6d24 100644 --- a/src/test/java/seedu/address/logic/LogicManagerTest.java +++ b/src/test/java/seedu/address/logic/LogicManagerTest.java @@ -61,7 +61,8 @@ public void execute_invalidCommandFormat_throwsParseException() { @Test public void execute_commandExecutionError_throwsCommandException() { String deleteCommand = "delete 9"; - assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + String expectedErrorMessage = String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, 9); + assertCommandException(deleteCommand, expectedErrorMessage); } @Test diff --git a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java index 0aafca649df..f2f1cdb98e2 100644 --- a/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/DeleteCommandTest.java @@ -3,6 +3,8 @@ 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_DUPLICATED_INDEX; +import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex; @@ -75,18 +77,23 @@ public void execute_outOfBoundIndexUnfilteredList_throwsCommandException() { List outOfBoundIndexList = new ArrayList<>(); outOfBoundIndexList.add(outOfBoundIndex); DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndexList); + String expectedErrorMessage = String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, expectedErrorMessage); } @Test public void execute_duplicateIndexUnfilteredList_throwsCommandException() { - List outOfBoundIndexList = new ArrayList<>(); - outOfBoundIndexList.add(INDEX_FIRST); - outOfBoundIndexList.add(INDEX_FIRST); - DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndexList); + List duplicatedList = new ArrayList<>(); + duplicatedList.add(INDEX_FIRST); + duplicatedList.add(INDEX_FIRST); + DeleteCommand deleteCommand = new DeleteCommand(duplicatedList); + + String expectedErrorMessage = String.format(MESSAGE_INVALID_DUPLICATED_INDEX, + INDEX_FIRST.getOneBased()); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, expectedErrorMessage); } @Test @@ -96,8 +103,10 @@ public void execute_invalidMultipleIndexUnfilteredList_throwsCommandException() outOfBoundIndexList.add(INDEX_FIRST); outOfBoundIndexList.add(outOfBoundIndex); DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndexList); + String expectedErrorMessage = String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, expectedErrorMessage); } @Test @@ -131,7 +140,10 @@ public void execute_invalidIndexFilteredList_throwsCommandException() { DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndexList); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + String expectedErrorMessage = String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); + + assertCommandFailure(deleteCommand, model, expectedErrorMessage); } @Test @@ -139,15 +151,18 @@ public void execute_duplicateIndexFilteredList_throwsCommandException() { showPersonAtIndex(model, INDEX_FIRST); Index duplicateIndex = INDEX_FIRST; - List outOfBoundIndexList = new ArrayList<>(); - outOfBoundIndexList.add(INDEX_SECOND); - outOfBoundIndexList.add(INDEX_SECOND); + List duplicatedIndexList = new ArrayList<>(); + duplicatedIndexList.add(INDEX_FIRST); + duplicatedIndexList.add(INDEX_FIRST); // ensures that outOfBoundIndex is still in bounds of address book list assertTrue(duplicateIndex.getZeroBased() < model.getAddressBook().getPersonList().size()); - DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndexList); + DeleteCommand deleteCommand = new DeleteCommand(duplicatedIndexList); + + String expectedErrorMessage = String.format(MESSAGE_INVALID_DUPLICATED_INDEX, + duplicateIndex.getOneBased()); - assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(deleteCommand, model, expectedErrorMessage); } @Test diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 52c7684641f..70f06759cd5 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -126,7 +126,10 @@ public void execute_invalidPersonIndexUnfilteredList_failure() { EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + String expectedErrorMessage = String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); + + assertCommandFailure(editCommand, model, expectedErrorMessage); } @@ -145,7 +148,10 @@ public void execute_invalidPersonIndexFilteredList_failure() { EditCommand editCommand = new EditCommand(outOfBoundIndex, new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build()); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + String expectedErrorMessage = String.format(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); + + assertCommandFailure(editCommand, model, expectedErrorMessage); } @Test From d101fabb0b0efdfdfbd54503726339d549aa8cbb Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 15:57:02 +0800 Subject: [PATCH 4/5] Add negative testcases for ArchiveCommand and UnarchiveCommand --- .../logic/commands/ArchiveCommandTest.java | 30 +++++++++++++++++++ .../logic/commands/UnarchiveCommandTest.java | 29 ++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/test/java/seedu/address/logic/commands/ArchiveCommandTest.java b/src/test/java/seedu/address/logic/commands/ArchiveCommandTest.java index 9fe2f1281e1..781029242df 100644 --- a/src/test/java/seedu/address/logic/commands/ArchiveCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ArchiveCommandTest.java @@ -3,7 +3,11 @@ 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_DUPLICATED_INDEX; +import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_LIST; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_LIST; import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD; @@ -55,6 +59,32 @@ public void execute_validSingleIndexUnfilteredPersonList_success() { AddressBookParser.setInspect(false); assertCommandSuccess(archiveCommand, model, expectedMessage, expectedModel); } + + @Test + public void execute_outOfBoundIndexUnfilteredList_throwsCommandException() { + Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + List outOfBoundIndexList = new ArrayList<>(); + outOfBoundIndexList.add(outOfBoundIndex); + ArchiveCommand archiveCommand = new ArchiveCommand(outOfBoundIndexList); + String expectedErrorMessage = String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); + + assertCommandFailure(archiveCommand, model, expectedErrorMessage); + } + + @Test + public void execute_duplicateIndexUnfilteredList_throwsCommandException() { + List duplicatedList = new ArrayList<>(); + duplicatedList.add(INDEX_FIRST); + duplicatedList.add(INDEX_FIRST); + ArchiveCommand archiveCommand = new ArchiveCommand(duplicatedList); + + String expectedErrorMessage = String.format(MESSAGE_INVALID_DUPLICATED_INDEX, + INDEX_FIRST.getOneBased()); + + assertCommandFailure(archiveCommand, model, expectedErrorMessage); + } + // //@Test //public void execute_validSingleIndexUnfilteredDeliveryList_success() { diff --git a/src/test/java/seedu/address/logic/commands/UnarchiveCommandTest.java b/src/test/java/seedu/address/logic/commands/UnarchiveCommandTest.java index efe96c26bd4..ecefbb68847 100644 --- a/src/test/java/seedu/address/logic/commands/UnarchiveCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/UnarchiveCommandTest.java @@ -3,7 +3,11 @@ 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_DUPLICATED_INDEX; +import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_LIST; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_LIST; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -55,6 +59,31 @@ public void execute_validSingleIndexUnfilteredPersonList_success() { assertCommandSuccess(unarchiveCommand, model, expectedMessage, expectedModel); } + @Test + public void execute_outOfBoundIndexUnfilteredList_throwsCommandException() { + Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + List outOfBoundIndexList = new ArrayList<>(); + outOfBoundIndexList.add(outOfBoundIndex); + UnarchiveCommand unarchiveCommand = new UnarchiveCommand(outOfBoundIndexList); + String expectedErrorMessage = String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); + + assertCommandFailure(unarchiveCommand, model, expectedErrorMessage); + } + + @Test + public void execute_duplicateIndexUnfilteredList_throwsCommandException() { + List duplicatedList = new ArrayList<>(); + duplicatedList.add(INDEX_FIRST); + duplicatedList.add(INDEX_FIRST); + UnarchiveCommand unarchiveCommand = new UnarchiveCommand(duplicatedList); + + String expectedErrorMessage = String.format(MESSAGE_INVALID_DUPLICATED_INDEX, + INDEX_FIRST.getOneBased()); + + assertCommandFailure(unarchiveCommand, model, expectedErrorMessage); + } + @Test public void equals() { UnarchiveCommand unarchiveFirstCommand = new UnarchiveCommand(INDEX_FIRST_LIST); From c858144196ec93666df15a7ed72d87ff544e2f76 Mon Sep 17 00:00:00 2001 From: xGladiate Date: Fri, 1 Nov 2024 16:02:52 +0800 Subject: [PATCH 5/5] Add negative testcases for inspect command --- .../logic/commands/InspectCommandTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/test/java/seedu/address/logic/commands/InspectCommandTest.java b/src/test/java/seedu/address/logic/commands/InspectCommandTest.java index 28adbce530f..fd58414ebb5 100644 --- a/src/test/java/seedu/address/logic/commands/InspectCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/InspectCommandTest.java @@ -2,11 +2,37 @@ 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.commands.CommandTestUtil.assertCommandFailure; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST; import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; import org.junit.jupiter.api.Test; + +import seedu.address.commons.core.index.Index; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; + +/** + * Contains integration tests (interaction with the Model) and unit tests for + * {@code InspectCommand}. + */ public class InspectCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + + @Test + public void execute_outOfBoundIndexUnfilteredList_throwsCommandException() { + Index outOfBoundIndex = Index.fromOneBased(model.getFilteredPersonList().size() + 1); + InspectCommand inspectCommand = new InspectCommand(outOfBoundIndex); + String expectedErrorMessage = String.format(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX, + outOfBoundIndex.getOneBased()); + + assertCommandFailure(inspectCommand, model, expectedErrorMessage); + } + @Test public void equals() { InspectCommand inspectFirstCommand = new InspectCommand(INDEX_FIRST);