diff --git a/asciidoctorj-arquillian-extension/build.gradle b/asciidoctorj-arquillian-extension/build.gradle
index 214e3c82c..a5f8b8b73 100644
--- a/asciidoctorj-arquillian-extension/build.gradle
+++ b/asciidoctorj-arquillian-extension/build.gradle
@@ -1,10 +1,11 @@
dependencies {
compileOnly project(':asciidoctorj')
- api project(':asciidoctorj-test-support')
+ implementation(project(':asciidoctorj-test-support')) { transitive = false }
api "org.jboss.arquillian.container:arquillian-container-spi:$arquillianVersion"
api "org.jboss.arquillian.container:arquillian-container-test-spi:$arquillianVersion"
api "org.jboss.arquillian.container:arquillian-container-impl-base:$arquillianVersion"
api "org.jboss.arquillian.container:arquillian-container-test-impl-base:$arquillianVersion"
+ api "junit:junit:$junit4Version"
}
def javaApiUrl = "https://docs.oracle.com/javase/8/docs/api/"
diff --git a/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/AsciidoctorTestObserver.java b/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/AsciidoctorTestObserver.java
index 99a0f50c4..a87afe72b 100644
--- a/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/AsciidoctorTestObserver.java
+++ b/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/AsciidoctorTestObserver.java
@@ -4,7 +4,7 @@
import org.asciidoctor.arquillian.api.Shared;
import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.jruby.AsciidoctorJRuby;
-import org.asciidoctor.util.ClasspathResources;
+import org.asciidoctor.junit.ClasspathResources;
import org.jboss.arquillian.core.api.InstanceProducer;
import org.jboss.arquillian.core.api.annotation.ApplicationScoped;
import org.jboss.arquillian.core.api.annotation.Inject;
@@ -122,7 +122,7 @@ public void afterTestClassShutdownSharedTemporaryFolderInstance(@Observes AfterC
}
private boolean isSharedInstanceRequired(Class> testClass, Class> resourceClass) {
- for (Field f: SecurityActions.getFieldsWithAnnotation(testClass, ArquillianResource.class)) {
+ for (Field f : SecurityActions.getFieldsWithAnnotation(testClass, ArquillianResource.class)) {
ArquillianResource arquillianResource = SecurityActions.getAnnotation(f, ArquillianResource.class);
if (f.getType() == resourceClass && arquillianResource.value() == Shared.class) {
return true;
@@ -132,7 +132,7 @@ private boolean isSharedInstanceRequired(Class> testClass, Class> resourceCl
}
private boolean isUnsharedInstanceRequired(Class> testClass, Class> resourceClass) {
- for (Field f: SecurityActions.getFieldsWithAnnotation(testClass, ArquillianResource.class)) {
+ for (Field f : SecurityActions.getFieldsWithAnnotation(testClass, ArquillianResource.class)) {
ArquillianResource arquillianResource = SecurityActions.getAnnotation(f, ArquillianResource.class);
if (f.getType() == resourceClass &&
(arquillianResource.value() == ArquillianResource.class || arquillianResource.value() == Unshared.class)) {
@@ -171,4 +171,4 @@ private boolean isUnsharedInstanceRequired(Method testMethod, Class> resourceC
}
return false;
}
-}
\ No newline at end of file
+}
diff --git a/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/ClasspathResourcesResourceProvider.java b/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/ClasspathResourcesResourceProvider.java
index fa6ce7d40..54e49e2b0 100644
--- a/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/ClasspathResourcesResourceProvider.java
+++ b/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/arquillian/ClasspathResourcesResourceProvider.java
@@ -1,6 +1,6 @@
package org.asciidoctor.arquillian;
-import org.asciidoctor.util.ClasspathResources;
+import org.asciidoctor.junit.ClasspathResources;
import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.annotation.ApplicationScoped;
import org.jboss.arquillian.core.api.annotation.Inject;
@@ -24,4 +24,4 @@ public boolean canProvide(Class> type) {
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
return classpathResourcesInstance.get();
}
-}
\ No newline at end of file
+}
diff --git a/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java b/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/junit/ClasspathResources.java
similarity index 70%
rename from asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java
rename to asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/junit/ClasspathResources.java
index abf81ba38..e66a1c8b1 100644
--- a/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java
+++ b/asciidoctorj-arquillian-extension/src/main/java/org/asciidoctor/junit/ClasspathResources.java
@@ -1,5 +1,6 @@
-package org.asciidoctor.util;
+package org.asciidoctor.junit;
+import org.asciidoctor.test.extension.ClasspathHelper;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@@ -9,17 +10,19 @@
*
* Delegates to {@link ClasspathHelper}.
*/
-public class ClasspathResources extends ClasspathHelper implements TestRule {
+public class ClasspathResources implements TestRule {
+
+ private ClasspathHelper classpathHelper;
public ClasspathResources() {
}
public ClasspathResources(Class> clazz) {
- setClassloader(clazz);
+ classpathHelper = new ClasspathHelper(clazz);
}
protected void before(Class> clazz) {
- super.setClassloader(clazz);
+ classpathHelper = new ClasspathHelper(clazz);
}
@Override
diff --git a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java
index c4f83a798..64415a30e 100644
--- a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java
+++ b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java
@@ -1,13 +1,14 @@
package org.asciidoctor.cli;
import org.asciidoctor.cli.jruby.AsciidoctorInvoker;
-import org.asciidoctor.util.ClasspathHelper;
+import org.asciidoctor.test.ClasspathResource;
+import org.asciidoctor.test.extension.ClasspathExtension;
import org.assertj.core.api.Assertions;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
-import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayOutputStream;
@@ -22,31 +23,24 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.core.StringStartsWith.startsWith;
+@ExtendWith(ClasspathExtension.class)
public class WhenAsciidoctorIsCalledUsingCli {
- private static final String SAMPLE_FILE = "rendersample.asciidoc";
- private static final String BROKEN_INCLUDE_ASCIIDOC = "brokeninclude.asciidoc";
- private static final String TOC_SAMPLE_ASCIIDOC = "tocsample.asciidoc";
+ static final String SOURCE_EXTENSION_PATTERN = "\\.asciidoc$";
- private static final String SOURCE_EXTENSION_PATTERN = "\\.asciidoc$";
+ @ClasspathResource("rendersample.asciidoc")
+ private File renderSampleDocument;
+ @ClasspathResource("brokeninclude.asciidoc")
+ private File brokenIncludeDocument;
+ @ClasspathResource("tocsample.asciidoc")
+ private File tocSampleDocument;
- private static ClasspathHelper classpath;
+ final String pwd = new File("").getAbsolutePath();
- @TempDir
- public File temporaryFolder;
-
- public String pwd = new File("").getAbsolutePath();
-
- @BeforeAll
- static void beforeAll() {
- classpath = new ClasspathHelper();
- classpath.setClassloader(WhenAsciidoctorIsCalledUsingCli.class);
- }
@Test
- public void with_no_options_file_should_be_rendered_in_place_and_in_html5_format() throws IOException {
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void with_no_options_file_should_be_rendered_in_place_and_in_html5_format() throws IOException {
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke(inputPath);
@@ -56,9 +50,8 @@ public void with_no_options_file_should_be_rendered_in_place_and_in_html5_format
}
@Test
- public void should_honor_doctype_defined_in_document_by_default() throws IOException {
- File inputFile = classpath.getResource("sample-book.adoc");
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void should_honor_doctype_defined_in_document_by_default(@ClasspathResource("sample-book.adoc") File sampleBookDocument) throws IOException {
+ final String inputPath = sampleBookDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke(inputPath);
@@ -72,9 +65,8 @@ public void should_honor_doctype_defined_in_document_by_default() throws IOExcep
}
@Test
- public void file_should_be_rendered_to_docbook_with_docbook_backend() throws IOException {
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void file_should_be_rendered_to_docbook_with_docbook_backend() throws IOException {
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke("-b", "docbook", inputPath);
@@ -84,9 +76,8 @@ public void file_should_be_rendered_to_docbook_with_docbook_backend() throws IOE
}
@Test
- public void single_attributes_should_be_interpreted_as_boolean() throws IOException {
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void single_attributes_should_be_interpreted_as_boolean() throws IOException {
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke("-a", "linkcss!", inputPath);
@@ -102,9 +93,8 @@ public void single_attributes_should_be_interpreted_as_boolean() throws IOExcept
}
@Test
- public void composed_attributes_should_be_built_as_attributes_map() throws IOException {
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void composed_attributes_should_be_built_as_attributes_map() throws IOException {
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke("-a", "stylesheet=mystyles.css", "-a", "linkcss", inputPath);
@@ -119,20 +109,18 @@ public void composed_attributes_should_be_built_as_attributes_map() throws IOExc
}
@Test
- public void destination_dir_should_render_files_to_ouput_directory() throws IOException {
- File outputDirectory = temporaryFolder;
+ void destination_dir_should_render_files_to_ouput_directory(@TempDir File temporaryFolder) throws IOException {
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
- new AsciidoctorInvoker().invoke("-D", outputDirectory.getAbsolutePath(), inputPath);
+ new AsciidoctorInvoker().invoke("-D", temporaryFolder.getAbsolutePath(), inputPath);
- File expectedFile = new File(outputDirectory, inputFile.getName().replaceFirst(SOURCE_EXTENSION_PATTERN, ".html"));
+ File expectedFile = new File(temporaryFolder, renderSampleDocument.getName().replaceFirst(SOURCE_EXTENSION_PATTERN, ".html"));
assertThat(expectedFile.exists(), is(true));
}
@Test
- public void empty_input_file_name_should_throw_an_exception() {
+ void empty_input_file_name_should_throw_an_exception() {
Throwable throwable = catchThrowable(() -> new AsciidoctorInvoker().invoke(""));
Assertions.assertThat(throwable)
@@ -140,7 +128,7 @@ public void empty_input_file_name_should_throw_an_exception() {
}
@Test
- public void version_flag_should_print_version_and_exit() throws IOException {
+ void version_flag_should_print_version_and_exit() throws IOException {
PrintStream oldOs = System.out;
ByteArrayOutputStream os = new ByteArrayOutputStream();
System.setOut(new PrintStream(os));
@@ -153,7 +141,7 @@ public void version_flag_should_print_version_and_exit() throws IOException {
}
@Test
- public void invalid_input_file_should_throw_an_exception() {
+ void invalid_input_file_should_throw_an_exception() {
Throwable throwable = catchThrowable(() -> new AsciidoctorInvoker().invoke("myunknown.adoc"));
Assertions.assertThat(throwable)
@@ -161,11 +149,9 @@ public void invalid_input_file_should_throw_an_exception() {
}
@Test
- public void should_convert_multiple_inputs() throws IOException {
- File inputFile1 = classpath.getResource(SAMPLE_FILE);
- String inputPath1 = inputFile1.getPath().substring(pwd.length() + 1);
- File inputFile2 = classpath.getResource(TOC_SAMPLE_ASCIIDOC);
- String inputPath2 = inputFile2.getPath().substring(pwd.length() + 1);
+ void should_convert_multiple_inputs() throws IOException {
+ final String inputPath1 = renderSampleDocument.getPath().substring(pwd.length() + 1);
+ final String inputPath2 = tocSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke(inputPath1, inputPath2);
@@ -179,10 +165,9 @@ public void should_convert_multiple_inputs() throws IOException {
}
@Test
- public void glob_expression_can_be_used_to_render_AsciiDoc_files() throws IOException {
- File inputFile = classpath.getResource(TOC_SAMPLE_ASCIIDOC);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
- String inputGlob = new File(new File(inputPath).getParentFile(), "toc*ple.asciidoc").getPath();
+ void glob_expression_can_be_used_to_render_AsciiDoc_files() throws IOException {
+ final String inputPath = tocSampleDocument.getPath().substring(pwd.length() + 1);
+ final String inputGlob = new File(new File(inputPath).getParentFile(), "toc*ple.asciidoc").getPath();
new AsciidoctorInvoker().invoke(inputGlob);
@@ -193,8 +178,8 @@ public void glob_expression_can_be_used_to_render_AsciiDoc_files() throws IOExce
}
@Test
- public void help_option_should_show_usage_information() throws IOException {
- ByteArrayOutputStream output = redirectStdout();
+ void help_option_should_show_usage_information() throws IOException {
+ final ByteArrayOutputStream output = redirectStdout();
new AsciidoctorInvoker().invoke("--help");
@@ -203,8 +188,8 @@ public void help_option_should_show_usage_information() throws IOException {
}
@Test
- public void no_parameters_should_show_usage_information() throws IOException {
- ByteArrayOutputStream output = redirectStdout();
+ void no_parameters_should_show_usage_information() throws IOException {
+ final ByteArrayOutputStream output = redirectStdout();
new AsciidoctorInvoker().invoke();
@@ -213,10 +198,9 @@ public void no_parameters_should_show_usage_information() throws IOException {
}
@Test
- public void output_file_hyphen_symbol_should_render_output_to_stdout() throws IOException {
- ByteArrayOutputStream output = redirectStdout();
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void output_file_hyphen_symbol_should_render_output_to_stdout() throws IOException {
+ final ByteArrayOutputStream output = redirectStdout();
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke("-o", "-", inputPath);
@@ -227,10 +211,9 @@ public void output_file_hyphen_symbol_should_render_output_to_stdout() throws IO
}
@Test
- public void verbose_option_should_fill_monitor_map() throws IOException {
- ByteArrayOutputStream output = redirectStdout();
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void verbose_option_should_fill_monitor_map() throws IOException {
+ final ByteArrayOutputStream output = redirectStdout();
+ final String inputPath = renderSampleDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke("--timings", inputPath);
@@ -240,10 +223,9 @@ public void verbose_option_should_fill_monitor_map() throws IOException {
}
@Test
- public void quiet_option_should_not_write_to_console() throws IOException {
- ByteArrayOutputStream output = redirectStdout();
- File inputFile = classpath.getResource(BROKEN_INCLUDE_ASCIIDOC);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void quiet_option_should_not_write_to_console() throws IOException {
+ final ByteArrayOutputStream output = redirectStdout();
+ final String inputPath = brokenIncludeDocument.getPath().substring(pwd.length() + 1);
new AsciidoctorInvoker().invoke("--quiet", inputPath);
@@ -252,9 +234,8 @@ public void quiet_option_should_not_write_to_console() throws IOException {
}
@Test
- public void should_exit_with_zero_status_even_if_errors_were_logged() throws IOException {
- File inputFile = classpath.getResource(BROKEN_INCLUDE_ASCIIDOC);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void should_exit_with_zero_status_even_if_errors_were_logged() throws IOException {
+ final String inputPath = brokenIncludeDocument.getPath().substring(pwd.length() + 1);
int status = new AsciidoctorInvoker().invoke(inputPath);
@@ -262,9 +243,8 @@ public void should_exit_with_zero_status_even_if_errors_were_logged() throws IOE
}
@Test
- public void should_exit_with_nonzero_status_if_logged_severity_was_at_least_failure_level() throws IOException {
- File inputFile = classpath.getResource(BROKEN_INCLUDE_ASCIIDOC);
- String inputPath = inputFile.getPath().substring(pwd.length() + 1);
+ void should_exit_with_nonzero_status_if_logged_severity_was_at_least_failure_level() throws IOException {
+ String inputPath = brokenIncludeDocument.getPath().substring(pwd.length() + 1);
int status = new AsciidoctorInvoker().invoke("--failure-level", "warn", inputPath);
@@ -272,9 +252,8 @@ public void should_exit_with_nonzero_status_if_logged_severity_was_at_least_fail
}
@Test
- public void with_absolute_path_file_should_be_rendered() throws IOException {
- File inputFile = classpath.getResource(SAMPLE_FILE);
- String inputPath = inputFile.getAbsolutePath();
+ void with_absolute_path_file_should_be_rendered() throws IOException {
+ String inputPath = renderSampleDocument.getAbsolutePath();
new AsciidoctorInvoker().invoke(inputPath);
@@ -284,10 +263,9 @@ public void with_absolute_path_file_should_be_rendered() throws IOException {
}
@Test
- public void should_convert_to_subdirectories() throws IOException {
- File inputFile = classpath.getResource("relative/sub/test.adoc");
- File srcDir = inputFile.getParentFile().getParentFile();
- File toDir = new File(srcDir, "target");
+ void should_convert_to_subdirectories(@ClasspathResource("relative/sub/test.adoc") File relativePathDocument) throws IOException {
+ final File srcDir = relativePathDocument.getParentFile().getParentFile();
+ final File toDir = new File(srcDir, "target");
new AsciidoctorInvoker().invoke("-R", srcDir.getPath(), "-D", toDir.getPath(), srcDir.getAbsolutePath() + "/**/*.adoc");
@@ -301,5 +279,4 @@ private ByteArrayOutputStream redirectStdout() {
System.setOut(new PrintStream(output));
return output;
}
-
}
diff --git a/asciidoctorj-core/build.gradle b/asciidoctorj-core/build.gradle
index 6246205b8..b666ce03f 100644
--- a/asciidoctorj-core/build.gradle
+++ b/asciidoctorj-core/build.gradle
@@ -33,7 +33,7 @@ dependencies {
testImplementation "com.google.guava:guava:$guavaVersion"
testImplementation "org.jsoup:jsoup:$jsoupVersion"
testImplementation "io.netty:netty-all:$nettyVersion"
- testImplementation project(':asciidoctorj-arquillian-extension')
+ testImplementation project(':asciidoctorj-test-support')
compileOnly "org.osgi:osgi.annotation:$osgiVersion"
}
@@ -138,6 +138,3 @@ task pollutedTest(type: Test) {
}
test.dependsOn pollutedTest
-
-
-
diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy
index b1b18a119..862a643c9 100644
--- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy
+++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy
@@ -1,7 +1,7 @@
package org.asciidoctor
import org.asciidoctor.jruby.internal.JRubyAsciidoctor
-import org.asciidoctor.util.ClasspathHelper
+import org.asciidoctor.test.extension.ClasspathHelper
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
@@ -9,15 +9,10 @@ import spock.lang.Specification
class WhenSlimTemplatesAreUsed extends Specification {
- ClasspathHelper classpath = new ClasspathHelper()
-
- def setup() {
- classpath = new ClasspathHelper()
- classpath.classloader = WhenSlimTemplatesAreUsed
- }
-
Asciidoctor asciidoctor = JRubyAsciidoctor.create()
+ ClasspathHelper classpath = new ClasspathHelper(WhenSlimTemplatesAreUsed)
+
def 'the slim paragraph template should be used when rendering a document inline'() {
given:
Options options = Options.builder()
diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy
index 45c5e14db..ff694bfed 100644
--- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy
+++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy
@@ -3,7 +3,7 @@ package org.asciidoctor.extension
import org.asciidoctor.Asciidoctor
import org.asciidoctor.Options
import org.asciidoctor.SafeMode
-import org.asciidoctor.util.ClasspathHelper
+import org.asciidoctor.test.extension.ClasspathHelper
import org.asciidoctor.util.TestHttpServer
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
@@ -36,8 +36,7 @@ githubcontributors::asciidoctor/asciidoctorj[]
def setup() {
asciidoctor = Asciidoctor.Factory.create()
- classpathResources = new ClasspathHelper()
- classpathResources.classloader = WhenABlockMacroProcessorCreatesATable
+ classpathResources = new ClasspathHelper(WhenABlockMacroProcessorCreatesATable)
TestHttpServer.start(['http://api.github.com/repos/asciidoctor/asciidoctorj/contributors': classpathResources.getResource('githubcontributors.json')])
}
diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenExtensionsAreRegisteredAsService.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenExtensionsAreRegisteredAsService.groovy
index a15c0db5b..1ee03d7bd 100644
--- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenExtensionsAreRegisteredAsService.groovy
+++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenExtensionsAreRegisteredAsService.groovy
@@ -3,7 +3,7 @@ package org.asciidoctor.extension
import org.asciidoctor.Asciidoctor
import org.asciidoctor.Options
import org.asciidoctor.SafeMode
-import org.asciidoctor.util.ClasspathHelper
+import org.asciidoctor.test.extension.ClasspathHelper
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
@@ -24,8 +24,7 @@ class WhenExtensionsAreRegisteredAsService extends Specification {
def setup() {
asciidoctor = Asciidoctor.Factory.create()
- classpath = new ClasspathHelper()
- classpath.classloader = WhenExtensionsAreRegisteredAsService
+ classpath = new ClasspathHelper(WhenExtensionsAreRegisteredAsService)
originalTCCL = Thread.currentThread().contextClassLoader
}
diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiated.java b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiated.java
index 0b95a9936..d95f43339 100644
--- a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiated.java
+++ b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiated.java
@@ -1,16 +1,16 @@
package org.asciidoctor;
import com.google.common.io.CharStreams;
-import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.jruby.AsciiDocDirectoryWalker;
import org.asciidoctor.jruby.internal.AsciidoctorCoreException;
-import org.asciidoctor.util.ClasspathResources;
+import org.asciidoctor.test.AsciidoctorInstance;
+import org.asciidoctor.test.ClasspathResource;
+import org.asciidoctor.test.extension.AsciidoctorExtension;
+import org.asciidoctor.test.extension.ClasspathExtension;
import org.assertj.core.api.Assertions;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -18,12 +18,11 @@
import javax.xml.transform.Source;
import javax.xml.transform.dom.DOMSource;
import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.text.Format;
import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
import static org.asciidoctor.AttributesBuilder.attributes;
import static org.asciidoctor.OptionsBuilder.options;
@@ -32,19 +31,24 @@
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.collection.IsArrayWithSize.arrayWithSize;
import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.xmlmatchers.xpath.HasXPath.hasXPath;
-@RunWith(Arquillian.class)
+@ExtendWith({AsciidoctorExtension.class, ClasspathExtension.class})
public class WhenAnAsciidoctorClassIsInstantiated {
- @ArquillianResource
- private ClasspathResources classpath;
+ @AsciidoctorInstance
+ private Asciidoctor asciidoctor;
- @ArquillianResource
- private TemporaryFolder testFolder;
+ @ClasspathResource("src")
+ private File pathToWalk;
+
+ @ClasspathResource("rendersample.asciidoc")
+ private File renderSampleDocument;
+
+ @TempDir
+ private File tempFolder;
- @ArquillianResource(Unshared.class)
- private Asciidoctor asciidoctor;
@Test
public void should_accept_empty_string_as_empty_content_when_output_is_String() {
@@ -64,7 +68,7 @@ public void should_accept_null_string_as_empty_content_when_output_is_String() {
@Test
public void should_accept_null_string_as_empty_content_when_output_is_File() {
- File expectedFile = new File(testFolder.getRoot(), "expected_empty.html");
+ File expectedFile = new File(tempFolder, "expected_empty.html");
Options options = Options.builder()
.safe(SafeMode.UNSAFE)
.toFile(expectedFile)
@@ -88,10 +92,10 @@ public void should_fail_when_reader_is_null() {
}
@Test
- public void content_should_be_read_from_reader_and_written_to_writer() throws IOException, SAXException,
- ParserConfigurationException {
+ public void content_should_be_read_from_reader_and_written_to_writer()
+ throws IOException, SAXException, ParserConfigurationException {
- FileReader inputAsciidoctorFile = new FileReader(classpath.getResource("rendersample.asciidoc"));
+ FileReader inputAsciidoctorFile = new FileReader(renderSampleDocument);
StringWriter rendererWriter = new StringWriter();
asciidoctor.convert(inputAsciidoctorFile, rendererWriter, options().asMap());
@@ -104,20 +108,18 @@ public void content_should_be_read_from_reader_and_written_to_writer() throws IO
public void file_document_should_be_rendered_into_default_backend() throws IOException, SAXException,
ParserConfigurationException {
- String render_file = asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"),
- options().toFile(false).get());
+ Options options = Options.builder().toFile(false).build();
+ String render_file = asciidoctor.convertFile(renderSampleDocument, options);
assertRenderedFile(render_file);
-
}
@Test
public void file_document_should_be_rendered_into_current_directory_using_options_class() {
Options options = options().inPlace(true).get();
- File inputFile = classpath.getResource("rendersample.asciidoc");
- String renderContent = asciidoctor.convertFile(inputFile, options);
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
- File expectedFile = new File(inputFile.getParent(), "rendersample.html");
+ File expectedFile = new File(renderSampleDocument.getParent(), "rendersample.html");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -128,11 +130,10 @@ public void file_document_should_be_rendered_into_current_directory_using_option
@Test
public void file_document_should_be_rendered_into_current_directory() {
- File inputFile = classpath.getResource("rendersample.asciidoc");
- String renderContent = asciidoctor.convertFile(inputFile, options()
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options()
.inPlace(true).asMap());
- File expectedFile = new File(inputFile.getParent(), "rendersample.html");
+ File expectedFile = new File(renderSampleDocument.getParent(), "rendersample.html");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -143,11 +144,14 @@ public void file_document_should_be_rendered_into_current_directory() {
@Test
public void file_document_should_be_rendered_into_foreign_directory() {
- Map options = options().inPlace(false).safe(SafeMode.UNSAFE).toDir(testFolder.getRoot())
- .asMap();
- String renderContent = asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);
+ final Options options = Options.builder()
+ .inPlace(false)
+ .safe(SafeMode.UNSAFE)
+ .toDir(tempFolder)
+ .build();
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
- File expectedFile = new File(testFolder.getRoot(), "rendersample.html");
+ File expectedFile = new File(tempFolder, "rendersample.html");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -156,12 +160,16 @@ public void file_document_should_be_rendered_into_foreign_directory() {
}
@Test
- public void file_document_should_be_rendered_from_base_dir() throws IOException {
-
- File output = testFolder.newFolder("asciidoc", "docs");
- Options options = options().inPlace(false).baseDir(testFolder.getRoot())
- .toFile(new File("asciidoc/docs/rendersample.html")).get();
- String renderContent = asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);
+ public void file_document_should_be_rendered_from_base_dir() {
+
+ final File output = new File(tempFolder, "asciidoc/docs");
+ output.mkdirs();
+ final Options options = Options.builder()
+ .inPlace(false)
+ .baseDir(tempFolder)
+ .toFile(new File("asciidoc/docs/rendersample.html"))
+ .build();
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
File renderedFile = new File(output, "rendersample.html");
@@ -172,11 +180,11 @@ public void file_document_should_be_rendered_from_base_dir() throws IOException
@Test
public void file_document_should_be_rendered_into_foreign_directory_using_options_class() {
- Options options = options().inPlace(false).safe(SafeMode.UNSAFE).toDir(testFolder.getRoot()).get();
+ Options options = options().inPlace(false).safe(SafeMode.UNSAFE).toDir(tempFolder).get();
- String renderContent = asciidoctor.convertFile(classpath.getResource("rendersample.asciidoc"), options);
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
- File expectedFile = new File(testFolder.getRoot(), "rendersample.html");
+ File expectedFile = new File(tempFolder, "rendersample.html");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -188,10 +196,9 @@ public void docbook_document_should_be_rendered_into_current_directory() {
Map attributes = attributes().backend("docbook").asMap();
Map options = options().inPlace(true).attributes(attributes).asMap();
- File inputFile = classpath.getResource("rendersample.asciidoc");
- String renderContent = asciidoctor.convertFile(inputFile, options);
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
- File expectedFile = new File(inputFile.getParent(), "rendersample.xml");
+ File expectedFile = new File(renderSampleDocument.getParent(), "rendersample.xml");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -205,10 +212,9 @@ public void docbook_document_should_be_rendered_into_current_directory_using_opt
Attributes attributes = attributes().backend("docbook").get();
Options options = options().inPlace(true).attributes(attributes).get();
- File inputFile = classpath.getResource("rendersample.asciidoc");
- String renderContent = asciidoctor.convertFile(inputFile, options);
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
- File expectedFile = new File(inputFile.getParent(), "rendersample.xml");
+ File expectedFile = new File(renderSampleDocument.getParent(), "rendersample.xml");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -221,10 +227,9 @@ public void docbook_document_should_be_rendered_into_current_directory_using_opt
Options options = options().inPlace(true).backend("docbook").get();
- File inputFile = classpath.getResource("rendersample.asciidoc");
- String renderContent = asciidoctor.convertFile(inputFile, options);
+ String renderContent = asciidoctor.convertFile(renderSampleDocument, options);
- File expectedFile = new File(inputFile.getParent(), "rendersample.xml");
+ File expectedFile = new File(renderSampleDocument.getParent(), "rendersample.xml");
assertThat(expectedFile.exists(), is(true));
assertThat(renderContent, is(nullValue()));
@@ -233,10 +238,9 @@ public void docbook_document_should_be_rendered_into_current_directory_using_opt
}
@Test
- public void string_content_with_custom_date_should_be_rendered() throws IOException, SAXException,
- ParserConfigurationException {
-
- InputStream content = new FileInputStream(classpath.getResource("documentwithdate.asciidoc"));
+ public void string_content_with_custom_date_should_be_rendered(
+ @ClasspathResource("documentwithdate.asciidoc") Path documentWithDate)
+ throws IOException, SAXException, ParserConfigurationException {
Calendar customDate = Calendar.getInstance();
customDate.set(Calendar.YEAR, 2012);
@@ -246,17 +250,16 @@ public void string_content_with_custom_date_should_be_rendered() throws IOExcept
Map attributes = attributes().localDate(customDate.getTime()).asMap();
Map options = options().attributes(attributes).asMap();
- String render_file = asciidoctor.convert(toString(content), options);
+ String render_file = asciidoctor.convert(Files.readString(documentWithDate), options);
assertRenderedLocalDateContent(render_file, "2012-12-05.");
}
@Test
- public void string_content_with_custom_time_should_be_rendered() throws IOException, SAXException,
+ public void string_content_with_custom_time_should_be_rendered(
+ @ClasspathResource("documentwithtime.asciidoc") Path documentWithDate) throws IOException, SAXException,
ParserConfigurationException {
- InputStream content = new FileInputStream(classpath.getResource("documentwithtime.asciidoc"));
-
Calendar customTime = Calendar.getInstance();
customTime.set(Calendar.HOUR_OF_DAY, 23);
customTime.set(Calendar.MINUTE, 15);
@@ -265,7 +268,7 @@ public void string_content_with_custom_time_should_be_rendered() throws IOExcept
Map attributes = attributes().localTime(customTime.getTime()).asMap();
Map options = options().attributes(attributes).asMap();
- String render_file = asciidoctor.convert(toString(content), options);
+ String render_file = asciidoctor.convert(Files.readString(documentWithDate), options);
Format TIME_FORMAT = new SimpleDateFormat("HH:mm:ss z");
@@ -277,8 +280,7 @@ public void string_content_with_custom_time_should_be_rendered() throws IOExcept
public void string_content_document_should_be_rendered_into_default_backend() throws IOException, SAXException,
ParserConfigurationException {
- InputStream content = new FileInputStream(classpath.getResource("rendersample.asciidoc"));
- String render_file = asciidoctor.convert(toString(content), new HashMap());
+ String render_file = asciidoctor.convert(Files.readString(renderSampleDocument.toPath()), new HashMap<>());
assertRenderedFile(render_file);
}
@@ -287,19 +289,21 @@ public void string_content_document_should_be_rendered_into_default_backend() th
public void all_files_from_a_collection_should_be_rendered_into_an_array() {
String[] allRenderedFiles = asciidoctor.convertFiles(
- Arrays.asList(classpath.getResource("rendersample.asciidoc")), options().toFile(false).get());
+ List.of(renderSampleDocument), options().toFile(false).get());
assertThat(allRenderedFiles, is(arrayWithSize(1)));
-
}
@Test
public void all_files_from_a_collection_should_be_rendered_into_files_and_not_in_array() {
- Map options = options().inPlace(false).safe(SafeMode.UNSAFE).toDir(testFolder.getRoot())
- .asMap();
+ Options options = Options.builder()
+ .inPlace(false)
+ .safe(SafeMode.UNSAFE)
+ .toDir(tempFolder)
+ .build();
String[] allRenderedFiles = asciidoctor.convertFiles(
- Arrays.asList(classpath.getResource("rendersample.asciidoc")), options);
+ Arrays.asList(renderSampleDocument), options);
assertThat(allRenderedFiles, is(arrayWithSize(0)));
}
@@ -307,11 +311,9 @@ public void all_files_from_a_collection_should_be_rendered_into_files_and_not_in
@Test
public void all_files_from_directory_and_subdirectories_should_be_rendered_into_an_array() {
- File pathToWalk = classpath.getResource("src");
-
- String[] allRenderedFiles = asciidoctor.convertDirectory(new AsciiDocDirectoryWalker(
- pathToWalk.getPath()),
- options().toFile(false).get());
+ String[] allRenderedFiles = asciidoctor.convertDirectory(
+ new AsciiDocDirectoryWalker(pathToWalk.getPath()),
+ Options.builder().toFile(false).build());
assertThat(allRenderedFiles, is(arrayWithSize(4)));
}
@@ -319,10 +321,11 @@ public void all_files_from_directory_and_subdirectories_should_be_rendered_into_
@Test
public void all_files_from_directory_and_subdirectories_should_be_rendered_into_files_and_not_in_array() {
- File pathToWalk = classpath.getResource("src");
- Map options = options().inPlace(false).safe(SafeMode.UNSAFE).toDir(testFolder.getRoot())
- .asMap();
-
+ final Options options = Options.builder()
+ .inPlace(false)
+ .safe(SafeMode.UNSAFE)
+ .toDir(tempFolder)
+ .build();
String[] allRenderedFiles = asciidoctor.convertDirectory(
new AsciiDocDirectoryWalker(pathToWalk.getAbsolutePath()),
options);
@@ -330,12 +333,15 @@ public void all_files_from_directory_and_subdirectories_should_be_rendered_into_
}
- @Test(expected = AsciidoctorCoreException.class)
+ @Test
public void an_exception_should_be_thrown_if_backend_cannot_be_resolved() {
- Options options = options().inPlace(true).backend("mybackend").get();
-
- File inputFile = classpath.getResource("rendersample.asciidoc");
- asciidoctor.convertFile(inputFile, options);
+ assertThrows(AsciidoctorCoreException.class, () -> {
+ final Options options = Options.builder()
+ .inPlace(true)
+ .backend("mybackend")
+ .build();
+ asciidoctor.convertFile(renderSampleDocument, options);
+ });
}
private void assertRenderedLocalDateContent(String render_content, String contentDateOrTime) throws IOException,
diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorJInstanceIsRequired.java b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorJInstanceIsRequired.java
index bf54985a3..2bb1b850e 100644
--- a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorJInstanceIsRequired.java
+++ b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorJInstanceIsRequired.java
@@ -1,23 +1,23 @@
package org.asciidoctor;
import org.asciidoctor.jruby.AsciidoctorJRuby;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThat;
public class WhenAnAsciidoctorJInstanceIsRequired {
- private static final String DOC = "[yell]\nHello World";
+ private static final String DOC = "[yell]\nHello World";
- @Test
- public void shouldUnwrapAsciidoctorInstanceAndRegisterRubyExtension() {
- AsciidoctorJRuby asciidoctorj = Asciidoctor.Factory.create().unwrap(AsciidoctorJRuby.class);
- asciidoctorj.rubyExtensionRegistry().loadClass(getClass().getResourceAsStream("/ruby-extensions/YellRubyBlock.rb")).block("yell", "YellRubyBlock");
+ @Test
+ public void shouldUnwrapAsciidoctorInstanceAndRegisterRubyExtension() {
+ AsciidoctorJRuby asciidoctorj = Asciidoctor.Factory.create().unwrap(AsciidoctorJRuby.class);
+ asciidoctorj.rubyExtensionRegistry().loadClass(getClass().getResourceAsStream("/ruby-extensions/YellRubyBlock.rb")).block("yell", "YellRubyBlock");
- String html = asciidoctorj.convert(DOC, OptionsBuilder.options().standalone(false));
+ String html = asciidoctorj.convert(DOC, OptionsBuilder.options().standalone(false));
- assertThat(html, containsString("HELLO WORLD"));
- }
+ assertThat(html, containsString("HELLO WORLD"));
+ }
}
diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciiDocIsLoadedToDocument.java b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciiDocIsLoadedToDocument.java
index d2b56e015..8c8ddd994 100644
--- a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciiDocIsLoadedToDocument.java
+++ b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciiDocIsLoadedToDocument.java
@@ -1,24 +1,24 @@
package org.asciidoctor;
-import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.ast.*;
-import org.asciidoctor.jruby.internal.IOUtils;
-import org.asciidoctor.util.ClasspathResources;
+import org.asciidoctor.test.AsciidoctorInstance;
+import org.asciidoctor.test.ClasspathResource;
+import org.asciidoctor.test.extension.AsciidoctorExtension;
+import org.asciidoctor.test.extension.ClasspathExtension;
import org.assertj.core.api.Assertions;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.test.api.ArquillianResource;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.Collections.emptyMap;
import static java.util.stream.Collectors.toList;
+import static org.asciidoctor.test.AsciidoctorInstance.InstanceScope.PER_METHOD;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -27,7 +27,7 @@
import static org.hamcrest.collection.IsMapContaining.hasKey;
-@RunWith(Arquillian.class)
+@ExtendWith({AsciidoctorExtension.class, ClasspathExtension.class})
public class WhenAsciiDocIsLoadedToDocument {
private static final String DOCUMENT = "= Document Title\n" +
@@ -66,11 +66,9 @@ public class WhenAsciiDocIsLoadedToDocument {
"\n" +
"content";
- @ArquillianResource(Unshared.class)
+ @AsciidoctorInstance(scope = PER_METHOD)
private Asciidoctor asciidoctor;
- @ArquillianResource
- private ClasspathResources classpath = new ClasspathResources();
@Test
public void should_return_empty_sources_when_document_is_null() {
@@ -164,11 +162,12 @@ public void should_return_options_from_parsed_string_when_passed_as_options_obje
}
@Test
- public void should_return_options_from_parsed_file_when_passed_as_options_object() {
+ public void should_return_options_from_parsed_file_when_passed_as_options_object(
+ @ClasspathResource("sourcelocation.adoc") File resource) {
+
Options options = Options.builder()
.compact(true)
.build();
- File resource = classpath.getResource("sourcelocation.adoc");
Document document = asciidoctor.loadFile(resource, options);
Map