forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from 0-yibai/edit-order-command
Add test cases for edit order parser and re-structure edit order command
- Loading branch information
Showing
11 changed files
with
206 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/test/java/seedu/address/logic/parser/EditOrderCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PRODUCT_DESC; | ||
import static seedu.address.logic.commands.CommandTestUtil.INVALID_QUANTITY_DESC; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_PRODUCT_DOUGHNUT; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_QUANTITY_ONE; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_QUANTITY_THREE; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_QUANTITY_TWO; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_ORDER; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRODUCT_QUANTITY; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_THIRD_PERSON; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.EditOrderCommand; | ||
import seedu.address.model.order.Product; | ||
import seedu.address.model.order.Quantity; | ||
import seedu.address.testutil.EditOrderDescriptorBuilder; | ||
|
||
public class EditOrderCommandParserTest { | ||
private static final String MESSAGE_INVALID_FORMAT = | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditOrderCommand.MESSAGE_USAGE); | ||
|
||
private EditOrderCommandParser parser = new EditOrderCommandParser(); | ||
|
||
@Test | ||
public void parse_missingParts_failure() { | ||
// no field specified | ||
assertParseFailure(parser, " " + PREFIX_ORDER + "1", EditOrderCommand.MESSAGE_NOT_EDITED); | ||
|
||
// no index and no field specified | ||
assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); | ||
} | ||
|
||
@Test | ||
public void parse_invalidValue_failure() { | ||
assertParseFailure(parser, " " + PREFIX_ORDER + "1" + INVALID_PRODUCT_DESC, | ||
Product.MESSAGE_CONSTRAINTS); // invalid name | ||
assertParseFailure(parser, " " + PREFIX_ORDER + "1" + INVALID_QUANTITY_DESC, | ||
Quantity.MESSAGE_CONSTRAINTS); // invalid phone | ||
|
||
// invalid product followed by valid quantity | ||
assertParseFailure(parser, " " + PREFIX_ORDER + "1" + INVALID_PRODUCT_DESC | ||
+ PREFIX_PRODUCT_QUANTITY + " " + VALID_QUANTITY_ONE, Product.MESSAGE_CONSTRAINTS); | ||
|
||
// multiple invalid values, but only the first invalid value is captured | ||
assertParseFailure(parser, " " + PREFIX_ORDER + "1" + INVALID_PRODUCT_DESC | ||
+ INVALID_QUANTITY_DESC, Product.MESSAGE_CONSTRAINTS); | ||
} | ||
|
||
@Test | ||
public void parse_bothFieldsSpecified_success() { | ||
Index targetIndex = INDEX_SECOND_PERSON; | ||
String userInput = " " + PREFIX_ORDER + targetIndex.getOneBased() + " " + PREFIX_PRODUCT_NAME + " " | ||
+ VALID_PRODUCT_DOUGHNUT + " " + PREFIX_PRODUCT_QUANTITY + " " + VALID_QUANTITY_TWO; | ||
|
||
EditOrderCommand.EditOrderDescriptor descriptor = new EditOrderDescriptorBuilder() | ||
.withProduct(VALID_PRODUCT_DOUGHNUT) | ||
.withQuantity(Integer.parseInt(VALID_QUANTITY_TWO)) | ||
.build(); | ||
|
||
EditOrderCommand expectedCommand = new EditOrderCommand(targetIndex, descriptor); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_oneFieldSpecified_failure() { | ||
// product only | ||
Index targetIndex = INDEX_THIRD_PERSON; | ||
String userInput = " " + PREFIX_ORDER + targetIndex.getOneBased() | ||
+ " " + PREFIX_PRODUCT_NAME + VALID_PRODUCT_DOUGHNUT; | ||
EditOrderCommand.EditOrderDescriptor descriptor = new EditOrderDescriptorBuilder() | ||
.withProduct(VALID_PRODUCT_DOUGHNUT).build(); | ||
assertParseFailure(parser, userInput, EditOrderCommand.MESSAGE_NOT_EDITED); | ||
|
||
// quantity only | ||
userInput = " " + PREFIX_ORDER + targetIndex.getOneBased() | ||
+ " " + PREFIX_PRODUCT_QUANTITY + VALID_QUANTITY_THREE; | ||
descriptor = new EditOrderDescriptorBuilder() | ||
.withQuantity(Integer.parseInt(VALID_QUANTITY_THREE)).build(); | ||
assertParseFailure(parser, userInput, EditOrderCommand.MESSAGE_NOT_EDITED); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/java/seedu/address/testutil/EditOrderDescriptorBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package seedu.address.testutil; | ||
|
||
import seedu.address.logic.commands.EditOrderCommand; | ||
import seedu.address.model.order.Product; | ||
import seedu.address.model.order.Quantity; | ||
|
||
/** | ||
* A utility class to help with building EditOrderDescriptor objects. | ||
*/ | ||
public class EditOrderDescriptorBuilder { | ||
private EditOrderCommand.EditOrderDescriptor descriptor; | ||
|
||
public EditOrderDescriptorBuilder() { | ||
descriptor = new EditOrderCommand.EditOrderDescriptor(); | ||
} | ||
|
||
public EditOrderDescriptorBuilder(EditOrderCommand.EditOrderDescriptor descriptor) { | ||
this.descriptor = new EditOrderCommand.EditOrderDescriptor(descriptor); | ||
} | ||
|
||
/** | ||
* Returns an {@code EditPersonDescriptor} with fields containing {@code person}'s details | ||
*/ | ||
public EditOrderDescriptorBuilder(Product product, Quantity quantity) { | ||
descriptor = new EditOrderCommand.EditOrderDescriptor(); | ||
descriptor.setProduct(product); | ||
descriptor.setQuantity(quantity); | ||
} | ||
|
||
/** | ||
* Sets the {@code Name} of the {@code EditPersonDescriptor} that we are building. | ||
*/ | ||
public EditOrderDescriptorBuilder withProduct(String product) { | ||
descriptor.setProduct(new Product(product)); | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the {@code Name} of the {@code EditPersonDescriptor} that we are building. | ||
*/ | ||
public EditOrderDescriptorBuilder withQuantity(int quantity) { | ||
descriptor.setQuantity(new Quantity(quantity)); | ||
return this; | ||
} | ||
|
||
public EditOrderCommand.EditOrderDescriptor build() { | ||
return descriptor; | ||
} | ||
} |