Add more tests for BlockProcessors that set a name with their constructor
MODIFY
asciidoctorj-core/src/test/java/org/asciidoctor/extension/BlockProcessorRegistrationTest.java
asciidoctorj-core/src/test/java/org/asciidoctor/extension/BlockProcessorRegistrationTest.java
@@ -48,6 +48,26 @@ public class BlockProcessorRegistrationTest {
}
}
+ public static class TestProcessorWithName extends BlockProcessor {
+
+ public static final String NAME = "somename";
+
+ public TestProcessorWithName() {
+ super(NAME);
+ }
+
+ @Override
+ public Object process(StructuralNode parent, Reader reader, Map<String, Object> attributes) {
+ List<String> s = reader.readLines().stream()
+ .map(line ->
+ line.chars()
+ .mapToObj(c -> Character.toString((char) c))
+ .collect(joining(" ")))
+ .collect(toList());
+ return createBlock(parent, "paragraph", s);
+ }
+ }
+
@Name(AnnotatedTestProcessor.NAME)
public static class AnnotatedTestProcessor extends AbstractTestProcessor {
public static final String NAME = "annotated";
@@ -117,6 +137,36 @@ public class BlockProcessorRegistrationTest {
}
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testRegisterClassWithNameAsClass() {
+ asciidoctor.javaExtensionRegistry().block(TestProcessorWithName.class);
+ }
+
+ @Test
+ public void testRegisterClassWithNameAsClassWithExplicitName() {
+ final String explicitblockname = "explicitblockname";
+ asciidoctor.javaExtensionRegistry().block(explicitblockname, TestProcessorWithName.class);
+ final String result = asciidoctor.convert(document(explicitblockname, "Hello Explicit"), OptionsBuilder.options());
+ check("H e l l o E x p l i c i t", result);
+ }
+
+ @Test
+ public void testRegisterClassWithNameAsInstance() {
+ asciidoctor.javaExtensionRegistry().block(new TestProcessorWithName());
+ final String result = asciidoctor.convert(document(TestProcessorWithName.NAME, "Another Test"), OptionsBuilder.options());
+ check("A n o t h e r T e s t", result);
+ }
+
+ @Test
+ public void testRegisterClassWithNameAsInstanceWithExplicitName() {
+ final String blockName = "somename";
+ asciidoctor.javaExtensionRegistry().block(blockName, new TestProcessorWithName());
+ final String result = asciidoctor.convert(document(blockName, "Yet Another Test"), OptionsBuilder.options());
+ check("Y e t A n o t h e r T e s t", result);
+ }
+
+
private void check(String expected, String html) {
assertEquals(expected, Jsoup.parse(html).select("div.paragraph > p").first().text());
}

Add more tests for BlockProcessors that set a name with their constructor