From 718c38aa2468c4824b7dfbd8afb161bb76c43222 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 14 Oct 2017 19:51:26 +0200 Subject: [PATCH] Fix failing LoginSecurityConverterTest: allow tolerance for java.sql.Date to millis conversion --- .../datasource/converter/LoginSecurityConverterTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/fr/xephi/authme/datasource/converter/LoginSecurityConverterTest.java b/src/test/java/fr/xephi/authme/datasource/converter/LoginSecurityConverterTest.java index 4a7e94fe6..d3ad34f0f 100644 --- a/src/test/java/fr/xephi/authme/datasource/converter/LoginSecurityConverterTest.java +++ b/src/test/java/fr/xephi/authme/datasource/converter/LoginSecurityConverterTest.java @@ -88,6 +88,10 @@ public class LoginSecurityConverterTest { assertIsCloseTo(captor.getAllValues().get(2).getRegistrationDate(), System.currentTimeMillis(), 500L); } + // Note ljacqu 20171014: JDBC mapping of a Date column to a java.sql.Date is difficult to handle, + // cf. https://stackoverflow.com/questions/9202857/timezones-in-sql-date-vs-java-sql-date + // For H2 it looks like Date#getTime returns the millis of the date at 12AM in the system's timezone, + // so we check with a margin of 12 hours to cover most cases... @Test public void shouldConvertFromMySql() throws IOException, SQLException { // given @@ -105,7 +109,7 @@ public class LoginSecurityConverterTest { assertThat(captor.getAllValues().get(0).getLastLogin(), equalTo(1494242093000L)); assertThat(captor.getAllValues().get(0).getPassword(), equalToHash("$2a$10$E1Ri7XKeIIBv4qVaiPplgepT7QH9xGFh3hbHfcmCjq7hiW.UBTiGK")); assertThat(captor.getAllValues().get(0).getLastIp(), equalTo("127.0.0.1")); - assertThat(captor.getAllValues().get(0).getRegistrationDate(), equalTo(1494194400000L)); + assertIsCloseTo(captor.getAllValues().get(0).getRegistrationDate(), 1494201600000L, 12 * 60 * 60 * 1000); assertThat(captor.getAllValues().get(1).getNickname(), equalTo("player2")); assertThat(captor.getAllValues().get(1).getLastLogin(), equalTo(1489317753000L));