~ubuntu-branches/ubuntu/utopic/apache-mime4j/utopic-proposed

« back to all changes in this revision

Viewing changes to dom/src/test/java/org/apache/james/mime4j/field/datetime/DateTimeTest.java

  • Committer: Package Import Robot
  • Author(s): David Paleino
  • Date: 2013-11-03 11:13:27 UTC
  • mfrom: (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20131103111327-09huep00ex05z113
Tags: 0.7.2-2
* Upload to unstable
* Fixed Vcs-* fields in debian/control
* Updated debian/watch
* Standards-Version bump to 3.9.5, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************
 
2
 * Licensed to the Apache Software Foundation (ASF) under one   *
 
3
 * or more contributor license agreements.  See the NOTICE file *
 
4
 * distributed with this work for additional information        *
 
5
 * regarding copyright ownership.  The ASF licenses this file   *
 
6
 * to you under the Apache License, Version 2.0 (the            *
 
7
 * "License"); you may not use this file except in compliance   *
 
8
 * with the License.  You may obtain a copy of the License at   *
 
9
 *                                                              *
 
10
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 
11
 *                                                              *
 
12
 * Unless required by applicable law or agreed to in writing,   *
 
13
 * software distributed under the License is distributed on an  *
 
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 
15
 * KIND, either express or implied.  See the License for the    *
 
16
 * specific language governing permissions and limitations      *
 
17
 * under the License.                                           *
 
18
 ****************************************************************/
 
19
 
 
20
package org.apache.james.mime4j.field.datetime;
 
21
 
 
22
import junit.framework.TestCase;
 
23
 
 
24
import org.apache.james.mime4j.MimeException;
 
25
import org.apache.james.mime4j.field.datetime.parser.DateTimeParser;
 
26
import org.apache.james.mime4j.field.datetime.parser.ParseException;
 
27
 
 
28
import java.io.StringReader;
 
29
 
 
30
public class DateTimeTest extends TestCase {
 
31
 
 
32
    public void testExceptionTree() {
 
33
        // make sure that our ParseException extends MimeException.
 
34
        assertTrue(MimeException.class.isAssignableFrom(ParseException.class));
 
35
    }
 
36
 
 
37
    public void testNormalDate() throws ParseException {
 
38
        new DateTimeParser(new StringReader("Fri, 21 Nov 1997 09:55:06 -0600")).parseAll();
 
39
        new DateTimeParser(new StringReader("21 Nov 97 09:55:06 GMT")).parseAll();
 
40
 
 
41
 
 
42
        ensureAllEqual(new String[] {
 
43
           "Fri, 21 Nov 1997 09:55:06 -0600", // baseline
 
44
           "Fri, 21 Nov 97 09:55:06 -0600",   // 2-digit year
 
45
           "Fri, 21 Nov 097 09:55:06 -0600",  // 3-digit year
 
46
           "Fri, 21 Nov 1997 10:55:06 -0500", // shift time zone
 
47
           "Fri, 21 Nov 1997 19:25:06 +0330", // shift time zone
 
48
           "21 Nov 1997 09:55:06 -0600"       // omit day of week
 
49
        });
 
50
 
 
51
        ensureAllEqual(new String[] {
 
52
            "Thu, 16 Sep 2019 14:37:22 +0000", // baseline
 
53
            "Thu, 16 Sep 19 14:37:22 +0000",   // 2-digit year
 
54
            "Thu, 16 Sep 119 14:37:22 +0000",  // 3-digit year
 
55
            "Thu, 16 Sep 2019 14:37:22 -0000", // minus-zero zone
 
56
            "Thu, 16 Sep 2019 14:37:22 GMT",   // alternate zone
 
57
            "Thu, 16 Sep 2019 14:37:22 UT"     // alternate zone
 
58
        });
 
59
 
 
60
        ensureAllEqual(new String[] {
 
61
            "Fri, 21 Nov 1997 12:00:00 GMT",
 
62
            "Fri, 21 Nov 1997 07:00:00 EST",
 
63
            "Fri, 21 Nov 1997 08:00:00 EDT",
 
64
            "Fri, 21 Nov 1997 06:00:00 CST",
 
65
            "Fri, 21 Nov 1997 07:00:00 CDT",
 
66
            "Fri, 21 Nov 1997 05:00:00 MST",
 
67
            "Fri, 21 Nov 1997 06:00:00 MDT",
 
68
            "Fri, 21 Nov 1997 04:00:00 PST",
 
69
            "Fri, 21 Nov 1997 05:00:00 PDT",
 
70
 
 
71
            // make sure military zones are ignored, per RFC2822 instructions
 
72
            "Fri, 21 Nov 1997 12:00:00 A",
 
73
            "Fri, 21 Nov 1997 12:00:00 B",
 
74
            "Fri, 21 Nov 1997 12:00:00 C",
 
75
            "Fri, 21 Nov 1997 12:00:00 D",
 
76
            "Fri, 21 Nov 1997 12:00:00 E",
 
77
            "Fri, 21 Nov 1997 12:00:00 F",
 
78
            "Fri, 21 Nov 1997 12:00:00 G",
 
79
            "Fri, 21 Nov 1997 12:00:00 H",
 
80
            "Fri, 21 Nov 1997 12:00:00 I",
 
81
            "Fri, 21 Nov 1997 12:00:00 K",
 
82
            "Fri, 21 Nov 1997 12:00:00 L",
 
83
            "Fri, 21 Nov 1997 12:00:00 M",
 
84
            "Fri, 21 Nov 1997 12:00:00 N",
 
85
            "Fri, 21 Nov 1997 12:00:00 O",
 
86
            "Fri, 21 Nov 1997 12:00:00 P",
 
87
            "Fri, 21 Nov 1997 12:00:00 Q",
 
88
            "Fri, 21 Nov 1997 12:00:00 R",
 
89
            "Fri, 21 Nov 1997 12:00:00 S",
 
90
            "Fri, 21 Nov 1997 12:00:00 T",
 
91
            "Fri, 21 Nov 1997 12:00:00 U",
 
92
            "Fri, 21 Nov 1997 12:00:00 V",
 
93
            "Fri, 21 Nov 1997 12:00:00 W",
 
94
            "Fri, 21 Nov 1997 12:00:00 X",
 
95
            "Fri, 21 Nov 1997 12:00:00 Y",
 
96
            "Fri, 21 Nov 1997 12:00:00 Z",
 
97
        });
 
98
    }
 
99
 
 
100
    private void ensureAllEqual(String[] dateStrings) throws ParseException {
 
101
        for (int i = 0; i < dateStrings.length - 1; i++) {
 
102
            assertEquals(
 
103
                    new DateTimeParser(new StringReader(dateStrings[i])).parseAll().getDate().getTime(),
 
104
                    new DateTimeParser(new StringReader(dateStrings[i + 1])).parseAll().getDate().getTime()
 
105
            );
 
106
        }
 
107
    }
 
108
 
 
109
}