Skip to content

Commit

Permalink
Merge pull request #290 from AY2223S1-CS2103T-W16-4/174-add-tests-in-…
Browse files Browse the repository at this point in the history
…addclientcommand

Add test cases in AddClientCommandParserTest
  • Loading branch information
ThomasHoooo authored Nov 1, 2022
2 parents e25e21b + be64fd0 commit 045e5dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"address" : "10th street",
"birthday" : "",
"meetings" : [ ],
"products" : [ "friends" ]
"products" : [ "Product2" ]
}, {
"@UUID" : "deed0742-5740-4514-87e7-bd9bef479046",
"name" : "Elle Meyer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PRODUCT_DESC;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
Expand Down Expand Up @@ -42,6 +43,7 @@
import seedu.address.model.client.Email;
import seedu.address.model.client.Name;
import seedu.address.model.client.Phone;
import seedu.address.model.product.Product;
import seedu.address.testutil.ClientBuilder;

public class AddClientCommandParserTest {
Expand Down Expand Up @@ -121,6 +123,10 @@ public void parse_invalidValue_failure() {
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC
+ PRODUCT_DESC_PRODUCT2 + PRODUCT_DESC_PRODUCT1, Address.MESSAGE_CONSTRAINTS);

// invalid product
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ INVALID_PRODUCT_DESC + PRODUCT_DESC_PRODUCT1, Product.MESSAGE_CONSTRAINTS);

// two invalid values, only first invalid value reported
assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC,
Name.MESSAGE_CONSTRAINTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

public class EditCommandParserTest {

private static final String Product_EMPTY = " " + PREFIX_PRODUCT;
private static final String PRODUCT_EMPTY = " " + PREFIX_PRODUCT;

private static final String MESSAGE_INVALID_FORMAT =
String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditClientCommand.MESSAGE_USAGE);
Expand Down Expand Up @@ -94,6 +94,15 @@ public void parse_invalidValue_failure() {
// is tested at {@code parse_invalidValueFollowedByValidValue_success()}
assertParseFailure(parser, " i/1" + PHONE_DESC_BOB + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS);

// while parsing {@code PREFIX_PRODUCT} alone will reset the products of the {@code Client} being edited,
// parsing it together with a valid product results in error
assertParseFailure(parser, " i/1" + PRODUCT_DESC_PRODUCT1 + PRODUCT_DESC_PRODUCT2 + PRODUCT_EMPTY,
Product.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, " i/1" + PRODUCT_DESC_PRODUCT1 + PRODUCT_EMPTY + PRODUCT_DESC_PRODUCT2,
Product.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, " i/1" + PRODUCT_EMPTY + PRODUCT_DESC_PRODUCT1 + PRODUCT_DESC_PRODUCT2,
Product.MESSAGE_CONSTRAINTS);

// multiple invalid values, but only the first invalid value is captured
assertParseFailure(parser, " i/1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC
+ VALID_ADDRESS_AMY + VALID_PHONE_AMY, Name.MESSAGE_CONSTRAINTS);
Expand Down Expand Up @@ -195,7 +204,7 @@ public void parse_invalidValueFollowedByValidValue_success() {
@Test
public void parse_resetProducts_success() {
Index targetIndex = INDEX_THIRD_ELEMENT;
String userInput = " i/" + targetIndex.getOneBased() + Product_EMPTY;
String userInput = " i/" + targetIndex.getOneBased() + PRODUCT_EMPTY;

EditClientDescriptor descriptor = new EditClientDescriptorBuilder().withProducts().build();
EditClientCommand expectedCommand = new EditClientCommand(targetIndex, descriptor);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/testutil/TypicalClients.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TypicalClients {
.withEmail("heinz@example.com").withAddress("wall street")
.build();
public static final Client DANIEL = new ClientBuilder().withName("Daniel Meier").withPhone("87652533")
.withEmail("cornelia@example.com").withAddress("10th street").withProducts("friends").build();
.withEmail("cornelia@example.com").withAddress("10th street").withProducts("Product2").build();
public static final Client ELLE = new ClientBuilder().withName("Elle Meyer").withPhone("94822241")
.withEmail("werner@example.com").withAddress("michegan ave").build();
public static final Client FIONA = new ClientBuilder().withName("Fiona Kunz").withPhone("94824271")
Expand Down

0 comments on commit 045e5dc

Please sign in to comment.