FactoryTreeBuilder { public R buildTreeUnvalidated(){ factoryContext.reset(); if (rootFactory!=null) { return rootFactory; } for (Function<FactoryContext<R>, NestedBuilder<R>> customBuildersCreator : customBuildersCreators) { NestedBuilder<R> nestedBuilder = customBuildersCreator.apply(factoryContext); nestedBuilder.internal_build(this); } this.rootFactory = factoryContext.get(rootTemplateId); if (rootFactory==null){ throw new IllegalStateException("FactoryCreator missing for root class "+ rootTemplateId.clazz); } rootFactory.internal().finalise(); rootFactory.internal().setFactoryTreeBuilder(this); return rootFactory; } protected  FactoryTreeBuilder(FactoryTemplateId<R> rootTemplateId, FactoryContext<R> factoryContext); protected  FactoryTreeBuilder(FactoryTemplateId<R> rootTemplateId, Consumer<FactoryTreeBuilder<L,R>> rootTemplateAdder);  FactoryTreeBuilder(FactoryTemplateId<R> rootTemplateId, Function<FactoryContext<R>, R> creator);  FactoryTreeBuilder(Class<R> rootClass);  FactoryTreeBuilder(Class<R> rootClass, Function<FactoryContext<R>, R> creator); void addFactory(FactoryTemplateId<F> templateId, Scope scope, Function<FactoryContext<R>, F> creator); void addFactory(Class<F> clazz, Scope scope, Function<FactoryContext<R>, F> creator); void addFactory(String name, Scope scope, Function<FactoryContext<R>, F> creator); void addFactory(Class<F> clazz, String name, Scope scope, Function<FactoryContext<R>, F> creator); void addFactory(Class<F> clazz, Scope scope); void addSingleton(FactoryTemplateId<F> templateId, Function<FactoryContext<R>, F> creator); void addSingleton(Class<F> clazz, Function<FactoryContext<R>, F> creator); void addSingleton(String name, Function<FactoryContext<R>, F> creator); void addSingleton(Class<F> clazz, String name, Function<FactoryContext<R>, F> creator); void addSingleton(Class<F> clazz, String name); void addSingleton(Class<F> clazz); void addPrototype(FactoryTemplateId<F> templateId, Function<FactoryContext<R>, F> creator); void addPrototype(Class<F> clazz, Function<FactoryContext<R>, F> creator); void addPrototype(String name, Function<FactoryContext<R>, F> creator); void addPrototype(Class<F> clazz, String name, Function<FactoryContext<R>, F> creator); void addPrototype(Class<F> clazz, String name); void addPrototype(Class<F> clazz); void removeFactory(FactoryTemplateId<F> templateId); @SuppressWarnings("unchecked") void addFactoryUnsafe(FactoryTemplateId<?> templateId, Scope scope, Function<FactoryContext<R>, F> creator); @SuppressWarnings("unchecked") void addFactoryUnsafe(Class<?> clazz, Scope scope, Function<FactoryContext<R>, F> creator); void addFactoryUnsafe(String name, Scope scope, Function<FactoryContext<R>, F> creator); @SuppressWarnings("unchecked") void addFactoryUnsafe(Class<?> clazz, String name, Scope scope, Function<FactoryContext<R>, F> creator); @SuppressWarnings("unchecked") void addFactoryUnsafe(Class<?> clazz, Scope scope); R buildTree(); void markAsNonPersistentFactoryBuilder(); boolean isPersistentFactoryBuilder(); R buildTreeUnvalidated(); FO buildNewSubTree(Class<FO> factoryClazz); FO buildSubTree(Class<FO> factoryClazz); List<FO> buildSubTrees(Class<FO> factoryClazz); List<FO> buildSubTreesForLiveObject(Class<LO> liveObjectClass); BranchSelector<R> branch(); Scope getScope(FactoryTemplateId<?> factoryTemplateId); void fillFromExistingFactoryTree(R root); MicroserviceBuilder<L,R> microservice(); MicroserviceBuilder<L,R> microservice(SimpleObjectMapper simpleObjectMapper); MicroserviceBuilder<L,R> microservice(Consumer<R> mocker); boolean isRebuildAble(List<FactoryBase<?, R>> existingFactoryBases); R rebuildTreeUnvalidated(List<FactoryBase<?, R>> existingFactoryBases); void addBuilder(Function<FactoryContext<R>, NestedBuilder<R>> builderCreators); FactoryTemplateId<R> getRootTemplateId(); FactoryTreeBuilder<L,R> copy();  }
@Test public void test_incomplete_builder_class() { Assertions.assertThrows(IllegalStateException.class, () -> { FactoryTreeBuilder< ExampleLiveObjectA, ExampleFactoryA> builder = new FactoryTreeBuilder<>(ExampleFactoryA.class, context -> { ExampleFactoryA factoryBases = new ExampleFactoryA(); factoryBases.referenceAttribute.set(context.get(io.github.factoryfx.factory.testfactories.ExampleFactoryB.class)); factoryBases.referenceAttribute.set(null); return factoryBases; }); ExampleFactoryA root = builder.buildTreeUnvalidated(); }); }
@Test public void test_incomplete_builder_classAndName() { Assertions.assertThrows(IllegalStateException.class, () -> { FactoryTreeBuilder< ExampleLiveObjectA, ExampleFactoryA> builder = new FactoryTreeBuilder<>(ExampleFactoryA.class, context -> { ExampleFactoryA factoryBases = new ExampleFactoryA(); factoryBases.referenceAttribute.set(context.get(io.github.factoryfx.factory.testfactories.ExampleFactoryB.class, "dfgdgf")); factoryBases.referenceAttribute.set(null); return factoryBases; }); ExampleFactoryA root = builder.buildTreeUnvalidated(); }); }