From 620a8be65bb786c77fc2016e9a53364f3d65260e Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Mon, 13 Nov 2017 11:25:16 +0100 Subject: [PATCH] Add missing unit test --- src/test/Readme.txt | 2 +- src/test/javassist/JvstTest.java | 12 +++++++++++- src/test/resources/Readme.txt | 12 ++++++++++++ src/test/resources/simple.jar | Bin 0 -> 631 bytes 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/simple.jar diff --git a/src/test/Readme.txt b/src/test/Readme.txt index 0a0df2c8..3218a9d2 100644 --- a/src/test/Readme.txt +++ b/src/test/Readme.txt @@ -10,7 +10,7 @@ Maven > mv ./target/javassist*-GA.jar ./javaassist.jar 2) Check that ./src/test/javassist/JvstTestRoot.PATH and .JAR_PATH point to the compiled jar file. - The default is "../". + The default is "../../". 3) Run Tests diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java index 436dc6de..bd68cf08 100644 --- a/src/test/javassist/JvstTest.java +++ b/src/test/javassist/JvstTest.java @@ -3,6 +3,7 @@ package javassist; import junit.framework.*; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.lang.reflect.Method; import javassist.bytecode.*; import javassist.expr.*; @@ -83,7 +84,16 @@ public class JvstTest extends JvstTestRoot { } public void testJarClassPath() throws Exception { - // TODO: Verify that classes can be loaded from a JarClassPath + String jarFileName = "./simple.jar"; + ClassLoader classLoader = getClass().getClassLoader(); + File jarFile = new File(classLoader.getResource(jarFileName).getFile()); + assertTrue(jarFile.exists()); + + ClassPool pool = ClassPool.getDefault(); + ClassPath cp = pool.appendClassPath(jarFile.getAbsolutePath()); + InputStream is = cp.openClassfile("com.test.Test"); + assertNotNull(is); + is.close(); } public void testSubtype() throws Exception { diff --git a/src/test/resources/Readme.txt b/src/test/resources/Readme.txt index 6ce81b50..77790dc1 100644 --- a/src/test/resources/Readme.txt +++ b/src/test/resources/Readme.txt @@ -2,3 +2,15 @@ This directory contains files used by the unit tests. empty.jar: An empty, but valid, jar file. + +simple.jar: +Contains a single Java class + +``` +package com.test; + +public class Test { + public Test() { + } +} +``` diff --git a/src/test/resources/simple.jar b/src/test/resources/simple.jar new file mode 100644 index 0000000000000000000000000000000000000000..e9455b92efbdee475ac9c3653d2eeab3cd5a7e01 GIT binary patch literal 631 zcmWIWW@Zs#;Nak3xE-16&42_r8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g1&9M^Bl+ZurId@U#=q21g)9xZwzz2ZVvL z$@#hZC8@aHXS4K0#mwX7mUEX>t(|eK6-7}k}luI6NK0iSuSC^;rkQGnx>rOAT@WM0Rp%P09 zUaXaM^Hx375MfntAl~MnT(hiDQCD-){|6m;>=*e#p&WDjhwnn5`wxSC$jBtZfEr1# z7yv~QDu9PND9Qr7QMDom94Lwqz!u1aYekAMWD`IEjO;K_03*ObAQMY)2Y9oxffO+V M;XWX}m=VMS0P;GsK>z>% literal 0 HcmV?d00001 -- 2.39.5