FunctionModel { public InvokableFunction build(FunctionBuilder builder, ComponentMap components) { Object receiver = builder.create(_root, components); return _rootMetadata.getInvokableFunction(receiver); } private  FunctionModel(FunctionModelNode root, FunctionMetadata rootMetadata); InvokableFunction build(FunctionBuilder builder, ComponentMap components); FunctionModelNode getRoot(); boolean isValid(); String prettyPrint(); String prettyPrint(boolean showProxies); static FunctionModel forFunction(FunctionMetadata function,
                                          FunctionModelConfig config,
                                          Set<Class<?>> availableComponents,
                                          NodeDecorator... nodeDecorators); static FunctionModel forFunction(FunctionMetadata function,
                                          FunctionModelConfig config,
                                          Set<Class<?>> availableComponents,
                                          NodeDecorator nodeDecorator,
                                          ArgumentConverter argumentConverter); static FunctionModel forFunction(FunctionMetadata function, FunctionModelConfig config); static FunctionModel forFunction(FunctionMetadata function); static FunctionModel forFunction(FunctionMetadata function, FunctionModelNode functionNode); static T build(Class<T> functionType,
                            FunctionModelConfig config,
                            ComponentMap componentMap,
                            NodeDecorator... nodeDecorators); static T build(Class<T> functionType,
                            FunctionModelConfig config,
                            ComponentMap componentMap,
                            FunctionBuilder functionBuilder,
                            NodeDecorator... nodeDecorators); static T build(Class<T> functionType, FunctionModelConfig config); static T build(Class<T> functionType);  }
@Test public void buildDirectly1() { Concrete1 fn = FunctionModel.build(Concrete1.class); assertNotNull(fn); }
@Test public void buildDirectly2() { FunctionModelConfig config = config(implementations(TestFn.class, BasicImpl.class)); TestFn fn = FunctionModel.build(TestFn.class, config); assertTrue(fn instanceof BasicImpl); }
@Test public void buildDirectly3() { ComponentMap infrastructure = ComponentMap.of(ImmutableMap.<Class<?>, Object>of(String.class, INFRASTRUCTURE_COMPONENT)); FunctionModelConfig config = config(implementations(TestFn.class, InfrastructureImpl.class)); TestFn fn = FunctionModel.build(TestFn.class, config, infrastructure); assertTrue(fn instanceof InfrastructureImpl); assertEquals(INFRASTRUCTURE_COMPONENT, ((InfrastructureImpl) fn)._infrastructureComponent); }
@Test public void decoratorFunction() { FunctionModelConfig config = config(implementations(Fn.class, Impl.class)); FunctionModelConfig decoratedConfig = config.decoratedWith(Decorator1.class); Fn fn = FunctionModel.build(Fn.class, decoratedConfig); assertEquals("2", fn.foo(1)); }
@Test public void decoratorFunctions() { FunctionModelConfig config = config(implementations(Fn.class, Impl.class)); FunctionModelConfig decoratedConfig = config.decoratedWith(Decorator2.class).decoratedWith(Decorator1.class); Fn fn = FunctionModel.build(Fn.class, decoratedConfig); assertEquals("5", fn.foo(2)); }
@Test public void decoratorFunctionsReversed() { FunctionModelConfig config = config(implementations(Fn.class, Impl.class)); FunctionModelConfig decoratedConfig = config.decoratedWith(Decorator1.class).decoratedWith(Decorator2.class); Fn fn = FunctionModel.build(Fn.class, decoratedConfig); assertEquals("6", fn.foo(2)); }