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 7be9057 FILEUPLOAD-320 - Use charset constant int the test V1 new d2dbb56 Merge pull request #73 from arturobernalg/feature/FILEUPLOAD-320 7be9057 is described below commit 7be9057fd5939923923417c66c7195cb80976d95 Author: Arturo Bernal <arturobern...@gmail.com> AuthorDate: Sun Apr 25 15:28:15 2021 +0200 FILEUPLOAD-320 - Use charset constant int the test V1 --- .../java/org/apache/commons/fileupload2/DiskFileUploadTest.java | 3 ++- src/test/java/org/apache/commons/fileupload2/FileUploadTest.java | 3 ++- .../commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java | 9 +++++---- .../commons/fileupload2/portlet/PortletFileUploadTest.java | 3 ++- .../commons/fileupload2/util/mime/Base64DecoderTestCase.java | 9 +++++---- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java b/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java index a4ba6ca..19c753b 100644 --- a/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java +++ b/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java @@ -19,6 +19,7 @@ package org.apache.commons.fileupload2; import static org.junit.jupiter.api.Assertions.*; import java.io.File; +import java.nio.charset.StandardCharsets; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -84,7 +85,7 @@ public class DiskFileUploadTest { "This is the content of the file\n" + "\r\n" + "-----1234--\r\n"; - final byte[] contentBytes = content.getBytes("US-ASCII"); + final byte[] contentBytes = content.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new MockHttpServletRequest(contentBytes, Constants.CONTENT_TYPE); final List<FileItem> items = myUpload.parseRequest(request); assertNotNull(items); diff --git a/src/test/java/org/apache/commons/fileupload2/FileUploadTest.java b/src/test/java/org/apache/commons/fileupload2/FileUploadTest.java index 65b583a..eef8b39 100644 --- a/src/test/java/org/apache/commons/fileupload2/FileUploadTest.java +++ b/src/test/java/org/apache/commons/fileupload2/FileUploadTest.java @@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.stream.Stream; @@ -220,7 +221,7 @@ public class FileUploadTest { "...contents of file2.gif...\r\n" + "--BbC04y--\r\n" + "--AaB03x--"; - final List<FileItem> fileItems = Util.parseUpload(upload, request.getBytes("US-ASCII"), contentType); + final List<FileItem> fileItems = Util.parseUpload(upload, request.getBytes(StandardCharsets.US_ASCII), contentType); assertEquals(3, fileItems.size()); final FileItem item0 = fileItems.get(0); assertEquals("field1", item0.getFieldName()); diff --git a/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java index e1b52a7..066652c 100644 --- a/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java +++ b/src/test/java/org/apache/commons/fileupload2/jaksrvlt/JakSrvltFileUploadTest.java @@ -19,6 +19,7 @@ package org.apache.commons.fileupload2.jaksrvlt; 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; @@ -63,7 +64,7 @@ public class JakSrvltFileUploadTest { "\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 MockJakSrvltHttpRequest(bytes, Constants.CONTENT_TYPE); final JakSrvltFileUpload upload = new JakSrvltFileUpload(new DiskFileItemFactory()); @@ -86,11 +87,11 @@ public class JakSrvltFileUploadTest { 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 MockJakSrvltHttpRequest(bytes, Constants.CONTENT_TYPE); final DiskFileItemFactory fileItemFactory = new DiskFileItemFactory(); @@ -98,6 +99,6 @@ public class JakSrvltFileUploadTest { final JakSrvltFileUpload upload = new JakSrvltFileUpload(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/portlet/PortletFileUploadTest.java b/src/test/java/org/apache/commons/fileupload2/portlet/PortletFileUploadTest.java index f443ab0..a4db94c 100644 --- a/src/test/java/org/apache/commons/fileupload2/portlet/PortletFileUploadTest.java +++ b/src/test/java/org/apache/commons/fileupload2/portlet/PortletFileUploadTest.java @@ -19,6 +19,7 @@ package org.apache.commons.fileupload2.portlet; 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; @@ -68,7 +69,7 @@ public class PortletFileUploadTest { "\r\n" + "value2\r\n" + "-----1234--\r\n"; - final byte[] bytes = text.getBytes("US-ASCII"); + final byte[] bytes = text.getBytes(StandardCharsets.US_ASCII); final ActionRequest request = new MockPortletActionRequest(bytes, Constants.CONTENT_TYPE); final Map<String, List<FileItem>> mappedParameters = upload.parseParameterMap(request); diff --git a/src/test/java/org/apache/commons/fileupload2/util/mime/Base64DecoderTestCase.java b/src/test/java/org/apache/commons/fileupload2/util/mime/Base64DecoderTestCase.java index a465dbb..81908c6 100644 --- a/src/test/java/org/apache/commons/fileupload2/util/mime/Base64DecoderTestCase.java +++ b/src/test/java/org/apache/commons/fileupload2/util/mime/Base64DecoderTestCase.java @@ -24,6 +24,7 @@ import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; @@ -134,15 +135,15 @@ public final class Base64DecoderTestCase { // The non-ASCII characters should just be ignored @Test public void nonASCIIcharacter() throws Exception { - assertEncoded("f","Zg=�="); // A-grave + assertEncoded("f","Zg=À="); // A-grave assertEncoded("f","Zg=\u0100="); } 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); Base64Decoder.decode(encodedData, out); final byte[] actual = out.toByteArray(); @@ -151,7 +152,7 @@ public final class Base64DecoderTestCase { 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 { Base64Decoder.decode(encodedData, out); fail("Expected IOException");