Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/impl/AccessorTest.java @ 22533:1f7fe9f4207a
Putting the reflection back to allow the test to run when Accessor and the test are loaded by different classloaders
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 07 Jan 2016 11:07:28 +0100 |
parents | 5692953272eb |
children |
comparison
equal
deleted
inserted
replaced
22532:abb919421c2a | 22533:1f7fe9f4207a |
---|---|
20 * or visit www.oracle.com if you need additional information or have any | 20 * or visit www.oracle.com if you need additional information or have any |
21 * questions. | 21 * questions. |
22 */ | 22 */ |
23 package com.oracle.truffle.api.impl; | 23 package com.oracle.truffle.api.impl; |
24 | 24 |
25 import static org.junit.Assert.assertNotNull; | |
26 import static org.junit.Assert.assertNull; | |
27 | |
28 import java.lang.reflect.Field; | |
29 import java.util.concurrent.Executors; | 25 import java.util.concurrent.Executors; |
30 | 26 |
31 import org.junit.BeforeClass; | 27 import org.junit.BeforeClass; |
32 import org.junit.Test; | 28 import org.junit.Test; |
33 | 29 |
34 import com.oracle.truffle.api.source.Source; | 30 import com.oracle.truffle.api.source.Source; |
35 import com.oracle.truffle.api.vm.ImplicitExplicitExportTest.ExportImportLanguage1; | 31 import com.oracle.truffle.api.vm.ImplicitExplicitExportTest.ExportImportLanguage1; |
36 import static com.oracle.truffle.api.vm.ImplicitExplicitExportTest.L1; | 32 import static com.oracle.truffle.api.vm.ImplicitExplicitExportTest.L1; |
37 import com.oracle.truffle.api.vm.PolyglotEngine; | 33 import com.oracle.truffle.api.vm.PolyglotEngine; |
34 import java.lang.reflect.Method; | |
35 import static org.junit.Assert.assertNotNull; | |
36 import static org.junit.Assert.assertNull; | |
38 | 37 |
39 public class AccessorTest { | 38 public class AccessorTest { |
40 public static Accessor API; | 39 public static Method find; |
41 | 40 |
42 @BeforeClass | 41 @BeforeClass |
43 public static void initAccessors() throws Exception { | 42 public static void initAccessors() throws Exception { |
44 Field f = Accessor.class.getDeclaredField("API"); | 43 find = Accessor.class.getDeclaredMethod("findLanguageByClass", Object.class, Class.class); |
45 f.setAccessible(true); | 44 find.setAccessible(true); |
46 API = (Accessor) f.get(null); | |
47 } | 45 } |
48 | 46 |
49 @Test | 47 @Test |
50 public void canGetAccessToOwnLanguageInstance() throws Exception { | 48 public void canGetAccessToOwnLanguageInstance() throws Exception { |
51 PolyglotEngine vm = PolyglotEngine.newBuilder().executor(Executors.newSingleThreadExecutor()).build(); | 49 PolyglotEngine vm = PolyglotEngine.newBuilder().executor(Executors.newSingleThreadExecutor()).build(); |
54 | 52 |
55 Source s = Source.fromText("return nothing", "nothing"); | 53 Source s = Source.fromText("return nothing", "nothing"); |
56 Object ret = language.eval(s).get(); | 54 Object ret = language.eval(s).get(); |
57 assertNull("nothing is returned", ret); | 55 assertNull("nothing is returned", ret); |
58 | 56 |
59 ExportImportLanguage1 afterInitialization = Accessor.findLanguageByClass(vm, ExportImportLanguage1.class); | 57 ExportImportLanguage1 afterInitialization = (ExportImportLanguage1) find.invoke(null, vm, ExportImportLanguage1.class); |
60 assertNotNull("Language found", afterInitialization); | 58 assertNotNull("Language found", afterInitialization); |
61 } | 59 } |
62 } | 60 } |