averbraeck / opentrafficsim

Open Source Multi-Level Traffic Simulator
BSD 3-Clause "New" or "Revised" License
29 stars 11 forks source link

GtuDumperTest does not work anymore and has to be updated #65

Closed averbraeck closed 3 weeks ago

averbraeck commented 1 year ago

GtuDumperTest in ots-core used to have a method createGTU (now createGtuDeprecated), but most lines have been commented out. The test needs a few updates, but does not prevent an OTS release from being built right now, so it is not urgent.

WJSchakel commented 3 weeks ago

The code that does not work is:

Gtu gtu = new Gtu()
{
    @Override
    public OrientedPoint2d getLocation()
    {
        // This GTU travels a circle around 100, 20, elevation 10, radius 20, angular velocity 0.1 radial / second
        double timeSI = GtuDumperTest.this.simulator.getSimulatorTime().si;
        double angle = timeSI / 10;
        return new OrientedPoint2d(100 + 20 * Math.cos(angle), 20 + 20 * Math.sin(angle), angle + Math.PI / 2);
    }
};

Gtu needs al sorts of input parameters. It has been replaced with:

Gtu gtu = Mockito.mock(Gtu.class);
Mockito.when(gtu.getLocation()).thenAnswer((invocationOnMock) ->
{
    // This GTU travels a circle around 100, 20, elevation 0, radius 20, angular velocity 0.1 radial / second
    double timeSI = GtuDumperTest.this.simulator.getSimulatorTime().si;
    double angle = AngleUtil.normalizeAroundPi(timeSI / 10.0);
    return new OrientedPoint2d(100.0 + 20.0 * Math.cos(angle), 20.0 + 20.0 * Math.sin(angle), angle);
});
Mockito.when(gtu.getSpeed()).thenReturn(Speed.instantiateSI(2.0));
Mockito.when(gtu.toString()).thenReturn("test GTU");

The unit test works again.