You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/06/05 03:21:27 UTC

[1/3] james-mime4j git commit: JAMES-2045 Add century when parsing dates without

Repository: james-mime4j
Updated Branches:
  refs/heads/master 5c5830375 -> 5acd2cf3c


JAMES-2045 Add century when parsing dates without


Project: http://git-wip-us.apache.org/repos/asf/james-mime4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-mime4j/commit/7829f79a
Tree: http://git-wip-us.apache.org/repos/asf/james-mime4j/tree/7829f79a
Diff: http://git-wip-us.apache.org/repos/asf/james-mime4j/diff/7829f79a

Branch: refs/heads/master
Commit: 7829f79a69bd3f07bfea324edbb30ab850b8c886
Parents: 5c58303
Author: Antoine Duprat <ad...@linagora.com>
Authored: Fri Jun 2 15:29:50 2017 +0200
Committer: benwa <bt...@linagora.com>
Committed: Mon Jun 5 10:15:47 2017 +0700

----------------------------------------------------------------------
 .../mime4j/field/datetime/DateTimeParser.jj     | 10 ++-
 .../mime4j/field/DateTimeFieldImplTest.java     | 73 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/7829f79a/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
----------------------------------------------------------------------
diff --git a/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj b/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
index ff1adf6..7b9b490 100644
--- a/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
+++ b/dom/src/main/javacc/org/apache/james/mime4j/field/datetime/DateTimeParser.jj
@@ -225,7 +225,15 @@ int month() :
 String year() :
 {Token t;}
 {
-    t=<DIGITS> { return t.image; }
+    t=<DIGITS> 
+    {
+      String year = (String) t.image;
+      if (year.length() == 2) 
+      {
+        return "20" + year;
+      }
+      return year;
+    }
 }
 
 Time time() :

http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/7829f79a/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java
----------------------------------------------------------------------
diff --git a/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java b/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java
new file mode 100644
index 0000000..0e13b2d
--- /dev/null
+++ b/dom/src/test/java/org/apache/james/mime4j/field/DateTimeFieldImplTest.java
@@ -0,0 +1,73 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.mime4j.field;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.TimeZone;
+
+import org.apache.james.mime4j.MimeException;
+import org.apache.james.mime4j.dom.field.DateTimeField;
+import org.apache.james.mime4j.stream.RawField;
+import org.apache.james.mime4j.stream.RawFieldParser;
+import org.apache.james.mime4j.util.ByteSequence;
+import org.apache.james.mime4j.util.ContentUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class DateTimeFieldImplTest {
+
+    private TimeZone timeZone;
+
+    @Before
+    public void setup() {
+        timeZone = TimeZone.getDefault();
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+    }
+    
+    @After
+    public void tearDown() {
+        TimeZone.setDefault(timeZone);
+    }
+    
+    @Test
+    public void parseShouldReturnYearWhen4Digits() throws Exception {
+        DateTimeField field = parse("Date: Sun, 13 May 1917 14:18:52Z");
+        assertEquals("Sun May 13 14:18:52 UTC 1917", field.getDate().toString());
+    }
+
+    @Test
+    public void parseShouldAddCenturyWhen2Digits() throws Exception {
+        DateTimeField field = parse("Date: Sat, 13 May 17 14:18:52Z");
+        assertEquals("Sat May 13 14:18:52 UTC 2017", field.getDate().toString());
+    }
+
+    @Test
+    public void dayIsDependentFromTheDateNotFromTheGivenDay() throws Exception {
+        DateTimeField field = parse("Date: Mon, 13 May 17 14:18:52Z");
+        assertEquals("Sat May 13 14:18:52 UTC 2017", field.getDate().toString());
+    }
+
+    private DateTimeField parse(final String s) throws MimeException {
+        ByteSequence raw = ContentUtil.encode(s);
+        RawField rawField = RawFieldParser.DEFAULT.parseField(raw);
+        return DateTimeFieldImpl.PARSER.parse(rawField, null);
+    }
+}


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


[3/3] james-mime4j git commit: JAMES-2045 Correct DateTimeTests

Posted by bt...@apache.org.
JAMES-2045 Correct DateTimeTests


Project: http://git-wip-us.apache.org/repos/asf/james-mime4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-mime4j/commit/5acd2cf3
Tree: http://git-wip-us.apache.org/repos/asf/james-mime4j/tree/5acd2cf3
Diff: http://git-wip-us.apache.org/repos/asf/james-mime4j/diff/5acd2cf3

