Skip to content

Commit

Permalink
WW-4043 Adds additional function to provide encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Apr 28, 2020
1 parent 592c942 commit 1e14438
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions plugins/junit/src/main/java/org/apache/struts2/util/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -31,6 +32,7 @@
* Utility methods for test classes
*/
public class TestUtils {

/**
* A regex pattern for recognizing blocks of whitespace characters.
*/
Expand Down Expand Up @@ -83,9 +85,19 @@ public static void assertEquals(URL source, String text) throws Exception {
}

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);
}

}

0 comments on commit 1e14438

Please sign in to comment.