Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #353 from fatclarence/branch-update-ug
Browse files Browse the repository at this point in the history
Add test for withdraw command
  • Loading branch information
seanlowjk authored Nov 11, 2019
2 parents 6280aa2 + 744c0b5 commit b0103ca
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WithdrawCommand extends Command {
+ "Restriction: " + Savings.MESSAGE_CONSTRAINTS + "\n"
+ "Example: " + COMMAND_WORD + " 100";

private static final String MESSAGE_WITHDRAW_SUCCESS = "Withdrawn from your Savings Account: $%1$s";
public static final String MESSAGE_WITHDRAW_SUCCESS = "Withdrawn from your Savings Account: $%1$s";

private final Savings withdrawalAmount; // withdrawal is a negative saving.

Expand All @@ -33,6 +33,9 @@ public WithdrawCommand(String savings) {

}

public WithdrawCommand(String savings, String time) {
this.withdrawalAmount = new Savings(savings, time, true);
}

@Override
public CommandResult execute(Model model) throws CommandException {
Expand Down
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);
}
}

0 comments on commit b0103ca

Please sign in to comment.