Skip to content

Commit

Permalink
Merge pull request #197 from ReflectiveObsidian/improve-delete-behaviour
Browse files Browse the repository at this point in the history
Improve delete behaviour
  • Loading branch information
Tsenrae authored Apr 4, 2024
2 parents e3bcceb + ecf7203 commit 1f8a42a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Messages {
public static final String MESSAGE_DUPLICATE_FIELDS =
"Multiple values specified for the following single-valued field(s): ";

public static final String MESSAGE_INVALID_PERSON_UUID = "The UUID provided is invalid: ";
public static final String MESSAGE_INVALID_PERSON_UUID = "The UUID provided is invalid, "
+ "does the person exist and is it 4 characters long? The UUID you entered was: ";
public static final String MESSAGE_MISSING_ATTRIBUTES = "Missing attributes to delete.";

public static final String MESSAGE_INVALID_PREDEFINED_RELATIONSHIP_DESCRIPTOR = "You cannot delete this "
Expand All @@ -44,6 +45,8 @@ public class Messages {

public static final String MESSAGE_SEARCH_FAILURE = "No Relationship pathway found";
public static final String MESSAGE_INVALID_ATTRIBUTE_FORMAT = "Invalid attribute format.";
public static final String MESSAGE_UUID_EMPTY = "Blank UUID provided. Please provide a valid UUID in this format: "
+ "/UUID" + "\nExample: /d8d8";
public static final String MESSAGE_INVALID_UUID_FORMAT = "Invalid UUID format. Please ensure that the UUID is "
+ "in the format: /<UUID>.";

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class DeleteCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the person identified by the index number used in the displayed person list.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1234";
+ "Parameters: UUID (must be from a person who exists, 4 characters)\n"
+ "Example: " + COMMAND_WORD + " /1bd4";

public static final String MESSAGE_DELETE_PERSON_SUCCESS = "Deleted Person: %1$s";

Expand All @@ -38,7 +38,10 @@ public CommandResult execute(Model model) throws CommandException {
UUID targetUuid = model.getFullUuid(target);

if (targetUuid == null) {
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_UUID);
if (target.isEmpty()) {
throw new CommandException(Messages.MESSAGE_UUID_EMPTY + "\n" + MESSAGE_USAGE);
}
throw new CommandException(Messages.MESSAGE_INVALID_PERSON_UUID + target + "\n" + MESSAGE_USAGE);
}

Person personToDelete = model.getPersonByUuid(targetUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class DeleteCommandParser implements Parser<DeleteCommand> {
*/
public DeleteCommand parse(String args) throws ParseException {
if (!args.trim().startsWith("/")) {
throw new ParseException("Input a UUID prefixed with '/'.");
throw new ParseException("Please input a UUID prefixed with '/'." + "\n" + DeleteCommand.MESSAGE_USAGE);
}
return new DeleteCommand(args.trim().substring(1));
return new DeleteCommand(args.trim().substring(1).trim());
}
}
6 changes: 5 additions & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -62,7 +63,10 @@ public void execute_invalidCommandFormat_throwsParseException() {
@Test
public void execute_commandExecutionError_throwsCommandException() {
String deleteCommand = "delete /9";
assertCommandException(deleteCommand, MESSAGE_INVALID_PERSON_UUID);
assertCommandException(
deleteCommand,
MESSAGE_INVALID_PERSON_UUID + "9" + "\n" + DeleteCommand.MESSAGE_USAGE
);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public void execute_validUuid_success() {
public void execute_nonRealUuidFilteredList_throwsCommandException() {
DeleteCommand deleteCommand = new DeleteCommand("12345");

assertCommandFailure(deleteCommand, model, Messages.MESSAGE_INVALID_PERSON_UUID);
assertCommandFailure(
deleteCommand,
model,
Messages.MESSAGE_INVALID_PERSON_UUID + "12345" + "\n" + DeleteCommand.MESSAGE_USAGE
);
}

@Test
Expand Down Expand Up @@ -113,4 +117,15 @@ public void execute_validUuidUnfilteredList_success() {

assertCommandSuccess(deleteCommand, model, expectedMessage, expectedModel);
}
@Test
public void execute_blankUuid_error() {
DeleteCommand deleteCommand = new DeleteCommand("");
String expectedMessage = Messages.MESSAGE_UUID_EMPTY + "\n" + DeleteCommand.MESSAGE_USAGE;
ModelManager emptyModel = new ModelManager(model.getAddressBook(), new UserPrefs());
try {
deleteCommand.execute(emptyModel);
} catch (CommandException e) {
assertEquals(expectedMessage, e.getMessage());
}
}
}

0 comments on commit 1f8a42a

Please sign in to comment.