Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/profiles/LazyProfileLoadingTest.java @ 22530:4ba1aa33fda4
Run all tests with SeparateClassLoaderRunner to ensure package private methods are accessible even if the truffle.jar is on bootclasspath.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 06 Jan 2016 13:52:35 +0100 |
parents | a63bda98cfdb |
children |
comparison
equal
deleted
inserted
replaced
22529:2643b968c0c6 | 22530:4ba1aa33fda4 |
---|---|
22 */ | 22 */ |
23 package com.oracle.truffle.api.profiles; | 23 package com.oracle.truffle.api.profiles; |
24 | 24 |
25 import java.lang.reflect.InvocationTargetException; | 25 import java.lang.reflect.InvocationTargetException; |
26 import java.lang.reflect.Method; | 26 import java.lang.reflect.Method; |
27 import java.net.URLClassLoader; | |
28 | 27 |
29 import org.junit.Assert; | 28 import org.junit.Assert; |
30 import org.junit.Test; | 29 import org.junit.Test; |
31 import org.junit.runner.RunWith; | 30 import org.junit.runner.RunWith; |
32 import org.junit.runners.BlockJUnit4ClassRunner; | |
33 import org.junit.runners.model.InitializationError; | |
34 | 31 |
35 import com.oracle.truffle.api.Truffle; | 32 import com.oracle.truffle.api.Truffle; |
36 import com.oracle.truffle.api.profiles.LazyProfileLoadingTest.SeparateClassloaderTestRunner; | |
37 | 33 |
38 @RunWith(SeparateClassloaderTestRunner.class) | 34 @RunWith(SeparateClassloaderTestRunner.class) |
39 public class LazyProfileLoadingTest { | 35 public class LazyProfileLoadingTest { |
40 | 36 |
41 @Test | 37 @Test |
103 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { | 99 } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
104 throw new RuntimeException(e); | 100 throw new RuntimeException(e); |
105 } | 101 } |
106 } | 102 } |
107 | 103 |
108 public static class SeparateClassloaderTestRunner extends BlockJUnit4ClassRunner { | |
109 | |
110 public SeparateClassloaderTestRunner(Class<?> clazz) throws InitializationError { | |
111 super(getFromTestClassloader(clazz)); | |
112 } | |
113 | |
114 private static Class<?> getFromTestClassloader(Class<?> clazz) throws InitializationError { | |
115 try { | |
116 ClassLoader testClassLoader = new TestClassLoader(); | |
117 return Class.forName(clazz.getName(), true, testClassLoader); | |
118 } catch (ClassNotFoundException e) { | |
119 throw new InitializationError(e); | |
120 } | |
121 } | |
122 | |
123 public static class TestClassLoader extends URLClassLoader { | |
124 public TestClassLoader() { | |
125 super(((URLClassLoader) getSystemClassLoader()).getURLs()); | |
126 } | |
127 | |
128 @Override | |
129 public Class<?> loadClass(String name) throws ClassNotFoundException { | |
130 if (name.startsWith(Profile.class.getPackage().getName())) { | |
131 return super.findClass(name); | |
132 } | |
133 return super.loadClass(name); | |
134 } | |
135 } | |
136 } | |
137 | |
138 } | 104 } |