Storing Some Fruit

For the sake of simplicity, let’s use the second simplest data store after memory—a file. Let’s get our step definition to write out the fruit information to a file:

rest_web_services/02/src/test/java/fruit/FruitSteps.java
Line 1 
package​ fruit;
import​ com.google.gson.Gson;
import​ cucumber.api.java.en.*;
import​ java.io.PrintWriter;
import​ java.util.List;
10 
public​ ​class​ FruitSteps {
@Given(​"^the system knows about the following fruit:$"​)
public​ ​void​ theSystemKnowsAboutTheFollowingFruit(​List​<Fruit> fruitList)
throws​ ​Throwable​ {
Gson gson = ​new​ Gson();
15 
PrintWriter​ writer = ​new​ ​PrintWriter​(​"fruit.json"​, ​"UTF-8"​);
writer.println(gson.toJson(fruitList)); ...

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.