You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2020/04/28 05:49:44 UTC
[struts] branch WW-4043-moves-test-utils updated: WW-4043 Adds
additional function to provide encoding
This is an automated email from the ASF dual-hosted git repository.
lukaszlenart pushed a commit to branch WW-4043-moves-test-utils
in repository https://gitbox.apache.org/repos/asf/struts.git
The following commit(s) were added to refs/heads/WW-4043-moves-test-utils by this push:
new 1e14438 WW-4043 Adds additional function to provide encoding
1e14438 is described below
commit 1e1443871b4fc93f37cbf8347f980d3ee49b260c
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Tue Apr 28 07:49:06 2020 +0200
WW-4043 Adds additional function to provide encoding
---
.../main/java/org/apache/struts2/util/TestUtils.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java b/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java
index 131f009..2053813 100644
--- a/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java
+++ b/plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java
@@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils;
import org.junit.Assert;
import java.net.URL;
+import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,6 +32,7 @@ import java.util.regex.Pattern;
* Utility methods for test classes
*/
public class TestUtils {
+
/**
* A regex pattern for recognizing blocks of whitespace characters.
*/
@@ -83,9 +85,19 @@ public class TestUtils {
}
public static String readContent(URL url) throws Exception {
- if (url == null)
- throw new Exception("unable to verify a null URL");
+ return readContent(url, StandardCharsets.UTF_8);
+ }
+
+ public static String readContent(URL url, Charset encoding) throws Exception {
+ if (url == null) {
+ throw new IllegalArgumentException("Unable to verify a null URL");
+ }
- return IOUtils.toString(url.openStream(), StandardCharsets.UTF_8);
+ if (encoding == null) {
+ throw new IllegalArgumentException("Unable to verify the URL using a null Charset");
+ }
+
+ return IOUtils.toString(url.openStream(), encoding);
}
+
}