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

Resolve Inspection Command Bug #149

Merged
merged 3 commits into from
Nov 1, 2024
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
13 changes: 8 additions & 5 deletions src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -23,6 +24,7 @@
+ "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;

/**
Expand All @@ -46,6 +48,10 @@
throw new CommandException(Messages.MESSAGE_ARCHIVED_PERSON_DISPLAYED_INDEX);
}

if (AddressBookParser.getInspect()) {
throw new CommandException(Messages.MESSAGE_INVALID_WINDOW);

Check warning on line 52 in src/main/java/seedu/address/logic/commands/InspectCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/InspectCommand.java#L52

Added line #L52 was not covered by tests
}

Person personToInspect = lastShownList.get(index.getZeroBased());

return new CommandResult(generateSuccessMessage(personToInspect), personToInspect, false,
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/person/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


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