Search in sources :

Example 1 with SomeFactory

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);
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) SomeFactory(io.vertx.test.spi.SomeFactory) Test(org.junit.Test)

Example 2 with SomeFactory

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);
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) File(java.io.File) SomeFactory(io.vertx.test.spi.SomeFactory) Test(org.junit.Test)

Aggregations

SomeFactory (io.vertx.test.spi.SomeFactory)2 File (java.io.File)2 URLClassLoader (java.net.URLClassLoader)2 Test (org.junit.Test)2