Search in sources :

Example 1 with CodeBlock

use of org.neo4j.codegen.CodeBlock in project neo4j by neo4j.

the class ByteCodeVerifierTest method shouldVerifyBytecode.

@Test
public void shouldVerifyBytecode() throws Throwable {
    // given
    CodeGenerator generator = generateCode(BYTECODE, VERIFY_GENERATED_BYTECODE);
    ClassHandle handle;
    try (ClassGenerator clazz = generator.generateClass(PACKAGE, "SimpleClass");
        CodeBlock code = clazz.generateMethod(Integer.class, "box", param(int.class, "value"))) {
        handle = clazz.handle();
        code.returns(code.load("value"));
    }
    // when
    try {
        handle.loadClass();
        fail("Should have thrown exception");
    }// then
     catch (CompilationFailureException expected) {
        assertThat(expected.toString(), containsString("box(I)"));
    }
}
Also used : ClassGenerator(org.neo4j.codegen.ClassGenerator) CodeBlock(org.neo4j.codegen.CodeBlock) CodeGenerator(org.neo4j.codegen.CodeGenerator) ClassHandle(org.neo4j.codegen.ClassHandle) CompilationFailureException(org.neo4j.codegen.CompilationFailureException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ClassGenerator (org.neo4j.codegen.ClassGenerator)1 ClassHandle (org.neo4j.codegen.ClassHandle)1 CodeBlock (org.neo4j.codegen.CodeBlock)1 CodeGenerator (org.neo4j.codegen.CodeGenerator)1 CompilationFailureException (org.neo4j.codegen.CompilationFailureException)1