aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/javassist/JvstTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/javassist/JvstTest.java')
-rw-r--r--src/test/javassist/JvstTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/javassist/JvstTest.java b/src/test/javassist/JvstTest.java
index d28c0654..ff58106a 100644
--- a/src/test/javassist/JvstTest.java
+++ b/src/test/javassist/JvstTest.java
@@ -1,7 +1,9 @@
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.*;
@@ -64,6 +66,36 @@ public class JvstTest extends JvstTestRoot {
assertTrue("[class path: ]".equals(pool.toString()));
}
+ public void testReleaseJarClassPathFileHandle() throws Exception {
+ String jarFileName = "./empty.jar";
+ ClassLoader classLoader = getClass().getClassLoader();
+ File jarFile = new File(classLoader.getResource(jarFileName).getFile());
+ assertTrue(jarFile.exists());
+
+ // Prepare class pool and force it to open the Jar file
+ ClassPool pool = ClassPool.getDefault();
+ ClassPath cp = pool.appendClassPath(jarFile.getAbsolutePath());
+ assertNull(cp.openClassfile("nothere.Dummy"));
+
+ // Assert that it is possible to delete the jar file.
+ // On Windows deleting an open file will fail, while on on Mac/Linux this is always possible.
+ // This check will thus only fail on Windos if the file is still open.
+ assertTrue(jarFile.delete());
+ }
+
+ public void testJarClassPath() throws Exception {
+ 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 {
CtClass cc = sloader.get("test1.Subtype");
assertTrue(cc.subtypeOf(cc));