This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 8ab23e7db3cec919027612d7213c3f795df58f93
Author: Matthieu Baechler <matth...@apache.org>
AuthorDate: Thu Nov 28 22:13:00 2019 +0100

    [Refactoring] use LocaleDatetime instead of Date to carry knowledge about 
the timezone
---
 .../org/apache/james/imap/decode/DecoderUtils.java |   7 +-
 .../james/imap/decode/ImapRequestLineReader.java   |   4 +-
 .../imap/decode/parser/AppendCommandParser.java    |  10 +-
 .../imap/decode/DecoderUtilsLocaleDateTest.java    | 397 ++++++++-------------
 .../apache/james/imap/decode/DecoderUtilsTest.java |  33 +-
 5 files changed, 172 insertions(+), 279 deletions(-)

diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/DecoderUtils.java 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/DecoderUtils.java
index 3ce137c..5207b71 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/DecoderUtils.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/DecoderUtils.java
@@ -19,8 +19,9 @@
 
 package org.apache.james.imap.decode;
 
+import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.util.Calendar;
-import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
 import java.util.TimeZone;
@@ -97,7 +98,7 @@ public final class DecoderUtils {
      * @throws DecodingException
      *             when this conversion fails
      */
-    public static Date decodeDateTime(CharSequence chars) throws 
DecodingException {
+    public static LocalDateTime decodeDateTime(CharSequence chars) throws 
DecodingException {
         if (isDateTime(chars)) {
             char dayHigh = chars.charAt(0);
             char dayLow = chars.charAt(1);
@@ -136,7 +137,7 @@ public final class DecoderUtils {
             GregorianCalendar calendar = new 
GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US);
             calendar.clear();
             calendar.set(year, month, day, hour, minute, second);
-            return calendar.getTime();
+            return LocalDateTime.ofInstant(calendar.getTime().toInstant(), 
ZoneId.systemDefault());
         } else {
             final String message;
             if (chars == null) {
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
index b4f5e75..a5b5bbe 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/ImapRequestLineReader.java
@@ -28,8 +28,8 @@ import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import javax.mail.Flags;
@@ -313,7 +313,7 @@ public abstract class ImapRequestLineReader {
     /**
      * Reads a "date-time" argument from the request.
      */
-    public Date dateTime() throws DecodingException {
+    public LocalDateTime dateTime() throws DecodingException {
         char next = nextWordChar();
         String dateString;
         if (next == '"') {
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
index 468fa87..2fbfc63 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/decode/parser/AppendCommandParser.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.imap.decode.parser;
 
+import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.util.Date;
 
 import javax.mail.Flags;
@@ -59,7 +61,7 @@ public class AppendCommandParser extends 
AbstractImapCommandParser {
      * If the next character in the request is a '"', tries to read a DateTime
      * argument. If not, returns null.
      */
-    public Date optionalDateTime(ImapRequestLineReader request) throws 
DecodingException {
+    public LocalDateTime optionalDateTime(ImapRequestLineReader request) 
throws DecodingException {
         char next = request.nextWordChar();
         if (next == '"') {
             return request.dateTime();
@@ -75,12 +77,12 @@ public class AppendCommandParser extends 
AbstractImapCommandParser {
         if (flags == null) {
             flags = new Flags();
         }
-        Date datetime = optionalDateTime(request);
+        LocalDateTime datetime = optionalDateTime(request);
         if (datetime == null) {
-            datetime = new Date();
+            datetime = LocalDateTime.now();
         }
         request.nextWordChar();
 
-        return new AppendRequest(command, mailboxName, flags, datetime, 
request.consumeLiteral(true), tag);
+        return new AppendRequest(command, mailboxName, flags, 
Date.from(datetime.atZone(ZoneId.systemDefault()).toInstant()), 
request.consumeLiteral(true), tag);
     }
 }
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
index dea3c1b..683618f 100644
--- 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsLocaleDateTest.java
@@ -21,278 +21,159 @@ package org.apache.james.imap.decode;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Locale;
+import java.util.stream.Stream;
 
 import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
 
-public class DecoderUtilsLocaleDateTest  {
+import reactor.util.function.Tuples;
 
-    private static final Locale BASE_DEFAULT_LOCALE = Locale.getDefault();
 
+public class DecoderUtilsLocaleDateTest {
+
+    private static final Locale BASE_DEFAULT_LOCALE = Locale.getDefault();
 
     @After
     public void tearDown() throws Exception {
         Locale.setDefault(BASE_DEFAULT_LOCALE);
     }
 
-    @Test
-    public void testUS() throws Exception {
-        runTests(Locale.US);
-    }
-
-    @Test
-    public void testITALY() throws Exception {
-        runTests(Locale.ITALY);
-    }
-
-    @Test
-    public void testTAIWAN() throws Exception {
-        runTests(Locale.TAIWAN);
-    }
-
-    @Test
-    public void testCHINA() throws Exception {
-        runTests(Locale.CHINA);
-    }
-
-    @Test
-    public void testKOREA() throws Exception {
-        runTests(Locale.KOREA);
-    }
-
-    @Test
-    public void testJAPAN() throws Exception {
-        runTests(Locale.JAPAN);
-    }
-
-    @Test
-    public void testUK() throws Exception {
-        runTests(Locale.UK);
+    static Stream<Arguments> decodeDateTimeWithVariousDefaultLocale() {
+        return
+            Stream.of(
+                Tuples.of("21-Oct-1972 20:00:00 +0000", "21 Oct 1972 20:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0100", "21 Oct 1972 19:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0200", "21 Oct 1972 18:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0300", "21 Oct 1972 17:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0400", "21 Oct 1972 16:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0500", "21 Oct 1972 15:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0600", "21 Oct 1972 14:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0700", "21 Oct 1972 13:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0800", "21 Oct 1972 12:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0900", "21 Oct 1972 11:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +1000", "21 Oct 1972 10:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +1100", "21 Oct 1972 09:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +1200", "21 Oct 1972 08:00:00 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:00:00 +1000", "21 Oct 1972 10:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0100", "21 Oct 1972 21:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0200", "21 Oct 1972 22:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0300", "21 Oct 1972 23:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0400", "22 Oct 1972 00:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0500", "22 Oct 1972 01:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0600", "22 Oct 1972 02:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0700", "22 Oct 1972 03:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0800", "22 Oct 1972 04:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0900", "22 Oct 1972 05:00:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -1000", "22 Oct 1972 06:00:00 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:00:00 +0030", "21 Oct 1972 19:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0130", "21 Oct 1972 18:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0230", "21 Oct 1972 17:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0330", "21 Oct 1972 16:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0430", "21 Oct 1972 15:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0530", "21 Oct 1972 14:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0630", "21 Oct 1972 13:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0730", "21 Oct 1972 12:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0830", "21 Oct 1972 11:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +0930", "21 Oct 1972 10:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +1030", "21 Oct 1972 09:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +1130", "21 Oct 1972 08:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 +1230", "21 Oct 1972 07:30:00 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:00:00 -0030", "21 Oct 1972 20:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0130", "21 Oct 1972 21:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0230", "21 Oct 1972 22:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0330", "21 Oct 1972 23:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0430", "22 Oct 1972 00:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0530", "22 Oct 1972 01:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0630", "22 Oct 1972 02:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0730", "22 Oct 1972 03:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0830", "22 Oct 1972 04:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -0930", "22 Oct 1972 05:30:00 
GMT"),
+                Tuples.of("21-Oct-1972 20:00:00 -1030", "22 Oct 1972 06:30:00 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:16:27 +0000", "21 Oct 1972 20:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0100", "21 Oct 1972 19:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0200", "21 Oct 1972 18:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0300", "21 Oct 1972 17:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0400", "21 Oct 1972 16:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0500", "21 Oct 1972 15:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0600", "21 Oct 1972 14:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0700", "21 Oct 1972 13:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0800", "21 Oct 1972 12:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0900", "21 Oct 1972 11:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +1000", "21 Oct 1972 10:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +1100", "21 Oct 1972 09:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +1200", "21 Oct 1972 08:16:27 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:16:27 -0000", "21 Oct 1972 20:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0100", "21 Oct 1972 21:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0200", "21 Oct 1972 22:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0300", "21 Oct 1972 23:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0400", "22 Oct 1972 00:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0500", "22 Oct 1972 01:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0600", "22 Oct 1972 02:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0700", "22 Oct 1972 03:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0800", "22 Oct 1972 04:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0900", "22 Oct 1972 05:16:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -1000", "22 Oct 1972 06:16:27 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:16:27 +0030", "21 Oct 1972 19:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0130", "21 Oct 1972 18:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0230", "21 Oct 1972 17:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0330", "21 Oct 1972 16:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0430", "21 Oct 1972 15:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0530", "21 Oct 1972 14:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0630", "21 Oct 1972 13:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0730", "21 Oct 1972 12:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0830", "21 Oct 1972 11:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +0930", "21 Oct 1972 10:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +1030", "21 Oct 1972 09:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +1130", "21 Oct 1972 08:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 +1230", "21 Oct 1972 07:46:27 
GMT"),
+
+                Tuples.of("21-Oct-1972 20:16:27 -0030", "21 Oct 1972 20:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0130", "21 Oct 1972 21:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0230", "21 Oct 1972 22:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0330", "21 Oct 1972 23:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0430", "22 Oct 1972 00:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0530", "22 Oct 1972 01:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0630", "22 Oct 1972 02:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0730", "22 Oct 1972 03:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0830", "22 Oct 1972 04:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -0930", "22 Oct 1972 05:46:27 
GMT"),
+                Tuples.of("21-Oct-1972 20:16:27 -1030", "22 Oct 1972 06:46:27 
GMT"))
+                .flatMap(tuple ->
+                    Stream.of(
+                        Locale.US,
+                        Locale.FRANCE,
+                        Locale.GERMANY,
+                        Locale.UK,
+                        Locale.CANADA,
+                        Locale.JAPAN,
+                        Locale.KOREA,
+                        Locale.CHINA,
+                        Locale.TAIWAN,
+                        Locale.ITALY
+                    ).map(locale -> Arguments.of(tuple.getT1(), tuple.getT2(), 
locale)));
     }
 
-    @Test
-    public void testCANADA() throws Exception {
-        runTests(Locale.CANADA);
-    }
-
-    @Test
-    public void testGERMANY() throws Exception {
-        runTests(Locale.GERMANY);
-    }
-
-    @Test
-    public void testFRANCH() throws Exception {
-        runTests(Locale.FRANCE);
-    }
-
-    
-    private void runTests(Locale locale) throws Exception {
+    @ParameterizedTest
+    @MethodSource
+    void decodeDateTimeWithVariousDefaultLocale(String input, String expected, 
Locale locale) throws Exception {
         Locale.setDefault(locale);
-        decodeDateTime();
-    }
-
-    @SuppressWarnings("deprecation")
-    private void decodeDateTime() throws Exception {
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0000").toGMTString()).isEqualTo("21 Oct 
1972 20:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0100").toGMTString()).isEqualTo("21 Oct 
1972 19:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0200").toGMTString()).isEqualTo("21 Oct 
1972 18:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0300").toGMTString()).isEqualTo("21 Oct 
1972 17:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0400").toGMTString()).isEqualTo("21 Oct 
1972 16:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0500").toGMTString()).isEqualTo("21 Oct 
1972 15:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0600").toGMTString()).isEqualTo("21 Oct 
1972 14:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0700").toGMTString()).isEqualTo("21 Oct 
1972 13:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0800").toGMTString()).isEqualTo("21 Oct 
1972 12:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0900").toGMTString()).isEqualTo("21 Oct 
1972 11:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1000").toGMTString()).isEqualTo("21 Oct 
1972 10:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1100").toGMTString()).isEqualTo("21 Oct 
1972 09:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1200").toGMTString()).isEqualTo("21 Oct 
1972 08:00:00 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1000").toGMTString()).isEqualTo("21 Oct 
1972 10:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0100").toGMTString()).isEqualTo("21 Oct 
1972 21:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0200").toGMTString()).isEqualTo("21 Oct 
1972 22:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0300").toGMTString()).isEqualTo("21 Oct 
1972 23:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0400").toGMTString()).isEqualTo("22 Oct 
1972 00:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0500").toGMTString()).isEqualTo("22 Oct 
1972 01:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0600").toGMTString()).isEqualTo("22 Oct 
1972 02:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0700").toGMTString()).isEqualTo("22 Oct 
1972 03:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0800").toGMTString()).isEqualTo("22 Oct 
1972 04:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0900").toGMTString()).isEqualTo("22 Oct 
1972 05:00:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -1000").toGMTString()).isEqualTo("22 Oct 
1972 06:00:00 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0030").toGMTString()).isEqualTo("21 Oct 
1972 19:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0130").toGMTString()).isEqualTo("21 Oct 
1972 18:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0230").toGMTString()).isEqualTo("21 Oct 
1972 17:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0330").toGMTString()).isEqualTo("21 Oct 
1972 16:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0430").toGMTString()).isEqualTo("21 Oct 
1972 15:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0530").toGMTString()).isEqualTo("21 Oct 
1972 14:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0630").toGMTString()).isEqualTo("21 Oct 
1972 13:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0730").toGMTString()).isEqualTo("21 Oct 
1972 12:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0830").toGMTString()).isEqualTo("21 Oct 
1972 11:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +0930").toGMTString()).isEqualTo("21 Oct 
1972 10:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1030").toGMTString()).isEqualTo("21 Oct 
1972 09:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1130").toGMTString()).isEqualTo("21 Oct 
1972 08:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 +1230").toGMTString()).isEqualTo("21 Oct 
1972 07:30:00 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0030").toGMTString()).isEqualTo("21 Oct 
1972 20:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0130").toGMTString()).isEqualTo("21 Oct 
1972 21:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0230").toGMTString()).isEqualTo("21 Oct 
1972 22:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0330").toGMTString()).isEqualTo("21 Oct 
1972 23:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0430").toGMTString()).isEqualTo("22 Oct 
1972 00:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0530").toGMTString()).isEqualTo("22 Oct 
1972 01:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0630").toGMTString()).isEqualTo("22 Oct 
1972 02:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0730").toGMTString()).isEqualTo("22 Oct 
1972 03:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0830").toGMTString()).isEqualTo("22 Oct 
1972 04:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -0930").toGMTString()).isEqualTo("22 Oct 
1972 05:30:00 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:00:00 -1030").toGMTString()).isEqualTo("22 Oct 
1972 06:30:00 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0000").toGMTString()).isEqualTo("21 Oct 
1972 20:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0100").toGMTString()).isEqualTo("21 Oct 
1972 19:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0200").toGMTString()).isEqualTo("21 Oct 
1972 18:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0300").toGMTString()).isEqualTo("21 Oct 
1972 17:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0400").toGMTString()).isEqualTo("21 Oct 
1972 16:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0500").toGMTString()).isEqualTo("21 Oct 
1972 15:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0600").toGMTString()).isEqualTo("21 Oct 
1972 14:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0700").toGMTString()).isEqualTo("21 Oct 
1972 13:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0800").toGMTString()).isEqualTo("21 Oct 
1972 12:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0900").toGMTString()).isEqualTo("21 Oct 
1972 11:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +1000").toGMTString()).isEqualTo("21 Oct 
1972 10:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +1100").toGMTString()).isEqualTo("21 Oct 
1972 09:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +1200").toGMTString()).isEqualTo("21 Oct 
1972 08:16:27 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0000").toGMTString()).isEqualTo("21 Oct 
1972 20:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0100").toGMTString()).isEqualTo("21 Oct 
1972 21:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0200").toGMTString()).isEqualTo("21 Oct 
1972 22:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0300").toGMTString()).isEqualTo("21 Oct 
1972 23:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0400").toGMTString()).isEqualTo("22 Oct 
1972 00:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0500").toGMTString()).isEqualTo("22 Oct 
1972 01:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0600").toGMTString()).isEqualTo("22 Oct 
1972 02:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0700").toGMTString()).isEqualTo("22 Oct 
1972 03:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0800").toGMTString()).isEqualTo("22 Oct 
1972 04:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0900").toGMTString()).isEqualTo("22 Oct 
1972 05:16:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -1000").toGMTString()).isEqualTo("22 Oct 
1972 06:16:27 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0030").toGMTString()).isEqualTo("21 Oct 
1972 19:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0130").toGMTString()).isEqualTo("21 Oct 
1972 18:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0230").toGMTString()).isEqualTo("21 Oct 
1972 17:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0330").toGMTString()).isEqualTo("21 Oct 
1972 16:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0430").toGMTString()).isEqualTo("21 Oct 
1972 15:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0530").toGMTString()).isEqualTo("21 Oct 
1972 14:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0630").toGMTString()).isEqualTo("21 Oct 
1972 13:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0730").toGMTString()).isEqualTo("21 Oct 
1972 12:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0830").toGMTString()).isEqualTo("21 Oct 
1972 11:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +0930").toGMTString()).isEqualTo("21 Oct 
1972 10:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +1030").toGMTString()).isEqualTo("21 Oct 
1972 09:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +1130").toGMTString()).isEqualTo("21 Oct 
1972 08:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 +1230").toGMTString()).isEqualTo("21 Oct 
1972 07:46:27 GMT");
-
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0030").toGMTString()).isEqualTo("21 Oct 
1972 20:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0130").toGMTString()).isEqualTo("21 Oct 
1972 21:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0230").toGMTString()).isEqualTo("21 Oct 
1972 22:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0330").toGMTString()).isEqualTo("21 Oct 
1972 23:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0430").toGMTString()).isEqualTo("22 Oct 
1972 00:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0530").toGMTString()).isEqualTo("22 Oct 
1972 01:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0630").toGMTString()).isEqualTo("22 Oct 
1972 02:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0730").toGMTString()).isEqualTo("22 Oct 
1972 03:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0830").toGMTString()).isEqualTo("22 Oct 
1972 04:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -0930").toGMTString()).isEqualTo("22 Oct 
1972 05:46:27 GMT");
-        assertThat(DecoderUtils.decodeDateTime(
-                "21-Oct-1972 20:16:27 -1030").toGMTString()).isEqualTo("22 Oct 
1972 06:46:27 GMT");
-
+        LocalDateTime localDateTime = DecoderUtils.decodeDateTime(input);
+        assertThat(ZonedDateTime.of(localDateTime, ZoneId.systemDefault())
+            .withZoneSameInstant(ZoneId.of("GMT"))
+            .format(DateTimeFormatter.ofPattern("dd MMM YYYY HH:mm:ss VV", 
Locale.US)))
+            .isEqualTo(expected);
     }
 }
diff --git 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
index 82bccee..19ad193 100644
--- 
a/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
+++ 
b/protocols/imap/src/test/java/org/apache/james/imap/decode/DecoderUtilsTest.java
@@ -22,6 +22,11 @@ package org.apache.james.imap.decode;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.Locale;
@@ -150,16 +155,21 @@ class DecoderUtilsTest {
 
     @ParameterizedTest
     @MethodSource
-    @SuppressWarnings("deprecation")
     void nominalDecodeDateTime(String input, String parsed) throws 
DecodingException {
-        
assertThat(DecoderUtils.decodeDateTime(input).toGMTString()).isEqualTo(parsed);
+        LocalDateTime localDateTime = DecoderUtils.decodeDateTime(input);
+        assertThat(ZonedDateTime.of(localDateTime, ZoneId.systemDefault())
+                .withZoneSameInstant(ZoneId.of("GMT"))
+                .format(DateTimeFormatter.ofPattern("dd MMM YYYY HH:mm:ss VV", 
Locale.US)))
+            .isEqualTo(parsed);
     }
 
     @Test
-    @SuppressWarnings("deprecation")
     void decodeDatetimeShouldAllowAppleMailPrependsZeroNotSpace() throws 
Exception {
-        assertThat(DecoderUtils.decodeDateTime("09-Apr-2008 15:17:51 
+0200").toGMTString())
-            .isEqualTo("9 Apr 2008 13:17:51 GMT");
+        LocalDateTime localDateTime = DecoderUtils.decodeDateTime("09-Apr-2008 
15:17:51 +0200");
+        assertThat(ZonedDateTime.of(localDateTime, ZoneId.systemDefault())
+                .withZoneSameInstant(ZoneId.of("GMT"))
+                .format(DateTimeFormatter.ofPattern("dd MMM YYYY HH:mm:ss VV", 
Locale.US)))
+            .isEqualTo("09 Apr 2008 13:17:51 GMT");
     }
 
     static Stream<Arguments> nominalDecodeDateTimeWithTimezone() {
@@ -218,7 +228,7 @@ class DecoderUtilsTest {
                 1246838821081L,
                 1226795970848L,
                 1260254185119L
-            ).mapToObj(Date::new)
+            ).mapToObj(Instant::ofEpochMilli)
             .collect(Collectors.toSet())
         ).stream()
             .map(list -> Arguments.of(list.toArray()));
@@ -226,12 +236,11 @@ class DecoderUtilsTest {
 
     @ParameterizedTest
     @MethodSource
-    void nominalDecodeDateTimeWithTimezone(TimeZone zone, Date date) throws 
Exception {
-        FastDateFormat format = FastDateFormat.getInstance("dd-MMM-yyyy 
hh:mm:ss Z", zone, Locale.US);
-        String in = format.format(date);
-        Date decodedDate = DecoderUtils.decodeDateTime(in);
-        String out = format.format(decodedDate);
-        assertThat(out).describedAs("Round trip").isEqualTo(in);
+    void nominalDecodeDateTimeWithTimezone(TimeZone zone, Instant date) throws 
Exception {
+        FastDateFormat format = FastDateFormat.getInstance("dd-MMM-yyyy 
HH:mm:ss Z", zone, Locale.US);
+        String in = format.format(Date.from(date));
+        LocalDateTime decodedDate = DecoderUtils.decodeDateTime(in);
+        
assertThat(decodedDate.atZone(ZoneId.systemDefault())).describedAs("Round 
trip").isEqualToIgnoringNanos(ZonedDateTime.ofInstant(date, zone.toZoneId()));
     }
 
     static Stream<Arguments> nominalDecodeDigit() {


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to