This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git
commit 06a7699ea7e16558309470a08348b669cf8e7dc0 Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Sat Apr 12 08:47:21 2025 -0400 Simplify test --- pom.xml | 6 +++++ .../commons/jxpath/util/ClassLoaderUtilTest.java | 26 +++++----------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 077110b..baeb1fe 100644 --- a/pom.xml +++ b/pom.xml @@ -231,6 +231,12 @@ <version>3.17.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.19.0</version> + <scope>test</scope> + </dependency> </dependencies> <reporting> <plugins> diff --git a/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java b/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java index 170be7d..6f70b18 100644 --- a/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java +++ b/src/test/java/org/apache/commons/jxpath/util/ClassLoaderUtilTest.java @@ -21,13 +21,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.net.URL; +import org.apache.commons.io.IOUtils; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; import org.apache.commons.lang3.ArrayUtils; @@ -63,27 +62,12 @@ public class ClassLoaderUtilTest { if (TEST_CASE_CLASS_NAME.equals(name)) { if (testCaseClass == null) { final URL classUrl = getParent().getResource("org/apache/commons/jxpath/util/ClassLoaderUtilTest.class"); - final ByteArrayOutputStream out = new ByteArrayOutputStream(); - InputStream in = null; + byte[] clazzBytes; try { - in = classUrl.openStream(); - final byte[] buffer = new byte[2048]; - for (int read = in.read(buffer); read > -1; read = in.read(buffer)) { - out.write(buffer, 0, read); - } - } catch (final IOException e) { - throw new ClassNotFoundException("Could not read class from resource " + classUrl + ".", e); - } finally { - try { - in.close(); - } catch (final Exception e) { - } - try { - out.close(); - } catch (final Exception e) { - } + clazzBytes = IOUtils.toByteArray(classUrl); + } catch (IOException e) { + throw new ClassNotFoundException(classUrl.toString(), e); } - final byte[] clazzBytes = out.toByteArray(); this.testCaseClass = this.defineClass(TEST_CASE_CLASS_NAME, clazzBytes, 0, clazzBytes.length); } return this.testCaseClass;