How to Synchronize

In our current implementation, the debit and credit transactions are processed synchronously by our simplistic Account class:

support_code/17/src/main/java/nicebank/Account.java
 
package​ nicebank;
 
 
public​ ​class​ Account {
 
private​ Money balance = ​new​ Money();
 
 
public​ ​void​ credit(Money amount) {
 
balance = balance.add(amount);
 
}
 
 
public​ ​void​ debit(​int​ dollars) {
 
balance = balance.minus(​new​ Money(dollars, 0));
 
}
 
 
public​ Money getBalance() {
 
return​ balance;
 
}
 
}

This implementation, where the balance is updated during the method call to credit or debit, means that we can be certain the balance will have been updated by the time Cucumber checks the account balance in the final ...

Get The Cucumber for Java Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.