source: contrib/MailArchiver/sources/vendor/mime4j/custom/dom/src/test/java/org/apache/james/mime4j/field/mimeversion/MimeVersionParserTest.java @ 6785

Revision 6785, 3.0 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado codigo do MailArchiver?. Documentação na subpasta DOCS.

Line 
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
20package org.apache.james.mime4j.field.mimeversion;
21
22import java.io.StringReader;
23
24import junit.framework.TestCase;
25
26import org.apache.james.mime4j.field.mimeversion.parser.MimeVersionParser;
27import org.apache.james.mime4j.field.mimeversion.parser.ParseException;
28
29public class MimeVersionParserTest extends TestCase {
30
31    @Override
32    protected void setUp() throws Exception {
33        super.setUp();
34    }
35
36    @Override
37    protected void tearDown() throws Exception {
38        super.tearDown();
39    }
40
41    public void testPlainLine() throws Exception {
42        check("2.4", 2, 4);
43        check("25.344", 25, 344);
44        check("0.1", 0, 1);
45        check("123234234.0", 123234234, 0);
46    }
47   
48    public void testLineWithComments() throws Exception {
49        check("2(A comment).4", 2, 4);
50        check("2(.8).4", 2, 4);
51        check("(A comment)2.4", 2, 4);
52        check("2.4(A comment)", 2, 4);
53        check("2.(A comment)4", 2, 4);
54    }
55   
56    public void testLineWithNestedComments() throws Exception {
57        check("2(4.45 ( Another ()comment () blah (Wobble(mix)))Whatever).4", 2, 4);
58    }
59   
60    public void testEmptyLine() throws Exception {
61        try {
62            parse("(This is just a comment)");
63            fail("Expected exception to be thrown");
64        } catch (ParseException e) {
65            //expected
66        }
67    }
68   
69    private void check(String input, int expectedMajorVersion, int expectedMinorVersion) throws Exception {
70        MimeVersionParser parser = parse(input);
71        assertEquals("Major version number", expectedMajorVersion, parser.getMajorVersion());
72        assertEquals("Minor version number", expectedMinorVersion, parser.getMinorVersion());
73    }
74
75    private MimeVersionParser parse(String input) throws ParseException {
76        MimeVersionParser parser = new MimeVersionParser(new StringReader(input));
77        parser.parseAll();
78        return parser;
79    }
80}
Note: See TracBrowser for help on using the repository browser.