forked from nus-cs2103-AY2122S1/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 #235 from HongshuW/branch-testing
Add test cases
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/test/java/seedu/address/logic/commands/StatCommandTest.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,52 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_NUMBER_AMY; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PRODUCT; | ||
|
||
import java.time.LocalDate; | ||
import java.util.HashSet; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.ModelManager; | ||
import seedu.address.model.client.PhoneNumber; | ||
import seedu.address.model.commons.ID; | ||
import seedu.address.model.commons.Name; | ||
import seedu.address.model.order.Order; | ||
import seedu.address.model.product.Quantity; | ||
|
||
public class StatCommandTest { | ||
private Model model = new ModelManager(); | ||
|
||
@Test | ||
public void execute_noStatistics_throwCommandException() { | ||
StatCommand statCommand = new StatCommand(); | ||
assertThrows(CommandException.class, StatCommand.MESSAGE_FAILURE, () -> statCommand.execute(model)); | ||
} | ||
|
||
@Test | ||
public void execute_hasStatistics_success() { | ||
AddClientCommand.AddClientDescriptor descriptor = new AddClientCommand.AddClientDescriptor( | ||
new Name(VALID_NAME_AMY), new PhoneNumber(VALID_PHONE_NUMBER_AMY)); | ||
Order order = new Order(new ID(INDEX_FIRST_PRODUCT.getOneBased()), new Quantity("1"), LocalDate.now()); | ||
HashSet<Order> orders = new HashSet<>(); | ||
orders.add(order); | ||
descriptor.setOrders(orders); | ||
AddClientCommand addClientCommand = new AddClientCommand(descriptor); | ||
try { | ||
addClientCommand.execute(model); | ||
StatCommand statCommand = new StatCommand(); | ||
String actualFeedback = statCommand.execute(model).getFeedbackToUser(); | ||
String expectedFeedback = StatCommand.MESSAGE_SUCCESS; | ||
assertEquals(expectedFeedback, actualFeedback); | ||
} catch (CommandException e) { | ||
fail(); | ||
} | ||
} | ||
} |