use of com.alipay.sofa.ark.container.test.TestClassLoader in project sofa-ark by alipay.
the class ClassLoaderTest method testDelegateConfigure.
@Test
public void testDelegateConfigure() throws Throwable {
EnvironmentUtils.setProperty(Constants.FORCE_DELEGATE_TO_TEST_CLASSLOADER, Test.class.getPackage().getName());
EnvironmentUtils.setProperty(Constants.FORCE_DELEGATE_TO_APP_CLASSLOADER, ClassLoaderTest.class.getPackage().getName());
// incompatible with JDK9+
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
TestClassLoader testClassLoader = new TestClassLoader("mock:1.0", urlClassLoader.getURLs(), urlClassLoader);
Assert.assertEquals(testClassLoader, testClassLoader.loadClass(Test.class.getCanonicalName()).getClassLoader());
Assert.assertEquals(urlClassLoader, testClassLoader.loadClass(ClassLoaderTest.class.getCanonicalName()).getClassLoader());
EnvironmentUtils.clearProperty(Constants.FORCE_DELEGATE_TO_APP_CLASSLOADER);
EnvironmentUtils.clearProperty(Constants.FORCE_DELEGATE_TO_TEST_CLASSLOADER);
}
use of com.alipay.sofa.ark.container.test.TestClassLoader in project sofa-ark by alipay.
the class ClassLoaderTest method testDefaultDelegate.
@Test
public void testDefaultDelegate() throws Throwable {
// incompatible with JDK9+
URLClassLoader urlClassLoader = (URLClassLoader) ClassLoader.getSystemClassLoader();
TestClassLoader testClassLoader = new TestClassLoader("mock:1.0", urlClassLoader.getURLs(), urlClassLoader);
Assert.assertEquals(urlClassLoader, testClassLoader.loadClass(Test.class.getCanonicalName()).getClassLoader());
Assert.assertEquals(testClassLoader, testClassLoader.loadClass(ClassLoaderTest.class.getCanonicalName()).getClassLoader());
}
use of com.alipay.sofa.ark.container.test.TestClassLoader in project sofa-ark by alipay.
the class ArkJUnit4RunnerTest method test.
@Test
public void test() {
ClassLoader testClassLoader = getClass().getClassLoader();
Assert.assertTrue(testClassLoader.getClass().getCanonicalName().equals(TestClassLoader.class.getCanonicalName()));
Assert.assertTrue("@Before".equals(state));
state = "@Test";
ClassLoader testClCl = testClassLoader.getClass().getClassLoader();
Assert.assertTrue(testClCl.getClass().getCanonicalName().equals(ContainerClassLoader.class.getCanonicalName()));
}
Aggregations