Arakne / Araknemu

Simple Dofus server in Java
GNU Lesser General Public License v3.0
105 stars 28 forks source link

Fix: Error with test lastLogin in InformationTest.java #309

Closed Jean-Dv closed 11 months ago

Jean-Dv commented 11 months ago

Error

When I try to run the tests, I get the following error. image

This error is generated because the Information.lastLogin method uses the system's default zoneId.

Fix

To correct, the methods are overwritten, in which a parameter is passed, which refers to the zoneId image

vincent4vx commented 11 months ago

Hi !

Thanks for the PR, but your fix is not enough, because it creates a new methods which is never used anywhere but in tests.

To mitigate this issue, I have 3 solutions in mind:

Quick and dirty fix

The simplest fix is to add

TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Europe/Paris")));

on GameBaseGame#setUp(), and let the code unchanged. With this, the default system locale will be set to Europe/Paris.

Use LocalDateTime as parameter

Change the prototype of Information#lastLogin() to takes a LocalDateTime instead of Instant as first parameter. So, it will be the responsability of the caller to define the current timezone. And on the unity test, you simply have to create the date on the Europe/Paris timezone.

Configure timezone for the server

This is the most complete solution. First you need to implements the previous solution, and then define into GameConfiguration the timezone to used for the current server instance. Then inject the configuration on SelectCharacter constructor, and use the configured timezone for creates the corresponding LocalDateTime.

Jean-Dv commented 11 months ago

Ok, thanks for the response. I will be adding the most complete solution and will resubmit the changes to this same PR.