/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.fileupload.util.mime;

import static org.junit.Assert.assertEquals;

import org.apache.commons.fileupload.util.mime.MimeUtility;
import org.junit.Test;

/**
 * Use the online <a href="http://dogmamix.com/MimeHeadersDecoder/">MimeHeadersDecoder</a>
 * to validate expected values.
 *
 * @since 1.3
 */
public final class MimeUtilityTestCase {

    @Test
    public void noNeedToDecode() throws Exception {
        assertEncoded("abc", "abc");
    }

    @Test
    public void decodeUtf8QuotedPrintableEncoded() throws Exception {
        assertEncoded(" h! u !!!", "=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?=");
    }

    @Test
    public void decodeUtf8Base64Encoded() throws Exception {
        assertEncoded(" h! u !!!", "=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?=");
    }

    @Test
    public void decodeIso88591Base64Encoded() throws Exception {
        assertEncoded("If you can read this you understand the example.",
                      "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n");
    }

    private static void assertEncoded(String expected, String encoded) throws Exception {
        assertEquals(expected, MimeUtility.decodeText(encoded));
    }

}

@@ -892,16 +892,62 @@
 quals;%0A%0A
+import java.io.UnsupportedEncodingException;%0A%0A
 import o
@@ -2098,10 +2098,184 @@
 %0A    %7D%0A%0A
+    @Test(expected=UnsupportedEncodingException.class)%0A    public void decodeInvalidEncoding() throws Exception %7B%0A        MimeUtility.decodeText(%22=?invalid?B?xyz-?=%22);%0A    %7D%0A
 %7D%0A

Add test for unsupported encoding