]> source.dussan.org Git - javassist.git/commitdiff
Add missing unit test 168/head
authorChristian Melchior <christian@ilios.dk>
Mon, 13 Nov 2017 10:25:16 +0000 (11:25 +0100)
committerChristian Melchior <christian@ilios.dk>
Mon, 13 Nov 2017 10:25:16 +0000 (11:25 +0100)
src/test/Readme.txt
src/test/javassist/JvstTest.java
src/test/resources/Readme.txt
src/test/resources/simple.jar [new file with mode: 0644]

index 0a0df2c8f16866c6b63472f62a85af3de8b01cbe..3218a9d20f262a4e3038a8dfaa8243e971403eaf 100644 (file)
@@ -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
 
index 436dc6deb8dc346df25a45797a7c3c0059ecfafe..bd68cf08345b3cfd25580812b6286bc61b3b8845 100644 (file)
@@ -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 {
index 6ce81b50c273a4998747802022eac47abcf78155..77790dc134cba9bc5c94f089cd94dd252fd74ac2 100644 (file)
@@ -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 (file)
index 0000000..e9455b9
Binary files /dev/null and b/src/test/resources/simple.jar differ