### Question:
TrafficDensity2 { private CountByLane countByLane(int lanesNumber, double[] speedLimit, double speed){ for(int i = 1; i <= lanesNumber; i++){ if(speed <= speedLimit[i - 1]){ return new CountByLane(1, i); } } return new CountByLane(1, lanesNumber); }  Integer[] trafficByLane(Stream<TrafficUnit> stream, int trafficUnitsNumber, double timeSec,
                                   SpeedModel speedModel, double[] speedLimitByLane);  }### Answer:
@Test public void testCountByLane() { int[] count ={0}; double[] speeds = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; TrafficDensity2 trafficDensity = new TrafficDensity2(){ @Override protected double calcSpeed(Vehicle vehicle, double traction, double timeSec) { return speeds[count[0]++]; } }; double timeSec = 10.0; int trafficUnitsNumber = speeds.length; double[] speedLimitByLane = {4.5, 8.5, 12.5}; Integer[] expectedCountByLane = {4, 4, 4}; Integer[] trafficByLane = trafficDensity.trafficByLane(getTrafficUnitStream(trafficUnitsNumber), trafficUnitsNumber, timeSec, FactorySpeedModel.getSpeedModel(), speedLimitByLane ); assertArrayEquals("Assert count of " + speeds.length + " vehicles by " + speedLimitByLane.length + " lanes with speed limit " + Arrays.stream(speedLimitByLane).mapToObj(Double::toString).collect(Collectors.joining(", ")), expectedCountByLane, trafficByLane); }