Skip to content

Commit

Permalink
Merge pull request #149 from xGladiate/update-ui
Browse files Browse the repository at this point in the history
Resolve Inspection Command Bug
  • Loading branch information
xGladiate authored Nov 1, 2024
2 parents 5696805 + 635ff75 commit de73b74
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
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 @@ 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;

/**
Expand All @@ -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,
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));
}
}

0 comments on commit de73b74

Please sign in to comment.