Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add index for help text #153

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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_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 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.";
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/seedu/address/logic/commands/ArchiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,23 @@
private void validateIndexes(int listSize, List<Index> 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()));

Check warning on line 139 in src/main/java/seedu/address/logic/commands/ArchiveCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/ArchiveCommand.java#L137-L139

Added lines #L137 - L139 were not covered by tests
} 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()));
}
}
}

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,23 @@
private void validateIndexes(int listSize, List<Index> 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()));

Check warning on line 119 in src/main/java/seedu/address/logic/commands/DeleteCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/DeleteCommand.java#L117-L119

Added lines #L117 - L119 were not covered by tests
}
}

if (duplicate) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: Naming of boolean. I had so many warnings from the iP.

throw new CommandException(
String.format(Messages.MESSAGE_INVALID_DUPLICATED_INDEX,
targetIndex.getOneBased()));
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ private CommandResult editPerson(Model model) throws CommandException {
List<Person> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public CommandResult execute(Model model) throws CommandException {
List<Person> 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()) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/seedu/address/logic/commands/UnarchiveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,23 @@
private void validateIndexes(int listSize, List<Index> 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()));

Check warning on line 229 in src/main/java/seedu/address/logic/commands/UnarchiveCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/UnarchiveCommand.java#L227-L229

Added lines #L227 - L229 were not covered by tests
} 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()));
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/seedu/address/logic/commands/ArchiveCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Index> 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<Index> 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() {
Expand Down
41 changes: 28 additions & 13 deletions src/test/java/seedu/address/logic/commands/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,18 +77,23 @@ public void execute_outOfBoundIndexUnfilteredList_throwsCommandException() {
List<Index> 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<Index> outOfBoundIndexList = new ArrayList<>();
outOfBoundIndexList.add(INDEX_FIRST);
outOfBoundIndexList.add(INDEX_FIRST);
DeleteCommand deleteCommand = new DeleteCommand(outOfBoundIndexList);
List<Index> 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
Expand All @@ -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
Expand Down Expand Up @@ -131,23 +140,29 @@ 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
public void execute_duplicateIndexFilteredList_throwsCommandException() {
showPersonAtIndex(model, INDEX_FIRST);

Index duplicateIndex = INDEX_FIRST;
List<Index> outOfBoundIndexList = new ArrayList<>();
outOfBoundIndexList.add(INDEX_SECOND);
outOfBoundIndexList.add(INDEX_SECOND);
List<Index> 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
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/seedu/address/logic/commands/InspectCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Index> 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<Index> 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);
Expand Down