Skip to content

Commit

Permalink
Merge pull request #124 from GERARDJM018/V1.3-post-testing
Browse files Browse the repository at this point in the history
Fix bug and test cases
  • Loading branch information
LimZiJia authored Apr 4, 2024
2 parents 086115e + d39c7d1 commit 305f54f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/logic/parser/FindCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/seedu/address/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ public void execute_allFieldsSpecifiedUnfilteredList_success() {


assertCommandSuccess(editClientCommand, model, expectedMessageClient, expectedModelClient);

assertCommandSuccess(editClientCommand, model, expectedMessageHousekeeper, expectedModelHousekeeper);
}

@Test
Expand All @@ -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());
Expand All @@ -100,7 +98,6 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
expectedModelHousekeeper.setHousekeeper(lastHousekeeper, editedHousekeeper);

assertCommandSuccess(editCommandClient, model, expectedMessageC, expectedModelClient);
assertCommandSuccess(editCommandHousekeeper, model, expectedMessageH, expectedModelHousekeeper);
}

@Test
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
17 changes: 8 additions & 9 deletions src/test/java/seedu/address/logic/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -94,20 +93,20 @@ 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
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());
}

Expand Down
53 changes: 27 additions & 26 deletions src/test/java/seedu/address/logic/parser/EditCommandParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -171,25 +172,25 @@ 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;

assertParseFailure(parser, userInput,
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,
Expand All @@ -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);
Expand Down

0 comments on commit 305f54f

Please sign in to comment.