Skip to content

Commit

Permalink
Tidy code and add test cases
Browse files Browse the repository at this point in the history
Let's,
* modify the test cases for the new contact list empty messages
* tidy code
  • Loading branch information
KrashKart committed Oct 20, 2024
1 parent cb2266e commit ae17297
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public abstract class AbstractFindCommand extends Command {
+ COMMAND_WORD + PHONE_COMMAND_WORD + "12345678\n"
+ COMMAND_WORD + TAG_COMMAND_WORD + "CS2100_classmate\n";

public static final String MESSAGE_NO_PERSONS_FOUND = "No persons found!";

private final ContainsKeywordsPredicate predicate;

public AbstractFindCommand(ContainsKeywordsPredicate predicate) {
Expand All @@ -45,7 +47,7 @@ public CommandResult execute(Model model) {

// if the result find list is empty
if (model.getFilteredPersonList().isEmpty()) {
return new CommandResult(String.format("No persons found!"));
return new CommandResult(String.format(MESSAGE_NO_PERSONS_FOUND));
}

return new CommandResult(
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class DeleteCommand extends Command {

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

public static final String MESSAGE_DELETE_LIST_EMPTY = "\nThe contact list is empty! :(";

private final Index targetIndex;

public DeleteCommand(Index targetIndex) {
Expand All @@ -43,9 +45,9 @@ public CommandResult execute(Model model) throws CommandException {
Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);

String result = String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete);
String result = String.format(MESSAGE_DELETE_PERSON_SUCCESS, Messages.format(personToDelete));
if (model.getFilteredPersonList().isEmpty()) {
result += "\nThe contact list is empty! :(";
result += MESSAGE_DELETE_LIST_EMPTY;
}
return new CommandResult(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void execute_validIndexFilteredList_success() {
DeleteCommand deleteCommand = new DeleteCommand(INDEX_FIRST_PERSON);

String expectedMessage = String.format(DeleteCommand.MESSAGE_DELETE_PERSON_SUCCESS,
Messages.format(personToDelete));
Messages.format(personToDelete) + DeleteCommand.MESSAGE_DELETE_LIST_EMPTY);

Model expectedModel = new ModelManager(model.getCampusConnect(), new UserPrefs());
expectedModel.deletePerson(personToDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
EmailContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByEmailCommand command = new FindByEmailCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
NameContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByNameCommand command = new FindByNameCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
PhoneContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByPhoneCommand command = new FindByPhoneCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void equals() {

@Test
public void execute_zeroKeywords_noPersonFound() {
String expectedMessage = String.format(MESSAGE_PERSONS_LISTED_OVERVIEW, 0);
String expectedMessage = AbstractFindCommand.MESSAGE_NO_PERSONS_FOUND;
TagContainsKeywordsPredicate predicate = preparePredicate(" ");
FindByTagCommand command = new FindByTagCommand(predicate);
expectedModel.updateFilteredPersonList(predicate);
Expand Down

0 comments on commit ae17297

Please sign in to comment.