@Test
public final void testFrontVehicle() {

    RoadSegment.resetNextId();
    final double roadLength = 1000.0;
    final int laneCount = 1;
    final RoadSegment roadSegment = new RoadSegment(roadLength, laneCount);
    Vehicle.resetNextId();
    final Vehicle v0 = newVehicle(900.0, 1.0, Lanes.LANE1);
    roadSegment.addVehicle(v0);
    Vehicle fV = roadSegment.frontVehicle(Lanes.LANE1, 900.0);
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 1000.0);
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 901.0);
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 899.0);
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 0.0);
    assertEquals(v0, fV);
    final Vehicle v1 = newVehicle(800.0, 2.0, Lanes.LANE1);
    roadSegment.addVehicle(v1);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 900.0);
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 800.0);
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 901.0);
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 899.0);
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 801.0);
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 799.0);
    assertEquals(v1, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 0.0);
    assertEquals(v1, fV);
    final Vehicle v2 = newVehicle(700.0, 3.0, Lanes.LANE1);
    roadSegment.addVehicle(v2);
    fV = roadSegment.frontVehicle(Lanes.LANE1, v0.getMidPosition());
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, v1.getMidPosition());
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, v2.getMidPosition());
    assertEquals(v1, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 901.0);
    assertEquals(null, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 899.0);
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 801.0);
    assertEquals(v0, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 799.0);
    assertEquals(v1, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 701.0);
    assertEquals(v1, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 699.0);
    assertEquals(v2, fV);
    fV = roadSegment.frontVehicle(Lanes.LANE1, 0.0);
    assertEquals(v2, fV);
}