-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathSavingsAccountTest.java
67 lines (57 loc) · 2.25 KB
/
SavingsAccountTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package bankService;
import bankService.exceptions.InsufficientFundsException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.Assert.*;
public class SavingsAccountTest {
Customer customer;
SavingsAccount savings;
@BeforeClass
public void oneTimeSetup() {
customer = new Customer ("Mickey Mouse", "Disneyland", "[email protected]");
}
@BeforeMethod
public void eachTimeSetup() {
savings = new SavingsAccount(customer, 100.00, 123456789);
}
/**
* Customers should be able to withdraw from their savings account.
* Scenario:
* 1. Given a customer's savings account with an initial balance of $100.00
* 2. When I withdraw $60.00 from the account
* 3. Then the new account balance is $40.00
*/
@Test(dataProvider ="ValidWithdrawDataProvider")
public void withdrawingValidAmountFromSavingsAccount_DecreasesBalanceByAmount(double amount, double expectedBalance) throws InsufficientFundsException {
// When
savings.withdraw(amount);
// Then
assertEquals(savings.getBalance(), expectedBalance);
}
@DataProvider(name= "ValidWithdrawDataProvider")
private Object[][] createValidWithdrawData() {
return new Object[][] {
{60.0, 40.0},
{100.0, 0.0}};
}
/**
* Customers should not be able to withdraw more than their available savings account balance
* Scenario:
* 1. Given a customer's savings account with an initial balance of $100.00
* 2. When I attempt to withdraw $200.00
* 3. Then an exception should occur indicating that there are insufficient funds in the account
* 4. And the account balance should remain unchanged.
*/
@Test
public void withdrawingAmountGreaterThanBalance_Throws_InsufficientFundsException() throws InsufficientFundsException {
try {
savings.withdraw(200.00);
fail("Expected Insufficient Funds Exception but none is thrown");
} catch (InsufficientFundsException e){
// Then
assertEquals(savings.getBalance(), 100.00);
}
}
}