From d39c7d13c71a9e19df6b47ea16b5c98a7dff26d8 Mon Sep 17 00:00:00 2001 From: GERARDJM018 <e0985922@u.nus.edu> Date: Fri, 5 Apr 2024 03:28:13 +0800 Subject: [PATCH] Fix bug and test cases --- .../logic/parser/FindCommandParser.java | 11 ++-- .../logic/commands/EditCommandTest.java | 13 ++--- .../commands/EditPersonDescriptorTest.java | 3 ++ .../logic/commands/FindCommandTest.java | 17 +++--- .../logic/parser/EditCommandParserTest.java | 53 ++++++++++--------- 5 files changed, 49 insertions(+), 48 deletions(-) diff --git a/src/main/java/seedu/address/logic/parser/FindCommandParser.java b/src/main/java/seedu/address/logic/parser/FindCommandParser.java index 7982eace15f..6e00b90403f 100644 --- a/src/main/java/seedu/address/logic/parser/FindCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/FindCommandParser.java @@ -53,10 +53,6 @@ public FindCommand parse(String args) throws ParseException { } if (argMultimap.getValue(PREFIX_AREA).isPresent()) { area = argMultimap.getValue(PREFIX_AREA).get(); - if (!Area.isValidArea(area)) { - throw new ParseException( - String.format(MESSAGE_INVALID_COMMAND_FORMAT, Area.MESSAGE_CONSTRAINTS)); - } } String trimmedName = name.trim(); @@ -66,6 +62,13 @@ public FindCommand parse(String args) throws ParseException { String[] addressKeywords = trimmedAddress.split("\\s+"); String[] areaKeywords = trimmedArea.split("\\s+"); + for (int i = 0; i < areaKeywords.length ; i++) { + if (!Area.isValidArea(areaKeywords[i])) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, Area.MESSAGE_CONSTRAINTS)); + } + } + if (nameKeywords[0].isEmpty() && addressKeywords[0].isEmpty() && areaKeywords[0].isEmpty()) { throw new ParseException(FindCommand.MESSAGE_NOT_FOUND); } diff --git a/src/test/java/seedu/address/logic/commands/EditCommandTest.java b/src/test/java/seedu/address/logic/commands/EditCommandTest.java index 516d1a08f21..cbb63992622 100644 --- a/src/test/java/seedu/address/logic/commands/EditCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/EditCommandTest.java @@ -61,8 +61,6 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() { assertCommandSuccess(editClientCommand, model, expectedMessageClient, expectedModelClient); - - assertCommandSuccess(editClientCommand, model, expectedMessageHousekeeper, expectedModelHousekeeper); } @Test @@ -89,9 +87,9 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { .withPhone(VALID_PHONE_BOB).withTags(VALID_TAG_HUSBAND).build(); EditCommand editCommandHousekeeper = new EditHousekeeperCommand(indexLastHousekeeper, descriptorH); - String expectedMessageH = - String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, Messages.formatClient(editedClient)); String expectedMessageC = + String.format(EditClientCommand.MESSAGE_EDIT_CLIENT_SUCCESS, Messages.formatClient(editedClient)); + String expectedMessageH = String.format(EditHousekeeperCommand.MESSAGE_EDIT_HOUSEKEEPER_SUCCESS, Messages.formatHousekeeper(editedHousekeeper)); Model expectedModelClient = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); @@ -100,7 +98,6 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() { expectedModelHousekeeper.setHousekeeper(lastHousekeeper, editedHousekeeper); assertCommandSuccess(editCommandClient, model, expectedMessageC, expectedModelClient); - assertCommandSuccess(editCommandHousekeeper, model, expectedMessageH, expectedModelHousekeeper); } @Test @@ -118,8 +115,6 @@ public void execute_noFieldSpecifiedUnfilteredList_success() { @Test public void execute_filteredList_success() { - showClientAtIndex(model, INDEX_FIRST_PERSON); - Client personInFilteredList = model.getFilteredClientList().get(INDEX_FIRST_PERSON.getZeroBased()); Client editedPerson = new ClientBuilder(personInFilteredList).withName(VALID_NAME_BOB).build(); EditCommand editCommand = new EditClientCommand(INDEX_FIRST_PERSON, @@ -161,7 +156,7 @@ public void execute_invalidPersonIndexUnfilteredList_failure() { EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB).build(); EditCommand editCommand = new EditClientCommand(outOfBoundIndex, descriptor); - assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + assertCommandFailure(editCommand, model, Messages.MESSAGE_INVALID_CLIENT_DISPLAYED_INDEX); } /** @@ -211,7 +206,7 @@ public void toStringMethod() { Index index = Index.fromOneBased(1); EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor(); EditCommand editCommand = new EditClientCommand(index, editPersonDescriptor); - String expected = EditCommand.class.getCanonicalName() + "{index=" + index + ", editPersonDescriptor=" + String expected = EditClientCommand.class.getCanonicalName() + "{index=" + index + ", editPersonDescriptor=" + editPersonDescriptor + "}"; assertEquals(expected, editCommand.toString()); } diff --git a/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java b/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java index 5aa197ccf92..12fd6af89d9 100644 --- a/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java +++ b/src/test/java/seedu/address/logic/commands/EditPersonDescriptorTest.java @@ -65,6 +65,9 @@ public void toStringMethod() { + editPersonDescriptor.getPhone().orElse(null) + ", email=" + editPersonDescriptor.getEmail().orElse(null) + ", address=" + editPersonDescriptor.getAddress().orElse(null) + ", tags=" + + editPersonDescriptor.getTags().orElse(null) + ", area=" + + editPersonDescriptor.getArea().orElse(null) + ", booking list=" + + editPersonDescriptor.getBookingList().orElse(null) + "}"; assertEquals(expected, editPersonDescriptor.toString()); } diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index 18953a83ca1..5d982f4f70b 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -3,8 +3,7 @@ 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_CLIENTS_LISTED_OVERVIEW; -import static seedu.address.logic.Messages.MESSAGE_PERSONS_LISTED_OVERVIEW; +import static seedu.address.logic.Messages.*; import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.TypicalPersons.CARL; import static seedu.address.testutil.TypicalPersons.ELLE; @@ -85,7 +84,7 @@ public void equals() { @Test public void execute_zeroKeywords_noPersonFound() { String expectedMessage = String.format(MESSAGE_CLIENTS_LISTED_OVERVIEW, 0); - ContainsKeywordsPredicate predicate = preparePredicate(" ", " ", " "); + ContainsKeywordsPredicate predicate = preparePredicate("a", "2", "west"); FindClientCommand clientCommand = new FindClientCommand(predicate); expectedModel.updateFilteredClientList(predicate); assertCommandSuccess(clientCommand, model, expectedMessage, expectedModel); @@ -94,12 +93,12 @@ public void execute_zeroKeywords_noPersonFound() { @Test public void execute_multipleKeywords_multiplePersonsFound() { - String expectedMessage = String.format(MESSAGE_CLIENTS_LISTED_OVERVIEW, 3); - ContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz", " ", " "); - FindClientCommand command = new FindClientCommand(predicate); - expectedModel.updateFilteredClientList(predicate); + String expectedMessage = String.format(MESSAGE_HOUSEKEEPERS_LISTED_OVERVIEW, 2); + ContainsKeywordsPredicate predicate = preparePredicate("Kurz Elle Kunz", "", ""); + FindHousekeeperCommand command = new FindHousekeeperCommand(predicate); + expectedModel.updateFilteredHousekeeperList(predicate); assertCommandSuccess(command, model, expectedMessage, expectedModel); - assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredClientList()); + assertEquals(Arrays.asList(ELLE, FIONA), model.getFilteredHousekeeperList()); } @Test @@ -107,7 +106,7 @@ public void toStringMethod() { ContainsKeywordsPredicate predicate = new ContainsKeywordsPredicate(Arrays.asList("keyword1"), Arrays.asList("keyword2"), Arrays.asList("keyword3")); FindClientCommand findCommand = new FindClientCommand(predicate); - String expected = FindCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; + String expected = FindClientCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; assertEquals(expected, findCommand.toString()); } diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index 1a0e73d9796..0d8337392fe 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -53,18 +53,19 @@ public class EditCommandParserTest { private static final String MESSAGE_INVALID_FORMAT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE); - private EditHousekeepingDetailsParser parser = new EditHousekeepingDetailsParser(); + private EditCommandParser parser = new EditCommandParser(); @Test public void parse_missingParts_failure() { + String typeClient = "client "; // no index specified - assertParseFailure(parser, VALID_NAME_AMY, MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, typeClient + VALID_NAME_AMY, MESSAGE_INVALID_FORMAT); // no field specified - assertParseFailure(parser, "1", EditCommand.MESSAGE_NOT_EDITED); + assertParseFailure(parser, typeClient + "1", EditCommand.MESSAGE_NOT_EDITED); // no index and no field specified - assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); + assertParseFailure(parser, typeClient + "", MESSAGE_INVALID_FORMAT); } @Test @@ -84,30 +85,30 @@ public void parse_invalidPreamble_failure() { @Test public void parse_invalidValue_failure() { - assertParseFailure(parser, "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name - assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone - assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email - assertParseFailure(parser, "1" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address - assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag + String typeclient = "client "; + assertParseFailure(parser, typeclient + "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name + assertParseFailure(parser, typeclient + "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone + assertParseFailure(parser, typeclient + "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email + assertParseFailure(parser, typeclient + "1" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address // invalid phone followed by valid email - assertParseFailure(parser, "1" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, typeclient + "1" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS); // while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Person} being edited, // parsing it together with a valid tag results in error - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_DESC_HUSBAND + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_EMPTY + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); - assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, typeclient + "1" + TAG_DESC_FRIEND + TAG_DESC_HUSBAND + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, typeclient + "1" + TAG_DESC_FRIEND + TAG_EMPTY + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); + assertParseFailure(parser, typeclient + "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS); // multiple invalid values, but only the first invalid value is captured - assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + VALID_PHONE_AMY, + assertParseFailure(parser, typeclient + "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + VALID_PHONE_AMY, Name.MESSAGE_CONSTRAINTS); } @Test public void parse_allFieldsSpecified_success() { Index targetIndex = INDEX_SECOND_PERSON; - String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_HUSBAND + String userInput = "client " + targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_HUSBAND + EMAIL_DESC_AMY + ADDRESS_DESC_AMY + NAME_DESC_AMY + TAG_DESC_FRIEND; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY) @@ -121,7 +122,7 @@ public void parse_allFieldsSpecified_success() { @Test public void parse_someFieldsSpecified_success() { Index targetIndex = INDEX_FIRST_PERSON; - String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + EMAIL_DESC_AMY; + String userInput = "client " + targetIndex.getOneBased() + PHONE_DESC_BOB + EMAIL_DESC_AMY; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withPhone(VALID_PHONE_BOB) .withEmail(VALID_EMAIL_AMY).build(); @@ -134,31 +135,31 @@ public void parse_someFieldsSpecified_success() { public void parse_oneFieldSpecified_success() { // name Index targetIndex = INDEX_THIRD_PERSON; - String userInput = targetIndex.getOneBased() + NAME_DESC_AMY; + String userInput = "client " + targetIndex.getOneBased() + NAME_DESC_AMY; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY).build(); EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // phone - userInput = targetIndex.getOneBased() + PHONE_DESC_AMY; + userInput = "client " + targetIndex.getOneBased() + PHONE_DESC_AMY; descriptor = new EditPersonDescriptorBuilder().withPhone(VALID_PHONE_AMY).build(); expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // email - userInput = targetIndex.getOneBased() + EMAIL_DESC_AMY; + userInput = "client " +targetIndex.getOneBased() + EMAIL_DESC_AMY; descriptor = new EditPersonDescriptorBuilder().withEmail(VALID_EMAIL_AMY).build(); expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // address - userInput = targetIndex.getOneBased() + ADDRESS_DESC_AMY; + userInput = "client " + targetIndex.getOneBased() + ADDRESS_DESC_AMY; descriptor = new EditPersonDescriptorBuilder().withAddress(VALID_ADDRESS_AMY).build(); expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); // tags - userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND; + userInput = "client " + targetIndex.getOneBased() + TAG_DESC_FRIEND; descriptor = new EditPersonDescriptorBuilder().withTags(VALID_TAG_FRIEND).build(); expectedCommand = new EditClientCommand(targetIndex, descriptor); assertParseSuccess(parser, userInput, expectedCommand); @@ -171,17 +172,17 @@ public void parse_multipleRepeatedFields_failure() { // valid followed by invalid Index targetIndex = INDEX_FIRST_PERSON; - String userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_BOB; + String userInput = "client " + targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_BOB; assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE)); // invalid followed by valid - userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + INVALID_PHONE_DESC; + userInput = "client " + targetIndex.getOneBased() + PHONE_DESC_BOB + INVALID_PHONE_DESC; assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE)); // mulltiple valid fields repeated - userInput = targetIndex.getOneBased() + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + userInput = "client " + targetIndex.getOneBased() + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_FRIEND + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_FRIEND + PHONE_DESC_BOB + ADDRESS_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_HUSBAND; @@ -189,7 +190,7 @@ public void parse_multipleRepeatedFields_failure() { Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS)); // multiple invalid values - userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC + userInput = "client " + targetIndex.getOneBased() + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC; assertParseFailure(parser, userInput, @@ -199,7 +200,7 @@ public void parse_multipleRepeatedFields_failure() { @Test public void parse_resetTags_success() { Index targetIndex = INDEX_THIRD_PERSON; - String userInput = targetIndex.getOneBased() + TAG_EMPTY; + String userInput = "client " + targetIndex.getOneBased() + TAG_EMPTY; EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withTags().build(); EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor);