Testing Our Checkout Class

To implement the next step, edit step_definitions/CheckoutSteps.java so that the second step definition looks like this:

first_taste/07/step_definitions/CheckoutSteps.java
 
@When(​"^I checkout (\\d+) \"(.*?)\"$"​)
 
public​ ​void​ iCheckout(​int​ itemCount, ​String​ itemName) ​throws​ ​Throwable​ {
 
Checkout checkout = ​new​ Checkout();
 
checkout.add(itemCount, bananaPrice);
 
}

This code attempts to call an add() on an instance of our Checkout class, passing it the number of items being bought and their price.

This time when we run ./cucumber, we should get a compile error because we haven’t created a Checkout class yet:

 
step_definitions/CheckoutSteps.java:15: error: cannot find symbol
 
Checkout checkout = ...

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.