Skip to content

Commit

Permalink
close ShrinkWrapClassLoader in test suite (try-with-resources)
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangHG committed Dec 4, 2024
1 parent 5527e1d commit 16728e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public void test() throws Exception {

JavaArchive archive = ShrinkWrap.create(JavaArchive.class).add(new CtClassAsset(ctClass));

ShrinkWrapClassLoader classLoader = new ShrinkWrapClassLoader(ClassLoaderUtils.getBootstrapClassLoader(), archive);

assertNotNull(classLoader.loadClass(CLASS_NAME));

classLoader.close();
try (ShrinkWrapClassLoader classLoader = new ShrinkWrapClassLoader(ClassLoaderUtils.getBootstrapClassLoader(), archive)) {
assertNotNull(classLoader.loadClass(CLASS_NAME));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,14 @@ public void testJavaArchiveFromClass() throws Throwable {
public void testMultipleUse() throws ClassNotFoundException, IOException {
JavaArchive archive = ShrinkWrapUtils.getJavaArchiveFromClass(Test.class);

ShrinkWrapClassLoader classLoader =
new ShrinkWrapClassLoader(ClassLoaderUtils.getBootstrapClassLoader(), archive);
Class<?> nestedClass = classLoader.loadClass(Test.class.getName());
try (ShrinkWrapClassLoader classLoader =
new ShrinkWrapClassLoader(ClassLoaderUtils.getBootstrapClassLoader(), archive)) {
Class<?> nestedClass = classLoader.loadClass(Test.class.getName());

JavaArchive nestedArchive = ShrinkWrapUtils.getJavaArchiveFromClass(nestedClass);
JavaArchive nestedArchive = ShrinkWrapUtils.getJavaArchiveFromClass(nestedClass);

assertNotNull(nestedArchive.get("/org/junit/Test.class"));
assertNotNull(nestedArchive.get("/org/junit/Ignore.class"));

classLoader.close();
assertNotNull(nestedArchive.get("/org/junit/Test.class"));
assertNotNull(nestedArchive.get("/org/junit/Ignore.class"));
}
}
}

0 comments on commit 16728e9

Please sign in to comment.