O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

Here is how the mock of FactoryTraffic will look like:

public class FactoryTraffic {  public static List<TrafficUnit> generateTraffic(int     trafficUnitsNumber, Month month, DayOfWeek dayOfWeek,     int hour, String country, String city, String trafficLight){    List<TrafficUnit> tms = new ArrayList();    for (int i = 0; i < trafficUnitsNumber; i++) {      TrafficUnit trafficUnit =         FactoryTraffic.getOneUnit(month, dayOfWeek,  hour, country,                                   city, trafficLight);        tms.add(trafficUnit);    }    return tms;  }}

It assembles a collection of TrafficUnit objects. In a real system, these objects would be created from the rows of the result of some database query, for example. But in our case, we just mock the result:

 

public static TrafficUnit getOneUnit ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required