Branch: refs/heads/master
Commit: 5acd2cf3c221b88e6e14cc4d18b2f4553d430f60
Parents: 149e301
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 09:02:30 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Jun 5 10:15:56 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mime4j/field/datetime/DateTimeTest.java  | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/5acd2cf3/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
----------------------------------------------------------------------
diff --git a/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java b/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
index 02510ba..685281b 100644
--- a/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
+++ b/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
@@ -44,12 +44,12 @@ public class DateTimeTest {
 
 
         ensureAllEqual(new String[]{
-                "Fri, 21 Nov 1997 09:55:06 -0600", // baseline
+                "Fri, 21 Nov 2097 09:55:06 -0600", // baseline
                 "Fri, 21 Nov 97 09:55:06 -0600",   // 2-digit year
-                "Fri, 21 Nov 097 09:55:06 -0600",  // 3-digit year
-                "Fri, 21 Nov 1997 10:55:06 -0500", // shift time zone
-                "Fri, 21 Nov 1997 19:25:06 +0330", // shift time zone
-                "21 Nov 1997 09:55:06 -0600"       // omit day of week
+                "Fri, 21 Nov 197 09:55:06 -0600",  // 3-digit year
+                "Fri, 21 Nov 2097 10:55:06 -0500", // shift time zone
+                "Fri, 21 Nov 2097 19:25:06 +0330", // shift time zone
+                "21 Nov 2097 09:55:06 -0600"       // omit day of week
         });
 
         ensureAllEqual(new String[]{


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


[2/3] james-mime4j git commit: JAMES-2045 Improve DateTimeTest readability with assertJ messages

Posted by bt...@apache.org.
JAMES-2045 Improve DateTimeTest readability with assertJ messages

It was impossible to know wich dates differed before


Project: http://git-wip-us.apache.org/repos/asf/james-mime4j/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-mime4j/commit/149e3010
Tree: http://git-wip-us.apache.org/repos/asf/james-mime4j/tree/149e3010
Diff: http://git-wip-us.apache.org/repos/asf/james-mime4j/diff/149e3010

Branch: refs/heads/master
Commit: 149e3010ade21239c2c4a2f9f28ddf7626017832
Parents: 7829f79
Author: benwa <bt...@linagora.com>
Authored: Mon Jun 5 09:01:39 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Jun 5 10:15:51 2017 +0700

----------------------------------------------------------------------
 dom/pom.xml                                              |  6 ++++++
 .../apache/james/mime4j/field/datetime/DateTimeTest.java | 11 +++++++----
 pom.xml                                                  |  6 ++++++
 3 files changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/149e3010/dom/pom.xml
----------------------------------------------------------------------
diff --git a/dom/pom.xml b/dom/pom.xml
index 1b8ee4b..3a549f4 100644
--- a/dom/pom.xml
+++ b/dom/pom.xml
@@ -46,8 +46,14 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.mockito</groupId>

http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/149e3010/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
----------------------------------------------------------------------
diff --git a/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java b/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
index 37dfe08..02510ba 100644
--- a/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
+++ b/dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.mime4j.field.datetime;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
 import org.apache.james.mime4j.field.datetime.parser.ParseException;
@@ -101,10 +103,11 @@ public class DateTimeTest {
 
     private void ensureAllEqual(String[] dateStrings) throws ParseException {
         for (int i = 0; i < dateStrings.length - 1; i++) {
-            Assert.assertEquals(
-                    new DateTimeParser(new StringReader(dateStrings[i])).parseAll().getDate().getTime(),
-                    new DateTimeParser(new StringReader(dateStrings[i + 1])).parseAll().getDate().getTime()
-            );
+            long date1 = new DateTimeParser(new StringReader(dateStrings[i])).parseAll().getDate().getTime();
+            long date2 = new DateTimeParser(new StringReader(dateStrings[i + 1])).parseAll().getDate().getTime();
+            assertThat(date1)
+                .as(dateStrings[i] + " == " + dateStrings[i + 1])
+                .isEqualTo(date2);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/james-mime4j/blob/149e3010/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 354e2ec..359bf04 100644
--- a/pom.xml
+++ b/pom.xml
@@ -128,6 +128,12 @@
                 <scope>test</scope>
             </dependency>
             <dependency>
+                <groupId>org.assertj</groupId>
+                <artifactId>assertj-core</artifactId>
+                <version>1.7.1</version>
+                <scope>test</scope>
+            </dependency>
+            <dependency>
                 <groupId>org.mockito</groupId>
                 <artifactId>mockito-core</artifactId>
                 <version>${mockito.version}</version>


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