use of io.vertx.test.spi.SomeFactory in project vert.x by eclipse.
the class ServiceHelperTest method loadFactoriesFromTCCL.
@Test
public void loadFactoriesFromTCCL() throws Exception {
ClassLoader custom = new URLClassLoader(new URL[] { new File("target/externals").toURI().toURL() });
// Try without the TCCL classloader.
Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class);
assertThat(factories).isNotNull().hasSize(0);
// Try with the TCCL classloader
final ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(custom);
factories = ServiceHelper.loadFactories(SomeFactory.class);
assertThat(factories).isNotNull().hasSize(1);
assertThat(factories.iterator().next().classloader()).isEqualTo(custom);
} finally {
Thread.currentThread().setContextClassLoader(originalTCCL);
}
}
use of io.vertx.test.spi.SomeFactory in project vert.x by eclipse.
the class ServiceHelperTest method loadFactoriesWithClassloader.
@Test
public void loadFactoriesWithClassloader() throws Exception {
ClassLoader custom = new URLClassLoader(new URL[] { new File("target/externals").toURI().toURL() });
// Try without the custom classloader.
Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class);
assertThat(factories).isNotNull().hasSize(0);
// Try with the custom classloader
factories = ServiceHelper.loadFactories(SomeFactory.class, custom);
assertThat(factories).isNotNull().hasSize(1);
assertThat(factories.iterator().next().classloader()).isEqualTo(custom);
}
Aggregations