private Compiled compile(String name) { add(name); add("com.example.Mock"); ClassLoader classLoader = start(operatorProcessor()); Class<?> origin = load(classLoader, name); Object factory = create(classLoader, Constants.getFactoryClass(name)); Object impl = create(classLoader, Constants.getImplementationClass(name)); return new Compiled(origin, factory, impl); }
/** raise errors on initialize. */ @Test public void failure_init() { add("com.example.Simple"); add("com.example.Mock"); error( new OperatorAnnotationProcessor() { @Override protected CompileEnvironment createCompileEnvironment( ProcessingEnvironment processingEnv) { throw new RuntimeException(); } }); }
/** raise errors on process. */ @Test public void failure_process() { add( new Driver() { @Override public OperatorDescription analyze(Context context) { throw new RuntimeException(); } }); add("com.example.Simple"); add("com.example.Mock"); error(operatorProcessor()); }
private Object compile(String name) { add(name); ClassLoader classLoader = start( new Callback() { @Override protected void test() { TypeElement element = env.findTypeElement(new ClassDescription(name)); if (round.getRootElements().contains(element)) { assertThat(name, element, is(notNullValue())); OperatorImplementationEmitter emitter = new OperatorImplementationEmitter(env); emitter.emit(new OperatorClass(element, Collections.emptyList())); } } }); return create(classLoader, Constants.getImplementationClass(name)); }
/** simple testing. */ @Test public void simple() { add( new Driver() { @Override public OperatorDescription analyze(Context context) { List<Node> parameters = new ArrayList<>(); parameters.add( new Node( Kind.INPUT, "in", new ReferenceDocument(new ParameterReference(0)), context.getEnvironment().findDeclaredType(Descriptions.classOf(String.class)), new ParameterReference(0))); List<Node> outputs = new ArrayList<>(); outputs.add( new Node( Kind.OUTPUT, "out", new ReferenceDocument(new ReturnReference()), context .getEnvironment() .findDeclaredType(Descriptions.classOf(CharSequence.class)), new ReturnReference())); return new OperatorDescription( new ReferenceDocument(new MethodReference()), parameters, outputs); } }); Compiled compiled = compile("com.example.Simple"); assertThat(compiled.implementation, is(instanceOf(compiled.originalClass))); Method impleMethod = method(compiled.implementation.getClass(), "method", String.class); assertThat(impleMethod, is(notNullValue())); assertThat(Modifier.isAbstract(impleMethod.getModifiers()), is(false)); Object node = invoke(compiled.factory, "method", MockSource.of(String.class)); assertThat(field(node.getClass(), "out"), is(notNullValue())); }