You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2013/03/19 14:44:37 UTC
svn commit: r1458278 -
/commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
Author: simonetripodi
Date: Tue Mar 19 13:44:37 2013
New Revision: 1458278
URL: http://svn.apache.org/r1458278
Log:
[FILEUPLOAD-232] initial checkin of QuotedPrintableDecoderTestCase class
Added:
commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java (with props)
Added: commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java?rev=1458278&view=auto
==============================================================================
--- commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java (added)
+++ commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java Tue Mar 19 13:44:37 2013
@@ -0,0 +1,71 @@
+/*
+ * 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.assertArrayEquals;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
+/**
+ * @since 1.3
+ */
+public final class QuotedPrintableDecoderTestCase {
+
+ private static final String US_ASCII_CHARSET = "US-ASCII";
+
+ @Test
+ public void basicEncodeDecode() throws Exception {
+ assertEncoded("= Hello there =\r\n", "=3D Hello there =3D=0D=0A");
+ }
+
+ @Test(expected = IOException.class)
+ public void invalidQuotedPrintableEncoding() throws Exception {
+ assertEncoded("abc123_-.*~!@#$%^&()+{}\"\\;:`,/[]", "YWJjMTIzXy0uKn4hQCMkJV4mKCkre31cIlxcOzpgLC9bXQ==");
+ }
+
+ @Test
+ public void unsafeDecode() throws Exception {
+ assertEncoded("=\r\n", "=3D=0D=0A");
+ }
+
+ /**
+ * This is NOT supported by Commons-Codec, see CODEC-121.
+ *
+ * @throws Exception
+ * @see <a href="https://issues.apache.org/jira/browse/CODEC-121">CODEC-121</a>
+ */
+ @Test
+ public void softLineBreakDecode() throws Exception {
+ assertEncoded("If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.",
+ "If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics is the most beautiful branch of philosophy.");
+ }
+
+ private static void assertEncoded(String clearText, String encoded) throws Exception {
+ byte[] expected = clearText.getBytes(US_ASCII_CHARSET);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream(encoded.length());
+ byte[] encodedData = encoded.getBytes(US_ASCII_CHARSET);
+ QuotedPrintableDecoder.decode(encodedData, out);
+ byte[] actual = out.toByteArray();
+
+ assertArrayEquals(expected, actual);
+ }
+
+}
Propchange: commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/proper/fileupload/trunk/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain