This repository has been archived by the owner on Apr 28, 2021. It is now read-only.
forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 6
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 #353 from fatclarence/branch-update-ug
Add test for withdraw command
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
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
54 changes: 54 additions & 0 deletions
54
src/test/java/seedu/savenus/logic/commands/WithdrawCommandTest.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,54 @@ | ||
package seedu.savenus.logic.commands; | ||
|
||
import static seedu.savenus.logic.commands.CommandTestUtil.assertCommandSuccess; | ||
import static seedu.savenus.testutil.TypicalMenu.getTypicalMenu; | ||
import static seedu.savenus.testutil.TypicalWallet.getTypicalWallet; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.savenus.model.Model; | ||
import seedu.savenus.model.ModelManager; | ||
import seedu.savenus.model.alias.AliasList; | ||
import seedu.savenus.model.purchase.PurchaseHistory; | ||
import seedu.savenus.model.recommend.UserRecommendations; | ||
import seedu.savenus.model.savings.CurrentSavings; | ||
import seedu.savenus.model.savings.Savings; | ||
import seedu.savenus.model.savings.SavingsAccount; | ||
import seedu.savenus.model.savings.SavingsHistory; | ||
import seedu.savenus.model.savings.exceptions.InsufficientSavingsException; | ||
import seedu.savenus.model.sort.CustomSorter; | ||
import seedu.savenus.model.userprefs.UserPrefs; | ||
import seedu.savenus.model.util.Money; | ||
import seedu.savenus.model.util.TimeStamp; | ||
|
||
/** | ||
* Contains integration tests (interaction with the model) and unit tests for | ||
* {@code WithdrawCommand} | ||
*/ | ||
public class WithdrawCommandTest { | ||
|
||
private Model model = new ModelManager(getTypicalMenu(), new UserPrefs(), new UserRecommendations(), | ||
new PurchaseHistory(), getTypicalWallet(), new CustomSorter(), new SavingsHistory(), | ||
new SavingsAccount(new CurrentSavings(new Money("200.00"))), | ||
new AliasList()); | ||
|
||
@Test | ||
public void execute_validWithdrawalsAmount_success() { | ||
String time = TimeStamp.generateCurrentTimeStamp(); | ||
WithdrawCommand withdrawCommand = new WithdrawCommand("10.00", time); | ||
Savings testWithdraw = new Savings("10.00", time, true); | ||
String expectedMessage = String.format(WithdrawCommand.MESSAGE_WITHDRAW_SUCCESS, testWithdraw.toString()); | ||
ModelManager expectedModel = new ModelManager(model.getMenu(), new UserPrefs(), new UserRecommendations(), | ||
new PurchaseHistory(), model.getWallet(), new CustomSorter(), | ||
new SavingsHistory(), | ||
new SavingsAccount(new CurrentSavings(new Money("200.00"))), | ||
new AliasList()); | ||
try { | ||
expectedModel.withdrawFromSavings(testWithdraw); | ||
expectedModel.addToHistory(testWithdraw); | ||
} catch (InsufficientSavingsException e) { | ||
System.err.println("This should never be executed"); | ||
} | ||
assertCommandSuccess(withdrawCommand, model, expectedMessage, expectedModel); | ||
} | ||
} |