This is an automated email from the ASF dual-hosted git repository.

jochen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git


The following commit(s) were added to refs/heads/master by this push:
     new 1b10014  FILEUPLOAD-321 - Use charset constant int the test V2
     new 5d3e1d8  Merge pull request #72 from 
arturobernalg/feature/FILEUPLOAD-321
1b10014 is described below

commit 1b10014dddf12527f8dbad24169e4f6a9434e8c5
Author: Arturo Bernal <arturobern...@gmail.com>
AuthorDate: Sun Apr 25 15:29:19 2021 +0200

    FILEUPLOAD-321 - Use charset constant int the test V2
---
 .../commons/fileupload2/ProgressListenerTest.java  |  7 +++---
 .../org/apache/commons/fileupload2/SizesTest.java  | 25 +++++++++++-----------
 .../apache/commons/fileupload2/StreamingTest.java  |  7 +++---
 .../java/org/apache/commons/fileupload2/Util.java  |  3 ++-
 .../fileupload2/servlet/ServletFileUploadTest.java |  9 ++++----
 .../util/mime/QuotedPrintableDecoderTestCase.java  |  7 +++---
 6 files changed, 32 insertions(+), 26 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/fileupload2/ProgressListenerTest.java 
b/src/test/java/org/apache/commons/fileupload2/ProgressListenerTest.java
index 70c35c4..02809a5 100644
--- a/src/test/java/org/apache/commons/fileupload2/ProgressListenerTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/ProgressListenerTest.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 
 import org.apache.commons.fileupload2.servlet.ServletFileUpload;
 import org.junit.jupiter.api.Test;
@@ -77,13 +78,13 @@ public class ProgressListenerTest {
             final String header = "-----1234\r\n"
                 + "Content-Disposition: form-data; name=\"field" + (i+1) + 
"\"\r\n"
                 + "\r\n";
-            baos.write(header.getBytes("US-ASCII"));
+            baos.write(header.getBytes(StandardCharsets.US_ASCII));
             for (int j = 0;  j < 16384+i;  j++) {
                 baos.write((byte) j);
             }
-            baos.write("\r\n".getBytes("US-ASCII"));
+            baos.write("\r\n".getBytes(StandardCharsets.US_ASCII));
         }
-        baos.write("-----1234--\r\n".getBytes("US-ASCII"));
+        baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII));
         final byte[] contents = baos.toByteArray();
 
         MockHttpServletRequest request = new MockHttpServletRequest(contents, 
Constants.CONTENT_TYPE);
diff --git a/src/test/java/org/apache/commons/fileupload2/SizesTest.java 
b/src/test/java/org/apache/commons/fileupload2/SizesTest.java
index 80998a1..a254f34 100644
--- a/src/test/java/org/apache/commons/fileupload2/SizesTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/SizesTest.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.fail;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Iterator;
 import java.util.List;
 
@@ -58,13 +59,13 @@ public class SizesTest {
             final String header = "-----1234\r\n"
                 + "Content-Disposition: form-data; name=\"field" + (num++) + 
"\"\r\n"
                 + "\r\n";
-            baos.write(header.getBytes("US-ASCII"));
+            baos.write(header.getBytes(StandardCharsets.US_ASCII));
             for (int j = 0;  j < i;  j++) {
                 baos.write((byte) j);
             }
-            baos.write("\r\n".getBytes("US-ASCII"));
+            baos.write("\r\n".getBytes(StandardCharsets.US_ASCII));
         }
-        baos.write("-----1234--\r\n".getBytes("US-ASCII"));
+        baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII));
 
         final List<FileItem> fileItems =
                 Util.parseUpload(new ServletFileUpload(new 
DiskFileItemFactory()), baos.toByteArray());
@@ -103,7 +104,7 @@ public class SizesTest {
         ServletFileUpload upload = new ServletFileUpload(new 
DiskFileItemFactory());
         upload.setFileSizeMax(-1);
         HttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
+                request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         List<FileItem> fileItems = upload.parseRequest(req);
         assertEquals(1, fileItems.size());
         FileItem item = fileItems.get(0);
@@ -111,7 +112,7 @@ public class SizesTest {
 
         upload = new ServletFileUpload(new DiskFileItemFactory());
         upload.setFileSizeMax(40);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), 
Constants.CONTENT_TYPE);
+        req = new 
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         fileItems = upload.parseRequest(req);
         assertEquals(1, fileItems.size());
         item = fileItems.get(0);
@@ -119,7 +120,7 @@ public class SizesTest {
 
         upload = new ServletFileUpload(new DiskFileItemFactory());
         upload.setFileSizeMax(30);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), 
