use of com.google.template.soy.jbcsrc.restricted.testing.ExpressionTester.BooleanInvoker in project closure-templates by google.
the class MemoryClassLoaderTest method testAsResource.
@Test
public void testAsResource() throws IOException {
BooleanInvoker invoker = ExpressionTester.createInvoker(BooleanInvoker.class, FALSE);
byte[] classBytes = ByteStreams.toByteArray(invoker.getClass().getClassLoader().getResourceAsStream(invoker.getClass().getName().replace('.', '/') + ".class"));
ClassNode node = new ClassNode();
new ClassReader(classBytes).accept(node, 0);
assertThat(node.name).isEqualTo(Type.getInternalName(invoker.getClass()));
}
use of com.google.template.soy.jbcsrc.restricted.testing.ExpressionTester.BooleanInvoker in project closure-templates by google.
the class MemoryClassLoaderTest method testDelegation.
@Test
public void testDelegation() throws Exception {
// We want to make sure that for generated types, our classloader doesn't delegate to its parent
// loader
ClassData parentClass = ExpressionTester.createClass(BooleanInvoker.class, FALSE);
ClassData childClass = ExpressionTester.createClass(BooleanInvoker.class, TRUE);
// sanity check, they have the same fully qualified class name
assertThat(parentClass.type()).isEqualTo(childClass.type());
TypeInfo type = childClass.type();
MemoryClassLoader parentLoader = new MemoryClassLoader(ImmutableList.of(parentClass));
MemoryClassLoader childLoader = new MemoryClassLoader(parentLoader, ImmutableList.of(childClass));
BooleanInvoker fromParent = parentLoader.loadClass(type.className()).asSubclass(BooleanInvoker.class).getConstructor().newInstance();
assertThat(fromParent.invoke()).isFalse();
BooleanInvoker fromChild = childLoader.loadClass(type.className()).asSubclass(BooleanInvoker.class).getConstructor().newInstance();
assertThat(fromChild.invoke()).isTrue();
assertThat(fromChild.getClass()).isNotEqualTo(fromParent.getClass());
}
use of com.google.template.soy.jbcsrc.restricted.testing.ExpressionTester.BooleanInvoker in project closure-templates by google.
the class MemoryClassLoaderTest method testCollectable.
// Our memory classloaders should be garbage collectable when all references to their types
// disapear
@Test
public void testCollectable() {
BooleanInvoker invoker = ExpressionTester.createInvoker(BooleanInvoker.class, FALSE);
// sanity, the invoker works
assertThat(invoker.invoke()).isFalse();
MemoryClassLoader loader = (MemoryClassLoader) invoker.getClass().getClassLoader();
WeakReference<MemoryClassLoader> loaderRef = new WeakReference<MemoryClassLoader>(loader);
// unpin
invoker = null;
loader = null;
GcFinalization.awaitClear(loaderRef);
}
Aggregations