[testng] 07/160: Adding a test for ServiceLoader functionality
Eugene Zhukov
eugene-guest at moszumanska.debian.org
Tue Aug 18 10:22:14 UTC 2015
This is an automated email from the git hooks/post-receive script.
eugene-guest pushed a commit to annotated tag testng-6.9.5
in repository testng.
commit 85f4888e9c38b5ae3aad364a973deb86882f2a6e
Author: Krishnan Mahadevan <krishnan.mahadevan1978 at gmail.com>
Date: Thu May 21 08:29:57 2015 +0530
Adding a test for ServiceLoader functionality
* Added a unit test for service loader functionality
that basically relies on the current thread’s
contextual class loader to load the service loader
file and help TestNG load listeners via it.
---
src/test/java/test/serviceloader/ServiceLoaderTest.java | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src/test/java/test/serviceloader/ServiceLoaderTest.java b/src/test/java/test/serviceloader/ServiceLoaderTest.java
index adee343..902df69 100644
--- a/src/test/java/test/serviceloader/ServiceLoaderTest.java
+++ b/src/test/java/test/serviceloader/ServiceLoaderTest.java
@@ -22,4 +22,17 @@ public class ServiceLoaderTest extends SimpleBaseTest {
Assert.assertEquals(1, tng.getServiceLoaderListeners().size());
}
+
+ @Test
+ public void serviceLoaderWithNoClassLoader() {
+ //Here ServiceLoader is expected to rely on the current context class loader to load the service loader file
+ //Since serviceloader.jar doesn't seem to be visible to the current thread's contextual class loader
+ //resorting to pushing in a class loader into the current thread that can load the resource
+ URL url = getClass().getClassLoader().getResource("serviceloader.jar");
+ URLClassLoader ucl = URLClassLoader.newInstance(new URL[] { url });
+ Thread.currentThread().setContextClassLoader(ucl);
+ TestNG tng = create(ServiceLoaderSampleTest.class);
+ tng.run();
+ Assert.assertEquals(1, tng.getServiceLoaderListeners().size());
+ }
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git
More information about the pkg-java-commits
mailing list