Slide 30
Slide 30 text
public class DiscountStepdefs {
private List cart = new LinkedList<>();
!
@When("^I buy (\\d+) copies of \”([^\”]*)\"$")
public void I_buy_copies_of(int numberOfCopies, String title) {
Book book = bookByTitle(title)
.orElseThrow(() -> new UnknownTitle(title));
range(0, numberOfCopies)
.forEach(n -> this.cart.add(book));
}
!
@Then("^I must pay \\$(\\d+.?\\d*)$")
public void I_must_pay_$_(float amount) {
Long expected = Float.valueOf(amount * 100).longValue();
ShoppingCart shoppingCart = new ShoppingCart(this.cart);
Long total = shoppingCart.calculateTotal();
assertThat(total, is(expected));
}
!
// ..
}
!
class Book { .. }
!
class ShoppingCart {
public ShoppingCart(List cart) {}
public Long calculateTotal() { return -1L; }
}