-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWalletStepDefinitions.java
More file actions
63 lines (53 loc) · 1.85 KB
/
WalletStepDefinitions.java
File metadata and controls
63 lines (53 loc) · 1.85 KB
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
package com.example.testing.bdd;
import com.example.testing.bdd.Wallet;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.Map;
import java.util.HashMap;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
public class WalletStepDefinitions {
private int ids = 1;
private final Map<String, Wallet> users = new HashMap<>();
private Exception thrown;
@Given("{string} has a balance of £{double}")
public void userHasBalance(String name, double balance) {
users.put(name, new Wallet(ids++, name, balance));
}
@When("{string} tries to pay {string} £{double}")
public void userTriesToPay(String a, String b, double amount) {
var userA = users.get(a);
var userB = users.get(b);
try {
userA.pay(userB, amount);
} catch (Exception e) {
thrown = e;
}
}
@When("{string} tries to withdraw £{double}")
public void userTriesToWithdraw(String name, double amount) {
var user = users.get(name);
try {
user.withdraw(amount);
} catch (Exception e) {
thrown = e;
}
}
@Then("we get an insufficient funds error")
public void insufficientFundsError() {
assertThat(thrown)
.isNotNull()
.isInstanceOf(Wallet.InsufficientFundsException.class);
}
@Then("we get an invalid transaction error")
public void invalidAmountError() {
assertThat(thrown)
.isNotNull()
.isInstanceOf(Wallet.InvalidAmountException.class);
}
@Then("{string} will have a balance of £{double}")
public void userNowHasBalance(String name, double balance) {
var user = users.get(name);
assertThat(user.getBalance()).isEqualTo(balance);
}
}