@Test public void testDocFileNotFound() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", new File(new File("."), "does_not_exists").getAbsolutePath()); compiler.failCompile(); }
private Map<String, String> failDoc(String pkg) throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), pkg); compiler.failCompile(); return compiler.processor.failures; }
@Test public void testDocFileNotFile() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", new File(".").getAbsolutePath()); compiler.failCompile(); }
private String assertDocFile(String relativeName) throws Exception { File src = docFile(relativeName); Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", src.getAbsolutePath()); compiler.assertCompile(); return compiler.processor.getDoc(src.getName()); }
private String assertDoc(String pkg) throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), pkg); compiler.assertCompile(); return compiler.processor.getDoc(pkg); }
@Test public void testNestedBlocks() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.nested"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.nested"); assertThat(content, containsString("[source,java]")); assertThat(content, containsString("----")); assertThat(content, not(containsString("\\----"))); assertThat(content, containsString("System.out.println(\"Hello\");")); }
@Test public void testDocFileWithLinkToUnresolvableType() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.file"); compiler.setOption("docgen.source", docFile("docs/linktounresolvabletype.adoc").getAbsolutePath()); compiler.failCompile(); }
@Test public void testMissingPostProcessor() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.missing"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.missing"); // String processed = compiler.processor.applyPostProcessors(content); assertThat(content, containsString("This should be included.")); assertThat(content, containsString("[missing]")); assertThat(content, containsString("----")); }
@Test public void testCodeBlocks() throws Exception { // Code blocks must not be touched by pre-processors. Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.code"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.code"); assertThat(content, containsString("[source,java]")); assertThat(content, containsString("[source]")); assertThat(content, containsString("----")); assertThat(content, containsString("System.out.println(\"Hello\");")); assertThat(content, containsString(" System.out.println(\"Bye\");")); }
@Test public void testResolveLinkWithSourceAndClass() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.linkresolution.resolvable"); compiler.assertCompile(); File dependency = compiler.classOutput;
@Test public void testResolveLinkWithClass() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.linkresolution.resolvable"); compiler.assertCompile(); File dependency = compiler.classOutput;
@Test public void testVariableSubstitution() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.variables"); compiler.setOption("foo", "hello"); compiler.setOption("bar", "not-used"); compiler.setOption("baz", "vert.x"); compiler.assertCompile(); String content = compiler.processor.getDoc("io.vertx.test.variables"); String processed = compiler.processor.applyVariableSubstitution(content); assertThat(processed, containsString("hello")); assertThat(processed, containsString("${missing}")); assertThat(processed, containsString("vert.x")); assertThat(processed, containsString("${}")); assertThat(processed, not(containsString("not"))); }
@Test public void testGen() throws Exception { AtomicInteger count = new AtomicInteger(); AbstractProcessor proc = new AbstractProcessor() { @Override public Set<String> getSupportedAnnotationTypes() { return Collections.singleton("*"); } @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (count.getAndIncrement() == 0) { try { Filer filer = processingEnv.getFiler(); Element elt = processingEnv.getElementUtils().getTypeElement("gen.GeneratedClass"); JavaFileObject src = filer.createSourceFile("io.vertx.test.gen.GeneratedClass", elt); try (Writer writer = src.openWriter()) { writer.append("package io.vertx.test.gen;\npublic class GeneratedClass {\n}"); } } catch (Exception e) { e.printStackTrace(); } } return true; } }; Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.gen"); compiler.addProcessor(proc); compiler.assertCompile(); assertEquals(3, count.get()); }
Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.language"); compiler.assertCompile();
@Test public void testLinksInPostProcessedContent() throws Exception { Compiler<TestGenProcessor> compiler = buildCompiler(new TestGenProcessor(), "io.vertx.test.postprocessors.links"); compiler.assertCompile(); compiler.processor.registerPostProcessor(new PostProcessor() { @Override public String getName() { return "test"; } @Override public String process(String name, String content, String... args) { return content; } }); String content = compiler.processor.getDoc("io.vertx.test.postprocessors.links"); assertThat(content, containsString("`link:type[BaseProcessor]`")); }