### Question:
ClassBuilder { public String build() throws Exception { LOG.debug("Class building started for the class %s", fluent.getKlass().getSimpleName()); var list = fluent.getNodes(); if (list.size() == 0) { throw new GeciException("There are no actual calls in the fluent structure."); } LOG.debug("There are %d nodes on the top level", list.size()); final var tree = new Tree(Node.ONCE, list); final var exitType = NodeTypeCalculator.from(methods).getReturnType(getLastNode(list)); final var lastInterface = GeciReflectionTools.normalizeTypeName(exitType); LOG.debug("The last type is %s", lastInterface); final var interfaces = build(tree, lastInterface); final var code = JavaSource.builder(); writeStartMethod(code); writeWrapperInterface(code); writeWrapperClass(code); code.write(interfaces); return code.toString(); } ClassBuilder(FluentBuilderImpl fluent); private  ClassBuilder(ClassBuilder that); String build();  }### Answer:
@Test public void testTerminalsBuildup() throws Exception { var fluent = FluentBuilder.from(TestClass.class) .one("a") .optional("b") .oneOf("a", "b", "c", "d"); var result = new ClassBuilder((FluentBuilderImpl) fluent).build(); assertEqualToFile(result, "testTerminalsBuildup.txt"); }
@Test public void testTerminalsBuildupFullSample() throws Exception { var fluent = FluentBuilder.from(TestClass.class) .one("a") .optional("b") .oneOrMore("c") .zeroOrMore("d") .oneOf("a", "b"); var result = new ClassBuilder((FluentBuilderImpl) fluent).build(); assertEqualToFile(result, "testTerminalsBuildupFullSample.txt"); }
@Test public void testTreeBuildup() throws Exception { var f = FluentBuilder.from(TestClass.class); var aOrB = f.oneOf("a", "b"); var fluent = f.one("a") .optional(aOrB) .oneOf("a", "b", "c", "d"); var result = new ClassBuilder((FluentBuilderImpl) fluent).build(); assertEqualToFile(result, "testTreeBuildup.txt"); }
@Test public void testComplexTreeBuildup() throws Exception { var f = FluentBuilder.from(TestClass.class); var aOrB = f.oneOf("a", "b"); var fluent = f.one("a") .optional(aOrB) .one("c") .zeroOrMore(aOrB) .oneOf("a", "b", "c", "d"); var result = new ClassBuilder((FluentBuilderImpl) fluent).build(); assertEqualToFile(result, "testComplexTreeBuildup.txt"); }
@Test public void testOptionalInOptionalTreeBuildup() throws Exception { var f = FluentBuilder.from(TestClass.class); var aOrB = f.oneOf(f.optional("a"), f.one("b")); var fluent = f.one("a") .optional(aOrB) .one("c").cloner("copy"); var result = new ClassBuilder((FluentBuilderImpl) fluent).build(); assertEqualToFile(result, "testOptionalInOptionalTreeBuildup.txt"); }
@Test public void testIncompleteBuildup() { var fluent = FluentBuilder.from(TestClass.class); Assertions.assertThrows(GeciException.class, () -> new ClassBuilder((FluentBuilderImpl) fluent).build()); }