source: contrib/MailArchiver/sources/vendor/mime4j/custom/dom/src/test/java/org/apache/james/mime4j/field/structured/StructuredFieldParserTest.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.structured;
21
22import java.io.StringReader;
23
24import junit.framework.TestCase;
25
26import org.apache.james.mime4j.field.structured.parser.StructuredFieldParser;
27
28public class StructuredFieldParserTest extends TestCase {
29
30    @Override
31    protected void setUp() throws Exception {
32        super.setUp();
33    }
34
35    @Override
36    protected void tearDown() throws Exception {
37        super.tearDown();
38    }
39
40    public void testSimpleField() throws Exception {
41        final String string = "Field Value";
42        assertEquals(string, parse(string));
43    }
44   
45    public void testTrim() throws Exception {
46        final String string = "Field Value";
47        assertEquals(string, parse("    \t\r\n" + string + "  \t\r\n  "));
48    }
49   
50    public void testFolding() throws Exception {
51        assertEquals("Field Value", parse("Field \t\r\n  Value"));
52    }
53   
54    public void testQuotedString() throws Exception {
55        assertEquals("Field    Value", parse("\"Field    Value\""));
56        assertEquals("Field\t\r\nValue", parse("\"Field\t\r\nValue\""));
57        assertEquals("Field\t\r\nValue", parse("\"Field\t\r\n       \t       Value\""));
58    }
59   
60    public void testComments() throws Exception {
61        assertEquals("Field", parse("Fi(This is a comment)eld"));
62        assertEquals("Field Value", parse("Fi(This is a comment)eld (A (very (nested) )comment)Value"));
63    }
64   
65    public void testQuotedInComments() throws Exception {
66        assertEquals("Fi(This is a comment)eld", parse("\"Fi(This is a comment)eld\""));
67        assertEquals("Field Value", parse("Fi(This is a comment)eld (A (very (nested) )comment)Value"));
68    }
69   
70    private String parse(String in) throws Exception {
71        StructuredFieldParser parser = new StructuredFieldParser(new StringReader(in));
72        parser.setFoldingPreserved(true);
73        return parser.parse();
74    }
75}
Note: See TracBrowser for help on using the repository browser.