Constants.CONTENT_TYPE);
+        req = new 
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         try {
             upload.parseRequest(req);
             fail("Expected exception.");
@@ -146,7 +147,7 @@ public class SizesTest {
         ServletFileUpload upload = new ServletFileUpload(new 
DiskFileItemFactory());
         upload.setFileSizeMax(-1);
         HttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
+                request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         List<FileItem> fileItems = upload.parseRequest(req);
         assertEquals(1, fileItems.size());
         FileItem item = fileItems.get(0);
@@ -154,7 +155,7 @@ public class SizesTest {
 
         upload = new ServletFileUpload(new DiskFileItemFactory());
         upload.setFileSizeMax(40);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), 
Constants.CONTENT_TYPE);
+        req = new 
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         fileItems = upload.parseRequest(req);
         assertEquals(1, fileItems.size());
         item = fileItems.get(0);
@@ -163,7 +164,7 @@ public class SizesTest {
         // provided Content-Length is larger than the FileSizeMax -> handled 
by ctor
         upload = new ServletFileUpload(new DiskFileItemFactory());
         upload.setFileSizeMax(5);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), 
Constants.CONTENT_TYPE);
+        req = new 
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         try {
             upload.parseRequest(req);
             fail("Expected exception.");
@@ -174,7 +175,7 @@ public class SizesTest {
         // provided Content-Length is wrong, actual content is larger -> 
handled by LimitedInputStream
         upload = new ServletFileUpload(new DiskFileItemFactory());
         upload.setFileSizeMax(15);
-        req = new MockHttpServletRequest(request.getBytes("US-ASCII"), 
Constants.CONTENT_TYPE);
+        req = new 
MockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         try {
             upload.parseRequest(req);
             fail("Expected exception.");
@@ -209,7 +210,7 @@ public class SizesTest {
         upload.setSizeMax(200);
 
         final MockHttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
+                request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         try {
             upload.parseRequest(req);
             fail("Expected exception.");
@@ -246,7 +247,7 @@ public class SizesTest {
         // otherwise the buffer would be immediately filled
 
         final MockHttpServletRequest req = new MockHttpServletRequest(
-                request.getBytes("US-ASCII"), Constants.CONTENT_TYPE);
+                request.getBytes(StandardCharsets.US_ASCII), 
Constants.CONTENT_TYPE);
         req.setContentLength(-1);
         req.setReadLimit(10);
 
diff --git a/src/test/java/org/apache/commons/fileupload2/StreamingTest.java 
b/src/test/java/org/apache/commons/fileupload2/StreamingTest.java
index 93934e4..f2881ec 100644
--- a/src/test/java/org/apache/commons/fileupload2/StreamingTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/StreamingTest.java
@@ -26,6 +26,7 @@ import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
 import java.util.Iterator;
 import java.util.List;
 import javax.servlet.http.HttpServletRequest;
@@ -198,7 +199,7 @@ public class StreamingTest {
 
     private byte[] newShortRequest() throws IOException {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final OutputStreamWriter osw = new OutputStreamWriter(baos, 
"US-ASCII");
+        final OutputStreamWriter osw = new OutputStreamWriter(baos, 
StandardCharsets.US_ASCII);
         osw.write(getHeader("field"));
         osw.write("123");
         osw.write("\r\n");
@@ -209,7 +210,7 @@ public class StreamingTest {
 
     private byte[] newRequest() throws IOException {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        final OutputStreamWriter osw = new OutputStreamWriter(baos, 
"US-ASCII");
+        final OutputStreamWriter osw = new OutputStreamWriter(baos, 
StandardCharsets.US_ASCII);
         int add = 16;
         int num = 0;
         for (int i = 0;  i < 16384;  i += add) {
@@ -254,7 +255,7 @@ public class StreamingTest {
             "\r\n" +
             "value2\r\n" +
             "-----1234--\r\n";
-        final byte[] reqBytes = request.getBytes("US-ASCII");
+        final byte[] reqBytes = request.getBytes(StandardCharsets.US_ASCII);
 
         final FileItemIterator fileItemIter = parseUpload(reqBytes.length, new 
ByteArrayInputStream(reqBytes));
         final FileItemStream fileItemStream = fileItemIter.next();
diff --git a/src/test/java/org/apache/commons/fileupload2/Util.java 
b/src/test/java/org/apache/commons/fileupload2/Util.java
index b644ce0..95bc5b8 100644
--- a/src/test/java/org/apache/commons/fileupload2/Util.java
+++ b/src/test/java/org/apache/commons/fileupload2/Util.java
@@ -17,6 +17,7 @@
 package org.apache.commons.fileupload2;
 
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.List;
 
@@ -45,7 +46,7 @@ public class Util {
 
     public static List<FileItem> parseUpload(final FileUpload upload, final 
String content)
         throws UnsupportedEncodingException, FileUploadException {
-        final byte[] bytes = content.getBytes("US-ASCII");
+        final byte[] bytes = content.getBytes(StandardCharsets.US_ASCII);
         return parseUpload(upload, bytes, Constants.CONTENT_TYPE);
     }
 
diff --git 
a/src/test/java/org/apache/commons/fileupload2/servlet/ServletFileUploadTest.java
 
b/src/test/java/org/apache/commons/fileupload2/servlet/ServletFileUploadTest.java
index 7533604..ce3675d 100644
--- 
a/src/test/java/org/apache/commons/fileupload2/servlet/ServletFileUploadTest.java
+++ 
b/src/test/java/org/apache/commons/fileupload2/servlet/ServletFileUploadTest.java
@@ -19,6 +19,7 @@ package org.apache.commons.fileupload2.servlet;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 
@@ -64,7 +65,7 @@ public class ServletFileUploadTest {
                       "\r\n" +
                       "value2\r\n" +
                       "-----1234--\r\n";
-        final byte[] bytes = text.getBytes("US-ASCII");
+        final byte[] bytes = text.getBytes(StandardCharsets.US_ASCII);
         final HttpServletRequest request = new MockHttpServletRequest(bytes, 
Constants.CONTENT_TYPE);
 
         final ServletFileUpload upload = new ServletFileUpload(new 
DiskFileItemFactory());
@@ -87,11 +88,11 @@ public class ServletFileUploadTest {
         final String text = "-----1234\r\n" +
                 "Content-Disposition: form-data; name=\"utf8Html\"\r\n" +
                 "\r\n" +
-                "Th�s �s the co�te�t of the f�le\n" +
+                "Thís ís the coñteñt of the fíle\n" +
                 "\r\n" +
                 "-----1234--\r\n";
 
-        final byte[] bytes = text.getBytes("UTF-8");
+        final byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
         final HttpServletRequest request = new MockHttpServletRequest(bytes, 
Constants.CONTENT_TYPE);
 
         final DiskFileItemFactory fileItemFactory = new DiskFileItemFactory();
@@ -99,6 +100,6 @@ public class ServletFileUploadTest {
         final ServletFileUpload upload = new 
ServletFileUpload(fileItemFactory);
         final List<FileItem> fileItems = upload.parseRequest(request);
         final FileItem fileItem = fileItems.get(0);
-        assertTrue(fileItem.getString().contains("co�te�t"), 
fileItem.getString());
+        assertTrue(fileItem.getString().contains("coñteñt"), 
fileItem.getString());
     }
 }
diff --git 
a/src/test/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoderTestCase.java
 
b/src/test/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoderTestCase.java
index f72d03f..c17a03c 100644
--- 
a/src/test/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoderTestCase.java
+++ 
b/src/test/java/org/apache/commons/fileupload2/util/mime/QuotedPrintableDecoderTestCase.java
@@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 
 import org.junit.jupiter.api.Test;
 
@@ -99,10 +100,10 @@ public final class QuotedPrintableDecoderTestCase {
     }
 
     private static void assertEncoded(final String clearText, final String 
encoded) throws Exception {
-        final byte[] expected = clearText.getBytes(US_ASCII_CHARSET);
+        final byte[] expected = clearText.getBytes(StandardCharsets.US_ASCII);
 
         final ByteArrayOutputStream out = new 
ByteArrayOutputStream(encoded.length());
-        final byte[] encodedData = encoded.getBytes(US_ASCII_CHARSET);
+        final byte[] encodedData = encoded.getBytes(StandardCharsets.US_ASCII);
         QuotedPrintableDecoder.decode(encodedData, out);
         final byte[] actual = out.toByteArray();
 
@@ -111,7 +112,7 @@ public final class QuotedPrintableDecoderTestCase {
 
     private static void assertIOException(final String messageText, final 
String encoded) throws UnsupportedEncodingException {
         final ByteArrayOutputStream out = new 
ByteArrayOutputStream(encoded.length());
-        final byte[] encodedData = encoded.getBytes(US_ASCII_CHARSET);
+        final byte[] encodedData = encoded.getBytes(StandardCharsets.US_ASCII);
         try {
             QuotedPrintableDecoder.decode(encodedData, out);
             fail("Expected IOException");

Reply via email to