0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0N/A *
292N/A * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
0N/A *
0N/A * The contents of this file are subject to the terms of either the GNU
0N/A * General Public License Version 2 only ("GPL") or the Common Development
0N/A * and Distribution License("CDDL") (collectively, the "License"). You
292N/A * may not use this file except in compliance with the License. You can
292N/A * obtain a copy of the License at
292N/A * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
292N/A * or packager/legal/LICENSE.txt. See the License for the specific
0N/A * language governing permissions and limitations under the License.
0N/A *
0N/A * When distributing the software, include this License Header Notice in each
292N/A * file and include the License file at packager/legal/LICENSE.txt.
292N/A *
292N/A * GPL Classpath Exception:
292N/A * Oracle designates this particular file as subject to the "Classpath"
292N/A * exception as provided by Oracle in the GPL Version 2 section of the License
292N/A * file that accompanied this code.
292N/A *
292N/A * Modifications:
292N/A * If applicable, add the following below the License Header, with the fields
292N/A * enclosed by brackets [] replaced by your own identifying information:
292N/A * "Portions Copyright [year] [name of copyright owner]"
0N/A *
0N/A * Contributor(s):
0N/A * If you wish your version of this file to be governed by only the CDDL or
0N/A * only the GPL Version 2, indicate your decision by adding "[Contributor]
0N/A * elects to include this software in this distribution under the [CDDL or GPL
0N/A * Version 2] license." If you don't indicate a single choice of license, a
0N/A * recipient has the option to distribute your version of this file under
0N/A * either the CDDL, the GPL Version 2 or to extend the choice of license to
0N/A * its licensees as provided above. However, if you add GPL Version 2 code
0N/A * and therefore, elected the GPL Version 2 license, then the option applies
0N/A * only if the new code is made subject to such option by the copyright
0N/A * holder.
0N/A */
0N/A
235N/Apackage javax.mail.internet;
0N/A
0N/Aimport java.io.*;
235N/Aimport java.util.*;
0N/Aimport javax.mail.internet.MimeUtility;
0N/A
235N/Aimport org.junit.Test;
235N/Aimport org.junit.Assert;
235N/Aimport org.junit.runner.RunWith;
235N/Aimport org.junit.runners.Parameterized;
235N/Aimport org.junit.runners.Parameterized.Parameters;
235N/A
0N/A/**
0N/A * Test header folding.
0N/A *
0N/A * @author Bill Shannon
0N/A */
0N/A
235N/A@RunWith(Parameterized.class)
235N/Apublic class FoldTest {
235N/A private String direction;
235N/A private String orig;
235N/A private String expect;
235N/A
787N/A private static List<Object[]> testData;
0N/A
235N/A public FoldTest(String direction, String orig, String expect) {
235N/A this.direction = direction;
235N/A this.orig = orig;
235N/A this.expect = expect;
235N/A }
0N/A
235N/A @Parameters
787N/A public static Collection<Object[]> data() throws IOException {
787N/A testData = new ArrayList<Object[]>();
235N/A parse(new BufferedReader(new InputStreamReader(
235N/A FoldTest.class.getResourceAsStream("folddata"))));
235N/A return testData;
0N/A }
0N/A
0N/A /**
0N/A * Read the data from the test file. Format is multiple of any of
0N/A * the following:
0N/A *
0N/A * FOLD\nString$\nEXPECT\nString$\n
0N/A * UNFOLD\nString$\nEXPECT\nString$\n
0N/A * BOTH\nString$\n
0N/A */
235N/A private static void parse(BufferedReader in) throws IOException {
0N/A String line;
0N/A while ((line = in.readLine()) != null) {
292N/A if (line.startsWith("#") || line.length() == 0)
0N/A continue;
0N/A String orig = readString(in);
0N/A if (line.equals("BOTH")) {
235N/A testData.add(new Object[] { line, orig, null });
0N/A } else {
0N/A String e = in.readLine();
0N/A if (!e.equals("EXPECT"))
235N/A throw new IOException("TEST DATA FORMAT ERROR");
0N/A String expect = readString(in);
235N/A testData.add(new Object[] { line, orig, expect });
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Read a string that ends with '$', preserving all characters,
0N/A * especially including CR and LF.
0N/A */
235N/A private static String readString(BufferedReader in) throws IOException {
0N/A StringBuffer sb = new StringBuffer();
0N/A int c;
0N/A while ((c = in.read()) != '$')
0N/A sb.append((char)c);
0N/A in.readLine(); // throw away rest of line
0N/A return sb.toString();
0N/A }
0N/A
235N/A @Test
235N/A public void testFold() {
235N/A if (direction.equals("BOTH")) {
235N/A String fs = MimeUtility.fold(0, orig);
235N/A String us = MimeUtility.unfold(fs);
235N/A Assert.assertEquals(orig, us);
235N/A } else if (direction.equals("FOLD")) {
235N/A Assert.assertEquals("Fold", expect, MimeUtility.fold(0, orig));
235N/A } else if (direction.equals("UNFOLD")) {
235N/A Assert.assertEquals("Unfold", expect, MimeUtility.unfold(orig));
235N/A } else {
235N/A Assert.fail("Unknown direction: " + direction);
0N/A }
0N/A }
0N/A}