How to do it...

The mock of FactoryTraffic may look like the following:

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 hardcode the values:

public static TrafficUnit getOneUnit ...

Get Java 11 Cookbook 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.