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.util; |
---|
21 | |
---|
22 | import junit.framework.TestCase; |
---|
23 | |
---|
24 | public class MimeUtilTest extends TestCase { |
---|
25 | |
---|
26 | public void testFold() throws Exception { |
---|
27 | assertEquals("this is\r\n a test", MimeUtil.fold("this is a test", 68)); |
---|
28 | assertEquals("this is\r\n a test", MimeUtil.fold("this is a test", 69)); |
---|
29 | assertEquals("this\r\n is a test", MimeUtil.fold("this is a test", 70)); |
---|
30 | assertEquals("this \r\n is a test", MimeUtil.fold( |
---|
31 | "this is a test", 70)); |
---|
32 | } |
---|
33 | |
---|
34 | public void testFoldOverlyLongNonWhitespace() throws Exception { |
---|
35 | String ninety = "1234567890123456789012345678901234567890" |
---|
36 | + "12345678901234567890123456789012345678901234567890"; |
---|
37 | String input = String.format("testing 1 2 %s testing %s", ninety, |
---|
38 | ninety); |
---|
39 | |
---|
40 | String expected = String.format( |
---|
41 | "testing 1 2\r\n %s\r\n testing\r\n %s", ninety, ninety); |
---|
42 | |
---|
43 | assertEquals(expected, MimeUtil.fold(input, 0)); |
---|
44 | } |
---|
45 | |
---|
46 | public void testUnfold() throws Exception { |
---|
47 | assertEquals("", MimeUtil.unfold("")); |
---|
48 | assertEquals("x", MimeUtil.unfold("x")); |
---|
49 | assertEquals(" x ", MimeUtil.unfold(" x ")); |
---|
50 | |
---|
51 | assertEquals("", MimeUtil.unfold("\r")); |
---|
52 | assertEquals("", MimeUtil.unfold("\n")); |
---|
53 | assertEquals("", MimeUtil.unfold("\r\n")); |
---|
54 | |
---|
55 | assertEquals(" ", MimeUtil.unfold(" \n")); |
---|
56 | assertEquals(" ", MimeUtil.unfold("\n ")); |
---|
57 | assertEquals(" ", MimeUtil.unfold(" \r\n")); |
---|
58 | assertEquals(" ", MimeUtil.unfold("\r\n ")); |
---|
59 | |
---|
60 | assertEquals("this is a test", MimeUtil.unfold("this is\r\n a test")); |
---|
61 | assertEquals("this is a test", MimeUtil.unfold("this is\r\n a test")); |
---|
62 | assertEquals("this is a test", MimeUtil.unfold("this\r\n is a test")); |
---|
63 | assertEquals("this is a test", MimeUtil |
---|
64 | .unfold("this \r\n is a test")); |
---|
65 | |
---|
66 | assertEquals("this is a test", MimeUtil |
---|
67 | .unfold("this\r\n is\r\n a\r\n test")); |
---|
68 | } |
---|
69 | |
---|
70 | } |
---|