From 082011784407f4029a94ebc5e886a61ec82b8f0b Mon Sep 17 00:00:00 2001 From: Abel Salgado Romero Date: Sat, 22 Apr 2023 23:15:45 +0200 Subject: [PATCH] Set Junit5 as default test engine * Remove use of Arquillian Sputnik components: not compatible * Restrict codenarc configuration to modules using Spock * Bump codenarc to latest * Bump Groovy to v3.0.x * Fix deprecated 'defaultVersion' use of jruby Gradle plugin * CI: Add documentation reports upload in CI * CI: Fix upload reports naming overlap * Disable cleanup for @TempDir to fix Windows tests failing unable to delete --- .github/workflows/continuous-integration.yaml | 33 +++++- CHANGELOG.adoc | 1 + asciidoctorj-cli/build.gradle | 4 +- .../cli/WhenAsciidoctorAPICallIsCalled.java | 2 +- .../cli/WhenAsciidoctorIsCalledUsingCli.java | 46 +++++--- asciidoctorj-core/build.gradle | 14 +-- ...henADocumentContainsADefinitionList.groovy | 9 +- ...enADocumentContainsNumberedSections.groovy | 7 +- .../WhenADocumentIsRenderedToStream.groovy | 8 +- .../org/asciidoctor/WhenATableIsLoaded.groovy | 31 ++--- .../WhenSlimTemplatesAreUsed.groovy | 19 +-- .../WhenSubstitutionsAreUsed.groovy | 9 +- .../WhenTheSourceShouldBeAccessed.groovy | 8 +- .../CatalogOfRefsAreAvailable.groovy | 16 +-- .../converter/TableConverterTest.groovy | 11 +- .../converter/WhenFootnotesAreUsed.groovy | 7 +- .../WhenWritingConverterIsRegistered.groovy | 21 ++-- ...henABlockMacroProcessorCreatesAList.groovy | 7 +- ...ABlockMacroProcessorCreatesASection.groovy | 7 +- ...enABlockMacroProcessorCreatesATable.groovy | 75 ++++++------ ...eatesABlockThatATreeProcessorVisits.groovy | 76 ++++++------ .../WhenABlockShouldBeDuplicated.groovy | 10 +- .../WhenAJavaExtensionChecksAttributes.groovy | 7 +- ...ionGroupIsRegisteredWithAnnotations.groovy | 7 +- ...xtensionIsRegisteredWithAnnotations.groovy | 7 +- .../WhenAJavaExtensionUsesCounters.groovy | 7 +- .../WhenAPreprocessorIsRegistered.groovy | 9 +- ...APreprocessorSetsTheSourceMapOption.groovy | 8 +- .../WhenATreeProcessorCreatesNodes.groovy | 7 +- .../WhenATreeProcessorWorksOnTables.groovy | 7 +- .../WhenAnExtensionAppendsChildBlocks.groovy | 15 +-- ...InlineMacroProcessorProcessesATable.groovy | 7 +- ...henExtensionsAreRegisteredAsService.groovy | 28 ++--- ...AttributesMapDecoratorSpecification.groovy | 7 +- ...CoderayAdapterIsImplementedInGroovy.groovy | 7 +- ...lightjsAdapterIsImplementedInGroovy.groovy | 8 +- ...outingSyntaxHighlighterIsRegistered.groovy | 7 +- ...erSideSyntaxHighlighterIsRegistered.groovy | 7 +- ...erThatWritesStylesheetsIsRegistered.groovy | 10 +- ...nstantiatedInAnEnvironmentWithGemPath.java | 8 +- .../org/asciidoctor/categories/Polluted.java | 16 ++- .../extension/ArrowsAndBoxesExtension.java | 4 - asciidoctorj-distribution/build.gradle | 5 +- .../WhenAPdfDocumentIsRenderedToStream.groovy | 110 ------------------ .../diagram/WhenDitaaDiagramIsRendered.groovy | 109 ----------------- .../WhenAPdfDocumentIsRenderedToStream.java | 110 ++++++++++++++++++ .../org/asciidoctor/WhenBackendIsPdf.java | 59 +++++----- .../asciidoctor/WhenBackendIsRevealJs.java | 24 ++-- .../WhenDitaaDiagramIsRendered.java | 89 ++++++++++++++ asciidoctorj-documentation/build.gradle | 10 +- .../AsciidoctorInterface.java | 5 +- .../integrationguide/OptionsTest.java | 36 +++--- .../converter/TextConverterTest.java | 28 ++--- .../extension/ASTShowcase.java | 28 +++-- .../extension/CommentPreprocessorTest.java | 23 ++-- .../ContextMenuInlineMacroProcessorTest.java | 12 +- .../CopyrightFooterPostprocessorTest.java | 22 ++-- .../GistBlockMacroProcessorTest.java | 24 ++-- .../ImageInlineMacroProcessorTest.java | 20 ++-- .../IssueInlineMacroProcessorTest.java | 23 ++-- .../KeyboardInlineMacroProcessorTest.java | 22 ++-- .../LoggingBlockMacroProcessorTest.java | 25 ++-- .../extension/LsIncludeProcessorTest.java | 23 ++-- .../extension/RobotsDocinfoProcessorTest.java | 23 ++-- .../TerminalCommandTreeprocessorTest.java | 39 ++++--- .../extension/YellBlockProcessorTest.java | 24 ++-- .../HighlightJsHighlighterTest.java | 34 +++--- .../syntaxhighlighter/OrderTest.java | 60 +++++----- .../PrismJsHighlighterTest.java | 33 +++--- .../threeparams/HighlightJsHighlighter.java | 13 ++- .../build.gradle | 11 +- .../springboot-app/build.gradle | 4 - .../it/springboot/SpringBootTest.java | 7 +- asciidoctorj-test-support/build.gradle | 2 +- .../org/asciidoctor/util/ClasspathHelper.java | 11 +- .../asciidoctor/util/ClasspathResources.java | 7 +- .../build.gradle | 14 +-- .../asciidoctor/WildflyIntegrationTest.java | 21 ++-- .../org/asciidoctor/categories/Wildfly.java | 4 - build.gradle | 77 ++++++++---- 80 files changed, 847 insertions(+), 948 deletions(-) delete mode 100644 asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenAPdfDocumentIsRenderedToStream.groovy delete mode 100644 asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.groovy create mode 100644 asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenAPdfDocumentIsRenderedToStream.java create mode 100644 asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenDitaaDiagramIsRendered.java delete mode 100644 asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/categories/Wildfly.java diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 31e5680ee..ba89a5a51 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -14,7 +14,7 @@ jobs: name: Build strategy: fail-fast: false - max-parallel: 4 + max-parallel: 6 matrix: java: - '11' @@ -39,7 +39,6 @@ jobs: ./gradlew -S -Pskip.signing check build-windows: name: Build on Windows - runs-on: windows-latest strategy: fail-fast: false max-parallel: 3 @@ -48,6 +47,9 @@ jobs: - '11' - '17' - '19' + os: + - windows-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 with: @@ -64,6 +66,24 @@ jobs: shell: cmd run: | gradlew.bat -i -S check + - name: Upload asciidoctorj-core reports + uses: actions/upload-artifact@v3 + env: + os_name: ${{ matrix.os }} + java_version: ${{ matrix.java }} + if: always() + with: + name: asciidoctorj-core-reports-${{ env.os_name }}-${{ env.java_version }} + path: asciidoctorj-core/build/reports/* + - name: Upload asciidoctorj-documentation reports + uses: actions/upload-artifact@v3 + if: always() + env: + os_name: ${{ matrix.os }} + java_version: ${{ matrix.java }} + with: + name: asciidoctorj-documentation-reports-${{ env.os_name }}-${{ env.java_version }} + path: asciidoctorj-documentation/build/reports/* test-asciidoctor-upstream: name: Test Asciidoctor Upstream needs: @@ -88,16 +108,19 @@ jobs: - name: Setup Java uses: s4u/setup-maven-action@v1.7.0 with: - distribution: temurin + java-distribution: temurin java-version: ${{ matrix.java }} maven-version: ${{ matrix.maven }} - name: Upstream Build run: | unset GEM_PATH GEM_HOME JRUBY_OPTS ./ci/test-asciidoctor-upstream.sh - - name: Upload reports + - name: Upload asciidoctorj-core reports uses: actions/upload-artifact@v3 if: always() + env: + os_name: ${{ matrix.os }} + java_version: ${{ matrix.java }} with: - name: asciidoctorj-core-reports + name: asciidoctorj-core-reports-upstream-${{ env.os_name }}-${{ env.java_version }} path: asciidoctorj-core/build/reports/* diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ec4ee8b7f..61b5e5a15 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -52,6 +52,7 @@ Build Improvement:: * Run tests on Java 19 (#1563) * Fix upstream tests forcing SNAPSHOT on Asciidoctor gem installation (#1123) (@abelsromero) * Fix upstream build removing the explicit plugin repository (#1131) +* Set JUnit5 as default test engine (#1186) (@abelsromero) == 2.5.4 (2022-06-30) diff --git a/asciidoctorj-cli/build.gradle b/asciidoctorj-cli/build.gradle index 162fb65e8..9a869d6bd 100644 --- a/asciidoctorj-cli/build.gradle +++ b/asciidoctorj-cli/build.gradle @@ -6,7 +6,9 @@ dependencies { api project(':asciidoctorj') implementation "com.beust:jcommander:$jcommanderVersion" - testImplementation project(':asciidoctorj-arquillian-extension') + testImplementation (project(':asciidoctorj-test-support')) { + exclude group: 'junit', module: 'junit' + } testImplementation "org.jsoup:jsoup:$jsoupVersion" } diff --git a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorAPICallIsCalled.java b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorAPICallIsCalled.java index 2d8b027ed..b9299779e 100644 --- a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorAPICallIsCalled.java +++ b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorAPICallIsCalled.java @@ -2,7 +2,7 @@ import com.beust.jcommander.JCommander; import org.asciidoctor.SafeMode; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.nio.file.Path; 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 cf60a77ac..c4f83a798 100644 --- a/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java +++ b/asciidoctorj-cli/src/test/java/org/asciidoctor/cli/WhenAsciidoctorIsCalledUsingCli.java @@ -1,28 +1,27 @@ package org.asciidoctor.cli; import org.asciidoctor.cli.jruby.AsciidoctorInvoker; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; +import org.asciidoctor.util.ClasspathHelper; +import org.assertj.core.api.Assertions; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.PrintStream; +import static org.assertj.core.api.Assertions.catchThrowable; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.StringStartsWith.startsWith; -@RunWith(Arquillian.class) public class WhenAsciidoctorIsCalledUsingCli { private static final String SAMPLE_FILE = "rendersample.asciidoc"; @@ -31,14 +30,19 @@ public class WhenAsciidoctorIsCalledUsingCli { private static final String SOURCE_EXTENSION_PATTERN = "\\.asciidoc$"; - @ArquillianResource - private ClasspathResources classpath; + private static ClasspathHelper classpath; - @ArquillianResource - public TemporaryFolder temporaryFolder; + @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); @@ -116,7 +120,7 @@ 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.getRoot(); + File outputDirectory = temporaryFolder; File inputFile = classpath.getResource(SAMPLE_FILE); String inputPath = inputFile.getPath().substring(pwd.length() + 1); @@ -127,9 +131,12 @@ public void destination_dir_should_render_files_to_ouput_directory() throws IOEx } - @Test(expected = IllegalArgumentException.class) - public void empty_input_file_name_should_throw_an_exception() throws IOException { - new AsciidoctorInvoker().invoke(""); + @Test + public void empty_input_file_name_should_throw_an_exception() { + Throwable throwable = catchThrowable(() -> new AsciidoctorInvoker().invoke("")); + + Assertions.assertThat(throwable) + .isInstanceOf(IllegalArgumentException.class); } @Test @@ -145,9 +152,12 @@ public void version_flag_should_print_version_and_exit() throws IOException { assertThat(os.toString(), startsWith("Asciidoctor")); } - @Test(expected = IllegalArgumentException.class) - public void invalid_input_file_should_throw_an_exception() throws IOException { - new AsciidoctorInvoker().invoke("myunknown.adoc"); + @Test + public void invalid_input_file_should_throw_an_exception() { + Throwable throwable = catchThrowable(() -> new AsciidoctorInvoker().invoke("myunknown.adoc")); + + Assertions.assertThat(throwable) + .isInstanceOf(IllegalArgumentException.class); } @Test diff --git a/asciidoctorj-core/build.gradle b/asciidoctorj-core/build.gradle index c3c2bded8..57daa64bf 100644 --- a/asciidoctorj-core/build.gradle +++ b/asciidoctorj-core/build.gradle @@ -58,7 +58,7 @@ tasks.eclipse.dependsOn jrubyPrepare jruby { defaultRepositories = false - defaultVersion = jrubyVersion + jrubyVersion = jrubyVersion // TODO I'd like to be able to customize the name of the gemInstallDir } @@ -86,10 +86,6 @@ javadoc { source(project(':asciidoctorj-api').sourceSets.main.allJava) } -//jruby { -// execVersion = '1.7.20' -//} - jar { bnd( ('Bundle-Name'): 'asciidoctorj', @@ -99,8 +95,8 @@ jar { } test { - useJUnit { - excludeCategories 'org.asciidoctor.categories.Polluted' + useJUnitPlatform() { + excludeTags("polluted") } } @@ -119,8 +115,8 @@ version.asciidoctor: $asciidoctorGemVersion jar.dependsOn createVersionFile task pollutedTest(type: Test) { - useJUnit { - includeCategories 'org.asciidoctor.categories.Polluted' + useJUnitPlatform() { + includeTags 'polluted' } forkEvery = 10 minHeapSize = '128m' diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsADefinitionList.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsADefinitionList.groovy index 936bede15..b642aba8c 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsADefinitionList.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsADefinitionList.groovy @@ -7,19 +7,14 @@ import org.asciidoctor.ast.Document import org.asciidoctor.ast.ListItem import org.asciidoctor.converter.StringConverter import org.asciidoctor.extension.Treeprocessor -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenADocumentContainsADefinitionList extends Specification { static final String TAG_DD = 'dd' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def "the definition list should be loaded"() { @@ -170,6 +165,6 @@ Item A:: then: org.jsoup.nodes.Document htmlDoc = Jsoup.parse(result) htmlDoc.getElementsByTag(TAG_DD).size() == 1 - htmlDoc.getElementsByTag(TAG_DD)[0].text() == newDescription + htmlDoc.getElementsByTag(TAG_DD)[0].text() == newDescription } } diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsNumberedSections.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsNumberedSections.groovy index b8d2b797b..93ac9d681 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsNumberedSections.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentContainsNumberedSections.groovy @@ -1,16 +1,11 @@ package org.asciidoctor import org.asciidoctor.ast.Section -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenADocumentContainsNumberedSections extends Specification { - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def "for appendix the section numeral should be a letter"() { given: diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentIsRenderedToStream.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentIsRenderedToStream.groovy index 170fafce3..26052c4d3 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentIsRenderedToStream.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenADocumentIsRenderedToStream.groovy @@ -5,20 +5,15 @@ import org.asciidoctor.ast.ContentNode import org.asciidoctor.ast.Document import org.asciidoctor.ast.Section import org.asciidoctor.converter.StringConverter -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenADocumentIsRenderedToStream extends Specification { public static final String HTML5_BACKEND = 'html5' public static final String HELLO_WORLD = 'Hello World' public static final String EMPTY_STRING = '' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() static final String TEST_DOC = '''= Test @@ -106,6 +101,7 @@ Hello, World! TestConverter(String backend, Map opts) { super(backend, opts) } + @Override String convert(ContentNode node, String transform, Map opts) { if (transform == null) { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenATableIsLoaded.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenATableIsLoaded.groovy index 51f05dd10..8f3f13bf6 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenATableIsLoaded.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenATableIsLoaded.groovy @@ -2,19 +2,12 @@ package org.asciidoctor import org.asciidoctor.ast.Document import org.asciidoctor.ast.Table -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jruby.exceptions.RaiseException -import org.junit.runner.RunWith - import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenATableIsLoaded extends Specification { - - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def "colspan greater 1 should be passed correctly to the nodes"() { @@ -57,10 +50,10 @@ class WhenATableIsLoaded extends Specification { tableNode.body[0].cells[0].colspan == 0 } - def "asking a table cell for its inner document when it does not have one should return null"() { + def "asking a table cell for its inner document when it does not have one should return null"() { - given: - String document = '''= Test document + given: + String document = '''= Test document [cols="40,60"] |=== @@ -77,13 +70,13 @@ The second content cell |=== ''' - when: - Document documentNode = asciidoctor.load(document, OptionsBuilder.options().standalone(false).asMap()) - Table tableNode = documentNode.blocks[0] + when: + Document documentNode = asciidoctor.load(document, OptionsBuilder.options().standalone(false).asMap()) + Table tableNode = documentNode.blocks[0] - then: - tableNode.header[0].cells[0].innerDocument == null - tableNode.header[0].cells[1].innerDocument == null - notThrown(RaiseException) - } + then: + tableNode.header[0].cells[0].innerDocument == null + tableNode.header[0].cells[1].innerDocument == null + notThrown(RaiseException) + } } diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy index 6ddebfb59..b1b18a119 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSlimTemplatesAreUsed.groovy @@ -1,25 +1,30 @@ package org.asciidoctor import org.asciidoctor.jruby.internal.JRubyAsciidoctor -import org.asciidoctor.util.ClasspathResources +import org.asciidoctor.util.ClasspathHelper import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import org.junit.Rule import spock.lang.Specification -import static org.asciidoctor.OptionsBuilder.options - class WhenSlimTemplatesAreUsed extends Specification { - @Rule - ClasspathResources classpath = new ClasspathResources() + ClasspathHelper classpath = new ClasspathHelper() + + def setup() { + classpath = new ClasspathHelper() + classpath.classloader = WhenSlimTemplatesAreUsed + } Asciidoctor asciidoctor = JRubyAsciidoctor.create() def 'the slim paragraph template should be used when rendering a document inline'() { given: - Options options = options().templateDir(classpath.getResource('src/custom-backends/slim')).toFile(false).standalone(false).get() + Options options = Options.builder() + .templateDirs(classpath.getResource('src/custom-backends/slim')) + .toFile(false) + .standalone(false) + .build() String sourceDocument = ''' = Hello World diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSubstitutionsAreUsed.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSubstitutionsAreUsed.groovy index 3141fb8ae..523fcd1fb 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSubstitutionsAreUsed.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenSubstitutionsAreUsed.groovy @@ -3,10 +3,8 @@ package org.asciidoctor import org.asciidoctor.ast.Block import org.asciidoctor.ast.Document import org.asciidoctor.extension.Treeprocessor -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification + import static org.asciidoctor.ast.StructuralNode.SUBSTITUTION_SPECIAL_CHARACTERS import static org.asciidoctor.ast.StructuralNode.SUBSTITUTION_QUOTES import static org.asciidoctor.ast.StructuralNode.SUBSTITUTION_ATTRIBUTES @@ -14,12 +12,9 @@ import static org.asciidoctor.ast.StructuralNode.SUBSTITUTION_REPLACEMENTS import static org.asciidoctor.ast.StructuralNode.SUBSTITUTION_MACROS import static org.asciidoctor.ast.StructuralNode.SUBSTITUTION_POST_REPLACEMENTS - -@RunWith(ArquillianSputnik) class WhenSubstitutionsAreUsed extends Specification { - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def 'a node should return its substitutions'() { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheSourceShouldBeAccessed.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheSourceShouldBeAccessed.groovy index 7f605a81d..6cf68178a 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheSourceShouldBeAccessed.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/WhenTheSourceShouldBeAccessed.groovy @@ -9,24 +9,20 @@ import org.asciidoctor.ast.List import org.asciidoctor.ast.ListItem import org.asciidoctor.ast.Table import org.asciidoctor.extension.Treeprocessor -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup -import org.junit.runner.RunWith import spock.lang.Specification /** * Tests that the unsubstituted text can be retrieved from nodes */ -@RunWith(ArquillianSputnik) class WhenTheSourceShouldBeAccessed extends Specification { public static final String SOURCE = 'This paragraph should show {foo}' public static final String CONVERTED = 'This paragraph should show bar' public static final String P = 'p' public static final String TD = 'td' - @ArquillianResource - private Asciidoctor asciidoctor + + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def 'it should be possible to get the raw text from a paragraph'() { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/CatalogOfRefsAreAvailable.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/CatalogOfRefsAreAvailable.groovy index 4bac61bb4..b3915b329 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/CatalogOfRefsAreAvailable.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/CatalogOfRefsAreAvailable.groovy @@ -6,9 +6,6 @@ import org.asciidoctor.ast.ContentNode import org.asciidoctor.ast.Document import org.asciidoctor.ast.StructuralNode import org.hamcrest.BaseMatcher -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification import static org.hamcrest.Matchers.contains @@ -19,17 +16,17 @@ import static org.junit.Assert.assertThat /** * Tests that refs can be accessed from converter. */ -@RunWith(ArquillianSputnik) class CatalogOfRefsAreAvailable extends Specification { + static final String CONVERTER_BACKEND = 'refs' static final String NODE_NAME_SECTION = 'section' static final String NODE_NAME_PARAGRAPH = 'paragraph' static final String NODE_NAME_ULIST = 'ulist' static final String NODE_NAME_INLINE_ANCHOR = 'inline_anchor' - @ArquillianResource - private Asciidoctor asciidoctor - private static Map refs + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() + + private static Map refs static class Converter extends StringConverter { Converter(String backend, Map opts) { @@ -40,13 +37,13 @@ class CatalogOfRefsAreAvailable extends Specification { * For this conversion test we do not care about the conversion result, * we simply want to to verify that refs are available and as expected. */ + @Override String convert(ContentNode node, String transform, Map opts) { if (node instanceof Document) { def doc = (Document) node refs = doc.catalog.refs - } - else if (node instanceof StructuralNode) { + } else if (node instanceof StructuralNode) { ((StructuralNode) node).content } } @@ -167,5 +164,4 @@ An [#${idInline}]*quoted text* ] as BaseMatcher> } - } diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/TableConverterTest.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/TableConverterTest.groovy index dd7e70b67..56702cd4e 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/TableConverterTest.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/TableConverterTest.groovy @@ -2,16 +2,11 @@ package org.asciidoctor.converter import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class TableConverterTest extends Specification { - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def "should convert a table with horizontal alignment"() { given: @@ -39,7 +34,7 @@ class TableConverterTest extends Specification { String content = asciidoctor.convert(document, OptionsBuilder.options().standalone(false).backend('tabletestconverter')) then: - content.readLines().collect {it - ~/\s+$/ } == '''HELLO TABLE + content.readLines().collect { it - ~/\s+$/ } == '''HELLO TABLE -- A chapter -- @@ -71,7 +66,7 @@ a| String content = asciidoctor.convert(document, OptionsBuilder.options().standalone(false).backend('tabletestconverter')) then: - content.readLines().collect {it - ~/\s+$/ } == '''HELLO ASCIIDOCTOR TABLE + content.readLines().collect { it - ~/\s+$/ } == '''HELLO ASCIIDOCTOR TABLE A HEADER |Second column'''.readLines() diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenFootnotesAreUsed.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenFootnotesAreUsed.groovy index 939981cb0..540057e6b 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenFootnotesAreUsed.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenFootnotesAreUsed.groovy @@ -7,9 +7,6 @@ import org.asciidoctor.ast.Document import org.asciidoctor.ast.Footnote import org.asciidoctor.ast.StructuralNode import org.asciidoctor.jruby.ast.impl.FootnoteImpl -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification import static org.hamcrest.Matchers.contains @@ -22,13 +19,11 @@ import static org.junit.Assert.assertThat * Note that it is a current limitation of asciidoctor that footnotes are not * available until after they have been converted for the document. */ -@RunWith(ArquillianSputnik) class WhenFootnotesAreUsed extends Specification { static final String CONVERTER_BACKEND = 'footnote' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static List footnotesBeforeConvert private static List footnotesAfterConvert diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenWritingConverterIsRegistered.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenWritingConverterIsRegistered.groovy index 1b38ee6c5..287ff6042 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenWritingConverterIsRegistered.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/converter/WhenWritingConverterIsRegistered.groovy @@ -3,24 +3,22 @@ package org.asciidoctor.converter import org.asciidoctor.Asciidoctor import org.asciidoctor.Options import org.asciidoctor.SafeMode -import org.asciidoctor.arquillian.api.Unshared import org.asciidoctor.converter.ObjectConverter.ObjectConverterResult -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.rules.TemporaryFolder -import org.junit.runner.RunWith import spock.lang.Specification +import spock.lang.TempDir -@RunWith(ArquillianSputnik) class WhenWritingConverterIsRegistered extends Specification { public static final String BACKEND_NAME_42 = '42' - @ArquillianResource(Unshared) private Asciidoctor asciidoctor - @ArquillianResource - private TemporaryFolder tmp + @TempDir + private File tmp + + def setup() { + asciidoctor = Asciidoctor.Factory.create() + } def cleanup() { WritingTextConverter.targetFile = null @@ -33,7 +31,7 @@ class WhenWritingConverterIsRegistered extends Specification { // Register as default converter asciidoctor.javaConverterRegistry().register(WritingTextConverter) - File file = tmp.newFile('target.txt') + File file = new File(tmp, 'target.txt') String document = '''== Hello @@ -82,7 +80,8 @@ World! ByteArrayOutputStream bout = new ByteArrayOutputStream() when: - ObjectConverterResult result = asciidoctor.convert(DONT_CARE_DOCUMENT, Options.builder().backend(BACKEND_NAME_42).toStream(bout).build(), ObjectConverterResult) + Options options = Options.builder().backend(BACKEND_NAME_42).toStream(bout).build() + ObjectConverterResult result = asciidoctor.convert(DONT_CARE_DOCUMENT, options, ObjectConverterResult) then: new String(bout.toByteArray()) == new ObjectConverterResult(ObjectConverter.FIXED_RESULT).toString() diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesAList.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesAList.groovy index 1856f1f10..b5563db0e 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesAList.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesAList.groovy @@ -3,14 +3,10 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenABlockMacroProcessorCreatesAList extends Specification { public static final String LISTMACRO_NAME = 'list' @@ -21,8 +17,7 @@ class WhenABlockMacroProcessorCreatesAList extends Specification { public static final String FIRST_ITEM = 'First item' public static final String SECOND_ITEM = 'Second item' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static final String DOCUMENT = ''' = Section Creation Test diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesASection.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesASection.groovy index 9fb9ea708..af0aca480 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesASection.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesASection.groovy @@ -3,14 +3,10 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenABlockMacroProcessorCreatesASection extends Specification { public static final String BLOCKMACRO_NAME = 'section' @@ -20,8 +16,7 @@ class WhenABlockMacroProcessorCreatesASection extends Specification { public static final String SECT1_SELECTOR = 'div.sect1' public static final String PARAGRAPH_SELECTOR = 'div.paragraph' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static final String DOCUMENT = ''' = Section Creation Test 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 e35adca22..45c5e14db 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy @@ -1,35 +1,30 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor -import org.asciidoctor.OptionsBuilder +import org.asciidoctor.Options import org.asciidoctor.SafeMode -import org.asciidoctor.util.ClasspathResources +import org.asciidoctor.util.ClasspathHelper import org.asciidoctor.util.TestHttpServer -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document -import org.junit.rules.TemporaryFolder -import org.junit.runner.RunWith import spock.lang.Specification +import spock.lang.TempDir -@RunWith(ArquillianSputnik) class WhenABlockMacroProcessorCreatesATable extends Specification { - public static final String FIRST_TD = 'td:first-child' + public static final String FIRST_TD = 'td:first-child' public static final String SECOND_TD = 'td:nth-child(2)' - public static final String THIRD_TD = 'td:nth-child(3)' - public static final String IMG_ELEMENT = 'img' + public static final String THIRD_TD = 'td:nth-child(3)' + public static final String IMG_ELEMENT = 'img' public static final String CONTRIBUTOR = 'bob' public static final String BLOCKMACRO_NAME = 'githubcontributors' public static final String AVATAR_URL_REGEXP = /https:\/\/avatars.githubusercontent.com\/u\/.*/ - @ArquillianResource private Asciidoctor asciidoctor - @ArquillianResource - private TemporaryFolder tmp + @TempDir + private File tempDir private static final String DOCUMENT = ''' = AsciidoctorJRuby contributors @@ -37,11 +32,13 @@ class WhenABlockMacroProcessorCreatesATable extends Specification { githubcontributors::asciidoctor/asciidoctorj[] ''' - @ArquillianResource - private ClasspathResources classpathResources + private ClasspathHelper classpathResources def setup() { - TestHttpServer.start(['http://api.github.com/repos/asciidoctor/asciidoctorj/contributors' : classpathResources.getResource('githubcontributors.json')]) + asciidoctor = Asciidoctor.Factory.create() + classpathResources = new ClasspathHelper() + classpathResources.classloader = WhenABlockMacroProcessorCreatesATable + TestHttpServer.start(['http://api.github.com/repos/asciidoctor/asciidoctorj/contributors': classpathResources.getResource('githubcontributors.json')]) } def cleanup() { @@ -49,15 +46,19 @@ githubcontributors::asciidoctor/asciidoctorj[] } def "the table should be rendered to html"() { - given: - asciidoctor.javaExtensionRegistry().blockMacro(BLOCKMACRO_NAME, GithubContributorsBlockMacro) - - File resultFile = tmp.newFile('result.html') + File resultFile = new File(tempDir, 'result.html') when: - asciidoctor.convert(DOCUMENT, OptionsBuilder.options().safe(SafeMode.SAFE).inPlace(false).baseDir(tmp.getRoot()).toDir(tmp.getRoot()).toFile(resultFile)) + def options = Options.builder() + .safe(SafeMode.SAFE) + .inPlace(false) + .baseDir(tempDir) + .toDir(tempDir) + .toFile(resultFile) + .build() + asciidoctor.convert(DOCUMENT, options) then: Document htmlDocument = Jsoup.parse(resultFile, 'UTF-8') @@ -70,29 +71,27 @@ githubcontributors::asciidoctor/asciidoctorj[] htmlDocument.select(SECOND_TD).size() == htmlDocument.select(SECOND_TD) != 0 htmlDocument.select(SECOND_TD).size() != 0 - htmlDocument.select(SECOND_TD).every { tdElement -> tdElement.hasClass('halign-left')} - htmlDocument.select(THIRD_TD).every { tdElement -> tdElement.hasClass('halign-center')} + htmlDocument.select(SECOND_TD).every { tdElement -> tdElement.hasClass('halign-left') } + htmlDocument.select(THIRD_TD).every { tdElement -> tdElement.hasClass('halign-center') } htmlDocument.select(SECOND_TD).find { tdElement -> tdElement.text() == CONTRIBUTOR } != null } def "the table should be rendered to docbook"() { - given: - asciidoctor.javaExtensionRegistry().blockMacro(BLOCKMACRO_NAME, GithubContributorsBlockMacro) - - File resultFile = tmp.newFile('result.db') + File resultFile = new File(tempDir, 'result.db') when: - asciidoctor.convert(DOCUMENT, - OptionsBuilder.options() - .backend('docbook5') - .safe(SafeMode.SAFE) - .inPlace(false) - .baseDir(tmp.getRoot()) - .toDir(tmp.getRoot()) - .toFile(resultFile)) + def options = Options.builder() + .backend('docbook5') + .safe(SafeMode.SAFE) + .inPlace(false) + .baseDir(tempDir) + .toDir(tempDir) + .toFile(resultFile) + .build() + asciidoctor.convert(DOCUMENT, options) then: def rootNode = new XmlSlurper().parse(resultFile) @@ -100,11 +99,11 @@ githubcontributors::asciidoctor/asciidoctorj[] row.entry[1].text() == CONTRIBUTOR } rootNode.table.tgroup.tbody.'*'.size() > 0 - rootNode.table.tgroup.tbody.'*'.every {row -> + rootNode.table.tgroup.tbody.'*'.every { row -> row.entry[0].informalfigure.mediaobject.imageobject.imagedata.@fileref =~ AVATAR_URL_REGEXP } - rootNode.table.tgroup.tbody.'*'.every {row -> row.entry[1].@align == 'left'} - rootNode.table.tgroup.tbody.'*'.every {row -> row.entry[2].@align == 'center'} + rootNode.table.tgroup.tbody.'*'.every { row -> row.entry[1].@align == 'left' } + rootNode.table.tgroup.tbody.'*'.every { row -> row.entry[2].@align == 'center' } } } diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockProcessorCreatesABlockThatATreeProcessorVisits.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockProcessorCreatesABlockThatATreeProcessorVisits.groovy index 846d6c212..2313fce16 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockProcessorCreatesABlockThatATreeProcessorVisits.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockProcessorCreatesABlockThatATreeProcessorVisits.groovy @@ -7,58 +7,52 @@ import org.asciidoctor.ast.Block import org.asciidoctor.ast.ContentModel import org.asciidoctor.ast.Document import org.asciidoctor.ast.StructuralNode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith - import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenABlockProcessorCreatesABlockThatATreeProcessorVisits extends Specification { - @Name('tst') - @Contexts(Contexts.OPEN) - @ContentModel(ContentModel.COMPOUND) - static class BlockCreator extends BlockProcessor { + @Name('tst') + @Contexts(Contexts.OPEN) + @ContentModel(ContentModel.COMPOUND) + static class BlockCreator extends BlockProcessor { - @Override - Object process(StructuralNode parent, Reader reader, Map attributes) { - List output = new LinkedList<>() - output.add('line 1') - output.add('line 2') + @Override + Object process(StructuralNode parent, Reader reader, Map attributes) { + List output = new LinkedList<>() + output.add('line 1') + output.add('line 2') - attributes.put('name', 'value') + attributes.put('name', 'value') - createBlock(parent, 'open', output, attributes) - } - } + createBlock(parent, 'open', output, attributes) + } + } - static class BlockVisitor extends Treeprocessor { + static class BlockVisitor extends Treeprocessor { - @Override - Document process(Document document) { - recurse(document) - document - } + @Override + Document process(Document document) { + recurse(document) + document + } - private void recurse(StructuralNode node) { - // Accessing the attributes of a block that was previously created by a block processor - // causes a ClassCastException in ContentNodeImpl#getAttributes since the value returned - // from the AbstractNode in the JRuby AST is an instance of MapJavaProxy, which does not - // conform to RubyHash. - Map attributes = node.getAttributes() + private void recurse(StructuralNode node) { + // Accessing the attributes of a block that was previously created by a block processor + // causes a ClassCastException in ContentNodeImpl#getAttributes since the value returned + // from the AbstractNode in the JRuby AST is an instance of MapJavaProxy, which does not + // conform to RubyHash. + Map attributes = node.getAttributes() - // To silence Codenarc. We must access the attributes to provoke the error. - attributes = new HashMap(attributes) + // To silence Codenarc. We must access the attributes to provoke the error. + attributes = new HashMap(attributes) - for (Block block : node.getBlocks()) { - recurse(block) - } - } - } + for (Block block : node.getBlocks()) { + recurse(block) + } + } + } - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static final String DOCUMENT = ''' = Block and Tree Processor Interaction Test @@ -71,10 +65,9 @@ This will be ignored ''' def "execution should not throw class cast exception"() { - given: asciidoctor.javaExtensionRegistry().block(BlockCreator) - asciidoctor.javaExtensionRegistry().treeprocessor(BlockVisitor) + asciidoctor.javaExtensionRegistry().treeprocessor(BlockVisitor) when: asciidoctor.convert(DOCUMENT, OptionsBuilder.options().safe(SafeMode.SAFE).toFile(false).standalone(true)) @@ -83,5 +76,4 @@ This will be ignored notThrown(ClassCastException) } - } diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockShouldBeDuplicated.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockShouldBeDuplicated.groovy index 6a1397d05..efb97081e 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockShouldBeDuplicated.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockShouldBeDuplicated.groovy @@ -5,20 +5,15 @@ import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode import org.asciidoctor.ast.ContentModel import org.asciidoctor.ast.Document -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenABlockShouldBeDuplicated extends Specification { - public static final String VERBATIM = 'verbatim' public static final String CLASS_LISTINGBLOCK = '.listingblock' - @ArquillianResource - private Asciidoctor asciidoctor + + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def 'it should be possible to copy the content_model'() { @@ -42,7 +37,6 @@ class WhenABlockShouldBeDuplicated extends Specification { } - def 'it should be possible to copy substitutions'() { given: diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionChecksAttributes.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionChecksAttributes.groovy index df27f2284..5555330f6 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionChecksAttributes.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionChecksAttributes.groovy @@ -3,14 +3,10 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Issue import spock.lang.Specification @Issue('https://github.com/asciidoctor/asciidoctorj/issues/450') -@RunWith(ArquillianSputnik) class WhenAJavaExtensionChecksAttributes extends Specification { @@ -21,8 +17,7 @@ Check me ''' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def "a BlockProcessor should only get String attribute keys"() { when: diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionGroupIsRegisteredWithAnnotations.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionGroupIsRegisteredWithAnnotations.groovy index 7547ceb46..6b38ecdfa 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionGroupIsRegisteredWithAnnotations.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionGroupIsRegisteredWithAnnotations.groovy @@ -3,17 +3,13 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import org.junit.runner.RunWith import spock.lang.Issue import spock.lang.Specification @Issue('https://github.com/asciidoctor/asciidoctorj/issues/196') -@RunWith(ArquillianSputnik) class WhenAJavaExtensionGroupIsRegisteredWithAnnotations extends Specification { public static final String UTF8 = 'UTF-8' @@ -27,8 +23,7 @@ class WhenAJavaExtensionGroupIsRegisteredWithAnnotations extends Specification { public static final String HREF = 'href' public static final String ANCHOR_TAG = 'a' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static final String DOCUMENT = '''= Test document ''' diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionIsRegisteredWithAnnotations.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionIsRegisteredWithAnnotations.groovy index 941acb252..942d82292 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionIsRegisteredWithAnnotations.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionIsRegisteredWithAnnotations.groovy @@ -3,17 +3,13 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import org.junit.runner.RunWith import spock.lang.Issue import spock.lang.Specification @Issue('https://github.com/asciidoctor/asciidoctorj/issues/196') -@RunWith(ArquillianSputnik) class WhenAJavaExtensionIsRegisteredWithAnnotations extends Specification { public static final String UTF8 = 'UTF-8' @@ -27,8 +23,7 @@ class WhenAJavaExtensionIsRegisteredWithAnnotations extends Specification { public static final String HREF = 'href' public static final String ANCHOR_TAG = 'a' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static final String DOCUMENT = '''= Test document ''' diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionUsesCounters.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionUsesCounters.groovy index f15c06836..93e730017 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionUsesCounters.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAJavaExtensionUsesCounters.groovy @@ -8,18 +8,14 @@ import org.asciidoctor.ast.Block import org.asciidoctor.ast.ContentModel import org.asciidoctor.ast.Section import org.asciidoctor.ast.StructuralNode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.select.Elements -import org.junit.runner.RunWith import spock.lang.Specification import static org.asciidoctor.ast.ContentModel.SIMPLE @SuppressWarnings('DuplicateNumberLiteral') -@RunWith(ArquillianSputnik) class WhenAJavaExtensionUsesCounters extends Specification { public static final String UTF8 = 'UTF-8' @@ -28,8 +24,7 @@ class WhenAJavaExtensionUsesCounters extends Specification { public static final String PARAGRAPH_SELECTOR = '.paragraph' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def 'using the counter macro should continue the counters set in macros but doesnt'() { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorIsRegistered.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorIsRegistered.groovy index 885be592c..671342cdf 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorIsRegistered.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorIsRegistered.groovy @@ -3,18 +3,13 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.ast.Document -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification import java.util.concurrent.atomic.AtomicBoolean -@RunWith(ArquillianSputnik) class WhenAPreprocessorIsRegistered extends Specification { - - @ArquillianResource - private Asciidoctor asciidoctor + + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() public static final int ONE = 1 public static final int TWO = 2 diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorSetsTheSourceMapOption.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorSetsTheSourceMapOption.groovy index d5364f111..fdd346829 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorSetsTheSourceMapOption.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAPreprocessorSetsTheSourceMapOption.groovy @@ -3,18 +3,13 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.ast.Document -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenAPreprocessorSetsTheSourceMapOption extends Specification { static final int NOT_SET = -1 - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() static class SourceMapOptionPreprocessor extends Preprocessor { @Override @@ -26,6 +21,7 @@ class WhenAPreprocessorSetsTheSourceMapOption extends Specification { static class TestTreeprocessor extends Treeprocessor { int lineNoFirstSection = 0 + @Override Document process(Document document) { def blocks = document.getBlocks() diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorCreatesNodes.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorCreatesNodes.groovy index 6240a0c1f..d050b8633 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorCreatesNodes.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorCreatesNodes.groovy @@ -4,15 +4,11 @@ import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder import org.asciidoctor.ast.Document import org.asciidoctor.ast.StructuralNode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.select.Elements -import org.junit.runner.RunWith import spock.lang.Issue import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenATreeProcessorCreatesNodes extends Specification { public static final String NEW_CODE = 'puts "World"' @@ -23,8 +19,7 @@ class WhenATreeProcessorCreatesNodes extends Specification { public static final String ELEM_CODE = 'code' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() @Issue('https://github.com/asciidoctor/asciidoctorj/issues/513') def 'it should be able to copy attributes from another node'() { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorWorksOnTables.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorWorksOnTables.groovy index b124368e3..9ec87f862 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorWorksOnTables.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenATreeProcessorWorksOnTables.groovy @@ -2,13 +2,9 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenATreeProcessorWorksOnTables extends Specification { private static final String EMPTY_DOCUMENT = '= Document without table' @@ -23,8 +19,7 @@ class WhenATreeProcessorWorksOnTables extends Specification { public static final String TH = 'th' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def "then the extension should be able to create tables"() { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnExtensionAppendsChildBlocks.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnExtensionAppendsChildBlocks.groovy index 9c1f9fc7d..8662a5c45 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnExtensionAppendsChildBlocks.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnExtensionAppendsChildBlocks.groovy @@ -2,20 +2,18 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder -import org.asciidoctor.ast.StructuralNode import org.asciidoctor.ast.Block import org.asciidoctor.ast.Document import org.asciidoctor.ast.Section -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource +import org.asciidoctor.ast.StructuralNode import org.jsoup.Jsoup -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenAnExtensionAppendsChildBlocks extends Specification { - String document = '''= Test document + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() + + final String document = '''= Test document == Section 1 @@ -27,9 +25,6 @@ more text ''' - @ArquillianResource - private Asciidoctor asciidoctor - def 'should be able to blocks via Block_append'() { given: @@ -121,7 +116,7 @@ testmacro::target[] } }) - asciidoctor.javaExtensionRegistry().blockMacro(new BlockMacroProcessor('testmacro'){ + asciidoctor.javaExtensionRegistry().blockMacro(new BlockMacroProcessor('testmacro') { @Override StructuralNode process(StructuralNode parent, String target, Map attributes) { createBlock(parent, 'paragraph', expectedContent, [:]) diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnInlineMacroProcessorProcessesATable.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnInlineMacroProcessorProcessesATable.groovy index 3b4005b88..c39fb10d4 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnInlineMacroProcessorProcessesATable.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenAnInlineMacroProcessorProcessesATable.groovy @@ -2,17 +2,13 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.OptionsBuilder -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import org.junit.runner.RunWith import spock.lang.Issue import spock.lang.Specification @Issue('https://github.com/asciidoctor/asciidoctorj/issues/448') -@RunWith(ArquillianSputnik) class WhenAnInlineMacroProcessorProcessesATable extends Specification { public static final String UTF8 = 'UTF-8' @@ -20,8 +16,7 @@ class WhenAnInlineMacroProcessorProcessesATable extends Specification { public static final String ANCHOR_TAG = 'a' public static final String TARGET = 'gittutorial.html' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() private static final String INLINE_MACRO_DOCUMENT = '''= Test document 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 3bd9493eb..a15c0db5b 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenExtensionsAreRegisteredAsService.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenExtensionsAreRegisteredAsService.groovy @@ -3,36 +3,29 @@ package org.asciidoctor.extension import org.asciidoctor.Asciidoctor import org.asciidoctor.Options import org.asciidoctor.SafeMode -import org.asciidoctor.arquillian.api.Unshared -import org.asciidoctor.util.ClasspathResources -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource +import org.asciidoctor.util.ClasspathHelper import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import org.junit.Test -import org.junit.rules.TemporaryFolder -import org.junit.runner.RunWith import spock.lang.Ignore import spock.lang.Specification +import spock.lang.TempDir -@RunWith(ArquillianSputnik) class WhenExtensionsAreRegisteredAsService extends Specification { static final String FILENAME_HTML = 'rendersample.html' - @ArquillianResource - ClasspathResources classpath - - @ArquillianResource(Unshared) + ClasspathHelper classpath Asciidoctor asciidoctor - - @ArquillianResource - TemporaryFolder testFolder - ClassLoader originalTCCL + @TempDir + File testFolder + def setup() { + asciidoctor = Asciidoctor.Factory.create() + classpath = new ClasspathHelper() + classpath.classloader = WhenExtensionsAreRegisteredAsService originalTCCL = Thread.currentThread().contextClassLoader } @@ -42,14 +35,13 @@ class WhenExtensionsAreRegisteredAsService extends Specification { @Ignore('Test is ignored because currently it is not possible to register two block extensions in same instance. This may require deep changes on Asciidoctor Extensions API') - @Test def 'extensions should be correctly added'() throws IOException { when: //To avoid registering the same extension over and over for all tests, service is instantiated manually. new ArrowsAndBoxesExtension().register(asciidoctor) - File renderedFile = testFolder.newFile(FILENAME_HTML) + File renderedFile = new File(testFolder, FILENAME_HTML) Options options = Options.builder() .inPlace(false) .toFile(renderedFile) diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/jruby/internal/RubyAttributesMapDecoratorSpecification.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/jruby/internal/RubyAttributesMapDecoratorSpecification.groovy index 8eb22c6a8..6497ba7d9 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/jruby/internal/RubyAttributesMapDecoratorSpecification.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/jruby/internal/RubyAttributesMapDecoratorSpecification.groovy @@ -3,12 +3,8 @@ package org.asciidoctor.jruby.internal import org.asciidoctor.Asciidoctor import org.asciidoctor.ast.Block import org.asciidoctor.ast.Document -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class RubyAttributesMapDecoratorSpecification extends Specification { public static final String ATTR_ONE = '1' @@ -16,8 +12,7 @@ class RubyAttributesMapDecoratorSpecification extends Specification { public static final String ATTR_NAME_ROLE = 'role' public static final String ATTR_NAME_ID = 'id' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() String attrValue = 'example#idname.rolename' String blockStyle = 'example' diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenACoderayAdapterIsImplementedInGroovy.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenACoderayAdapterIsImplementedInGroovy.groovy index 776b50c2d..61cd94bda 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenACoderayAdapterIsImplementedInGroovy.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenACoderayAdapterIsImplementedInGroovy.groovy @@ -4,21 +4,16 @@ import org.asciidoctor.Asciidoctor import org.asciidoctor.AttributesBuilder import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.runner.RunWith import spock.lang.Ignore import spock.lang.Specification import static junit.framework.Assert.assertEquals -@RunWith(ArquillianSputnik) class WhenACoderayAdapterIsImplementedInGroovy extends Specification { public static final String NAME_SYNTAXHIGHLIGHTER = 'coderay4J' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() @Ignore('until the latest release also puts the link to the CSS into the header') def 'should highlight with coderay'() { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAHighlightjsAdapterIsImplementedInGroovy.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAHighlightjsAdapterIsImplementedInGroovy.groovy index 7190945c6..f475bfacf 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAHighlightjsAdapterIsImplementedInGroovy.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAHighlightjsAdapterIsImplementedInGroovy.groovy @@ -4,26 +4,20 @@ import org.asciidoctor.Asciidoctor import org.asciidoctor.AttributesBuilder import org.asciidoctor.OptionsBuilder import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.nodes.Document -import org.junit.runner.RunWith import spock.lang.Specification import static org.hamcrest.Matchers.equalTo import static org.hamcrest.Matchers.is import static org.junit.Assert.assertThat -@RunWith(ArquillianSputnik) class WhenAHighlightjsAdapterIsImplementedInGroovy extends Specification { public static final String NAME_SYNTAXHIGHLIGHTER = 'highlight4J' - public static final String HIGHLIGHTJS = 'highlightjs' public static final String EMPTY_STRING = '' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() def doc = '''= Test Document :nofooter: diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenALayoutingSyntaxHighlighterIsRegistered.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenALayoutingSyntaxHighlighterIsRegistered.groovy index 1b1268c1a..aca81afc1 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenALayoutingSyntaxHighlighterIsRegistered.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenALayoutingSyntaxHighlighterIsRegistered.groovy @@ -7,20 +7,15 @@ import org.asciidoctor.SafeMode import org.asciidoctor.ast.Block import org.asciidoctor.ast.Document import org.asciidoctor.extension.LocationType -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.select.Elements -import org.junit.runner.RunWith import spock.lang.Specification -@RunWith(ArquillianSputnik) class WhenALayoutingSyntaxHighlighterIsRegistered extends Specification { public static final String NAME_SYNTAXHIGHLIGHTER = 'test' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() static class AllGoHighlighter implements SyntaxHighlighterAdapter, Formatter { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAServerSideSyntaxHighlighterIsRegistered.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAServerSideSyntaxHighlighterIsRegistered.groovy index 15267255b..6208286f9 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAServerSideSyntaxHighlighterIsRegistered.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenAServerSideSyntaxHighlighterIsRegistered.groovy @@ -7,21 +7,16 @@ import org.asciidoctor.SafeMode import org.asciidoctor.ast.Block import org.asciidoctor.ast.Document import org.asciidoctor.extension.LocationType -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource import org.jsoup.Jsoup import org.jsoup.select.Elements -import org.junit.runner.RunWith import spock.lang.Specification import spock.lang.Unroll -@RunWith(ArquillianSputnik) class WhenAServerSideSyntaxHighlighterIsRegistered extends Specification { public static final String NAME_SYNTAXHIGHLIGHTER = 'test' - @ArquillianResource - private Asciidoctor asciidoctor + private Asciidoctor asciidoctor = Asciidoctor.Factory.create() static class TestHighlighter implements SyntaxHighlighterAdapter, Highlighter { diff --git a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenASyntaxHighlighterThatWritesStylesheetsIsRegistered.groovy b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenASyntaxHighlighterThatWritesStylesheetsIsRegistered.groovy index 640648dbf..6ab961751 100644 --- a/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenASyntaxHighlighterThatWritesStylesheetsIsRegistered.groovy +++ b/asciidoctorj-core/src/test/groovy/org/asciidoctor/syntaxhighlighter/WhenASyntaxHighlighterThatWritesStylesheetsIsRegistered.groovy @@ -6,9 +6,8 @@ import org.asciidoctor.Options import org.asciidoctor.SafeMode import org.asciidoctor.ast.Document import org.asciidoctor.extension.LocationType -import org.junit.Rule -import org.junit.rules.TemporaryFolder import spock.lang.Specification +import spock.lang.TempDir import spock.lang.Unroll class WhenASyntaxHighlighterThatWritesStylesheetsIsRegistered extends Specification { @@ -20,8 +19,8 @@ class WhenASyntaxHighlighterThatWritesStylesheetsIsRegistered extends Specificat private Asciidoctor asciidoctor = Asciidoctor.Factory.create() - @Rule - public TemporaryFolder tmp = new TemporaryFolder() + @TempDir + public File tempDir static class TestHighlighter implements SyntaxHighlighterAdapter, StylesheetWriter { @@ -72,7 +71,7 @@ System.out.println("Hello World"); ---- """ - def toDir = tmp.newFolder() + def toDir = tempDir asciidoctor.syntaxHighlighterRegistry().register(TestHighlighter, NAME_SYNTAXHIGHLIGHTER) when: @@ -94,6 +93,5 @@ System.out.println("Hello World"); lang | exists 'java' | true 'go' | false - } } diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiatedInAnEnvironmentWithGemPath.java b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiatedInAnEnvironmentWithGemPath.java index b4de3feaa..0bdf99cf7 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiatedInAnEnvironmentWithGemPath.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/WhenAnAsciidoctorClassIsInstantiatedInAnEnvironmentWithGemPath.java @@ -5,10 +5,10 @@ import org.asciidoctor.jruby.internal.JRubyRuntimeContext; import org.jruby.Ruby; import org.jruby.RubyString; -import org.junit.Test; -import org.junit.experimental.categories.Category; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; /** @@ -17,7 +17,7 @@ * It can mix up the JRuby instance when it can see gems from a C-Ruby * with native extensions. */ -@Category(Polluted.class) +@Polluted public class WhenAnAsciidoctorClassIsInstantiatedInAnEnvironmentWithGemPath { @Test diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/categories/Polluted.java b/asciidoctorj-core/src/test/java/org/asciidoctor/categories/Polluted.java index 796cc807c..362dbb1b7 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/categories/Polluted.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/categories/Polluted.java @@ -1,8 +1,18 @@ package org.asciidoctor.categories; +import org.junit.jupiter.api.Tag; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + /** - * Defines tests that are executed within a "polluted" environment, that is environment variables GEM_PATH - * and GEM_HOME will be set. + * Defines tests that are executed within a "polluted" environment, that is + * environment variables GEM_PATH and GEM_HOME will be set. */ -public class Polluted { +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Tag("polluted") +public @interface Polluted { } diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/ArrowsAndBoxesExtension.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/ArrowsAndBoxesExtension.java index 90693e95d..82f835151 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/ArrowsAndBoxesExtension.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/ArrowsAndBoxesExtension.java @@ -5,14 +5,10 @@ public class ArrowsAndBoxesExtension implements ExtensionRegistry { - @Override public void register(Asciidoctor asciidoctor) { - JavaExtensionRegistry javaExtensionRegistry = asciidoctor.javaExtensionRegistry(); javaExtensionRegistry.postprocessor(ArrowsAndBoxesIncludesPostProcessor.class); javaExtensionRegistry.block("arrowsAndBoxes", ArrowsAndBoxesBlock.class); - } - } diff --git a/asciidoctorj-distribution/build.gradle b/asciidoctorj-distribution/build.gradle index 24b0c0361..0a9f1cde1 100644 --- a/asciidoctorj-distribution/build.gradle +++ b/asciidoctorj-distribution/build.gradle @@ -29,7 +29,9 @@ dependencies { } implementation "org.jruby:jruby-complete:$jrubyVersion" - testImplementation project(':asciidoctorj-arquillian-extension') + testImplementation (project(':asciidoctorj-test-support')) { + exclude group: 'junit', module: 'junit' + } testImplementation "org.apache.pdfbox:pdfbox:$pdfboxVersion" testImplementation "org.jsoup:jsoup:$jsoupVersion" } @@ -68,6 +70,7 @@ def publication = rootProject.project('asciidoctorj').extensions.findByName('pub if (!publication) { throw new ProjectConfigurationException("Publication ${project.ext.publicationName} not configured yet", []) } + publication.each { it.artifact(distZip) { classifier 'bin' diff --git a/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenAPdfDocumentIsRenderedToStream.groovy b/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenAPdfDocumentIsRenderedToStream.groovy deleted file mode 100644 index 2ca628341..000000000 --- a/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenAPdfDocumentIsRenderedToStream.groovy +++ /dev/null @@ -1,110 +0,0 @@ -package org.asciidoctor.diagram - -import org.asciidoctor.Asciidoctor -import org.asciidoctor.AttributesBuilder -import org.asciidoctor.OptionsBuilder -import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.rules.TemporaryFolder -import org.junit.runner.RunWith -import spock.lang.Specification - -import java.text.SimpleDateFormat - -@RunWith(ArquillianSputnik) -class WhenAPdfDocumentIsRenderedToStream extends Specification { - - public static final String BACKEND_PDF = 'pdf' - @ArquillianResource - private Asciidoctor asciidoctor - - @ArquillianResource - public TemporaryFolder testFolder - - static final String ASCIIDOCTOR_DIAGRAM = 'asciidoctor-diagram' - - - def 'should render PDF to ByteArrayOutputStream'() throws Exception { - - given: - String imageFileName = UUID.randomUUID() - - File referenceFile = new File('build/stream-test-file.pdf') - File streamFile = new File('build/stream-test-stream.pdf') - File imagesOutDir = new File(testFolder.root, 'images-dir') - def createdCacheImage = new File(testFolder.root, ".asciidoctor/diagram/${imageFileName}.png.cache") - - String testDoc = """= Test - -A test document - -== A Section - -Hello World - -[ditaa,${imageFileName}] -.... - -+---+ -| A | -+---+ -.... - -== Another Section - -Some other test - -a - -<<< - -b - -c - -""" - - asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM) - - def out = new ByteArrayOutputStream() - - def dateTimeFormatter = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss z') - - def now = new Date() - - def attrs = AttributesBuilder.attributes() - .attribute('outdir', testFolder.root.absolutePath) - .attribute('imagesdir', imagesOutDir.name) - .attribute('docdatetime', dateTimeFormatter.format(now)) - .attribute('localdatetime', dateTimeFormatter.format(now)) - .attribute('reproducible', 'true') - - when: - asciidoctor.convert(testDoc, - OptionsBuilder.options() - .backend(BACKEND_PDF) - .standalone(true) - .attributes(attrs) - .safe(SafeMode.UNSAFE) - .toStream(out)) - - streamFile.bytes = out.toByteArray() - def toStreamBytes = out.toByteArray() - - asciidoctor.convert(testDoc, - OptionsBuilder.options() - .backend(BACKEND_PDF) - .standalone(true) - .attributes(attrs) - .safe(SafeMode.UNSAFE) - .toFile(referenceFile)) - - def toFileBytes = referenceFile.bytes - - then: - createdCacheImage.exists() - toStreamBytes.length == toFileBytes.length - Arrays.equals(toStreamBytes, toFileBytes) - } -} diff --git a/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.groovy b/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.groovy deleted file mode 100644 index 41e7c9663..000000000 --- a/asciidoctorj-distribution/src/test/groovy/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.groovy +++ /dev/null @@ -1,109 +0,0 @@ -package org.asciidoctor.diagram - -import org.asciidoctor.Asciidoctor -import org.asciidoctor.AttributesBuilder -import org.asciidoctor.OptionsBuilder -import org.asciidoctor.SafeMode -import org.jboss.arquillian.spock.ArquillianSputnik -import org.jboss.arquillian.test.api.ArquillianResource -import org.junit.rules.TemporaryFolder -import org.junit.runner.RunWith -import spock.lang.Specification - -@RunWith(ArquillianSputnik) -class WhenDitaaDiagramIsRendered extends Specification { - - static final String ASCIIDOCTOR_DIAGRAM = 'asciidoctor-diagram' - - static final String BUILD_DIR = 'build' - - @ArquillianResource - private Asciidoctor asciidoctor - - @ArquillianResource - public TemporaryFolder testFolder - - def 'should render ditaa diagram to HTML'() throws Exception { - - given: - String imageFileName = UUID.randomUUID() - File imagesOutDir = new File(testFolder.root, 'images-dir') - def createdCacheImage = new File(testFolder.root, ".asciidoctor/diagram/${imageFileName}.png.cache") - - String document = """= Document Title - -Hello World - -[ditaa,${imageFileName}] -.... - -+---+ -| A | -+---+ -.... - -""" - - asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM) - - when: - String result = asciidoctor.convert(document, OptionsBuilder.options() - .toFile(false) - .toDir(testFolder.root) - .safe(SafeMode.UNSAFE) - .attributes(AttributesBuilder.attributes() - .attribute('imagesdir', imagesOutDir.name) - .attribute('outdir', testFolder.root.absolutePath))) - - - then: - result.contains("""src="${imagesOutDir.name}/${imageFileName}.png""") - - new File(imagesOutDir, "${imageFileName}.png").exists() - createdCacheImage.exists() - - } - - def 'should render ditaa diagram to PDF'() throws Exception { - - given: - File destinationFile = new File('test.pdf') - String imageFileName = UUID.randomUUID() - - File createdPdf = new File(testFolder.root, destinationFile.name) - File createdImage = new File(testFolder.root, "${imageFileName}.png") - File createdCacheImage = new File(testFolder.root, ".asciidoctor/diagram/${imageFileName}.png.cache") - - String document = """= Document Title - -Hello World - -[ditaa,${imageFileName}] -.... - -+---+ -| A | -+---+ -.... - -""" - - asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM) - - when: - asciidoctor.convert(document, OptionsBuilder.options() - .toDir(testFolder.root) - .toFile(destinationFile) - .safe(SafeMode.UNSAFE) - .backend('pdf')) - - - then: - - createdPdf.exists() - createdImage.exists() - createdCacheImage.exists() - - } - -} diff --git a/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenAPdfDocumentIsRenderedToStream.java b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenAPdfDocumentIsRenderedToStream.java new file mode 100644 index 000000000..f100e24c7 --- /dev/null +++ b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenAPdfDocumentIsRenderedToStream.java @@ -0,0 +1,110 @@ +package org.asciidoctor; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +public class WhenAPdfDocumentIsRenderedToStream { + + private static final String BACKEND_PDF = "pdf"; + private static final String ASCIIDOCTOR_DIAGRAM = "asciidoctor-diagram"; + + private Asciidoctor asciidoctor; + + @BeforeEach + public void initAsciidoctor() { + this.asciidoctor = Asciidoctor.Factory.create(); + } + + @Test + void should_render_PDF_to_ByteArrayOutputStream(@TempDir File testFolder) throws IOException { + // given + final String imageFileName = String.format("%s", random()); + final File referenceFile = new File(testFolder, String.format("stream-test-file-%s.pdf", random())); + final File imagesOutDir = new File(testFolder, "images-dir"); + final File createdCacheImage = new File(testFolder, String.format(".asciidoctor/diagram/%s.png.cache", imageFileName)); + + String testDoc = new StringBuilder() + .append("= Test").append("\n") + .append("\n") + .append("A test document").append("\n") + .append("\n") + .append("== A Section").append("\n") + .append("\n") + .append("Hello World").append("\n") + .append("\n") + .append(String.format("[ditaa,%s]", imageFileName)).append("\n") + .append("....") + .append("\n") + .append("+---+") + .append("| A |") + .append("+---+") + .append("....") + .append("\n") + .append("== Another Section") + .append("\n") + .append("Some other test") + .append("\n") + .append("a") + .append("\n") + .append("<<<") + .append("\n") + .append("b") + .append("\n") + .append("c") + .append("\n") + .toString(); + + var out = new ByteArrayOutputStream(); + var dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); + var now = new Date(); + + Attributes attrs = Attributes.builder() + .attribute("outdir", testFolder.getAbsolutePath()) + .attribute("imagesdir", imagesOutDir.getName()) + .attribute("docdatetime", dateTimeFormatter.format(now)) + .attribute("localdatetime", dateTimeFormatter.format(now)) + .attribute("reproducible", "true") + .build(); + + // when + asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM); + asciidoctor.convert(testDoc, + Options.builder() + .backend(BACKEND_PDF) + .standalone(true) + .attributes(attrs) + .safe(SafeMode.UNSAFE) + .toStream(out) + .build()); + asciidoctor.convert(testDoc, + Options.builder() + .backend(BACKEND_PDF) + .standalone(true) + .attributes(attrs) + .safe(SafeMode.UNSAFE) + .toFile(referenceFile) + .build()); + + // then + assertThat(createdCacheImage).exists(); + final byte[] toStreamBytes = out.toByteArray(); + final byte[] toFileBytes = Files.readAllBytes(referenceFile.toPath()); + assertThat(toStreamBytes).isEqualTo(toFileBytes); + assertThat(toStreamBytes).hasSameSizeAs(toFileBytes); + } + + private static UUID random() { + return UUID.randomUUID(); + } +} diff --git a/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsPdf.java b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsPdf.java index b911057ac..b577e1545 100644 --- a/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsPdf.java +++ b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsPdf.java @@ -1,15 +1,12 @@ package org.asciidoctor; -import org.asciidoctor.arquillian.api.Unshared; -import org.asciidoctor.util.ClasspathResources; +import org.asciidoctor.util.ClasspathHelper; import org.asciidoctor.util.RougeColors; import org.asciidoctor.util.pdf.ColorsProcessor; import org.asciidoctor.util.pdf.ImageProcessor; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; import org.jruby.runtime.builtin.IRubyObject; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.awt.*; import java.io.File; @@ -18,20 +15,22 @@ import java.util.Map; import static org.asciidoctor.OptionsBuilder.options; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; + -@RunWith(Arquillian.class) public class WhenBackendIsPdf { public static final String DOCUMENT = "= A document\n\n Test"; - @ArquillianResource(Unshared.class) private Asciidoctor asciidoctor; + private ClasspathHelper classpath; - @ArquillianResource - private ClasspathResources classpath; + @BeforeEach + public void initAsciidoctor() { + this.asciidoctor = Asciidoctor.Factory.create(); + this.classpath = new ClasspathHelper(); + this.classpath.setClassloader(this.getClass()); + } @Test public void pdf_should_be_rendered_to_object_for_pdf_backend() { @@ -39,22 +38,22 @@ public void pdf_should_be_rendered_to_object_for_pdf_backend() { // If the result should be written to a file the write method will convert to a PDF stream // Therefore, if the result should not be written to a file the PDF converter should be returned. IRubyObject o = asciidoctor.convert(DOCUMENT, options().backend("pdf").get(), IRubyObject.class); - assertThat(o.getMetaClass().getRealClass().getName(), is("Asciidoctor::PDF::Converter")); + assertThat(o.getMetaClass().getRealClass().getName()).isEqualTo("Asciidoctor::PDF::Converter"); } @Test public void pdf_should_include_images() throws IOException { String filename = "image-sample"; - File inputFile = this.classpath.getResource(filename + ".adoc"); + File inputFile = classpath.getResource(filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); asciidoctor.convertFile(inputFile, options().backend("pdf").safe(SafeMode.UNSAFE).get()); - assertThat(outputFile1.exists(), is(true)); + assertThat(outputFile1).exists(); ImageProcessor imageProcessor = new ImageProcessor(); imageProcessor.parse(outputFile1.getAbsolutePath()); List images = imageProcessor.getImages(); - assertThat(images.size(), is(2)); + assertThat(images).hasSize(2); outputFile1.delete(); } @@ -62,23 +61,24 @@ public void pdf_should_include_images() throws IOException { @Test public void pdf_source_code_should_be_highlighted() throws IOException { String filename = "code-sample"; - File inputFile = this.classpath.getResource(filename + ".adoc"); + File inputFile = classpath.getResource(filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); asciidoctor.convertFile(inputFile, options().backend("pdf").safe(SafeMode.UNSAFE).get()); - assertThat(outputFile1.exists(), is(true)); + assertThat(outputFile1).exists(); - ColorsProcessor colorsProcessor = new ColorsProcessor("program", "System.out.println", "printHello", "HelloWorld", "", "else", "Math.sqrt" ); + ColorsProcessor colorsProcessor = new ColorsProcessor("program", "System.out.println", "printHello", "HelloWorld", "", "else", "Math.sqrt"); colorsProcessor.parse(outputFile1.getAbsolutePath()); Map> colors = colorsProcessor.getColors(); - assertThat(colors.get("program").get(0), equalTo(RougeColors.GREY)); - assertThat(colors.get("System.out.println").get(0), equalTo(RougeColors.LIGHT_BLUE)); - assertThat(colors.get("printHello").get(0), equalTo(RougeColors.DARK_BLUE)); - assertThat(colors.get("HelloWorld").get(0), equalTo(RougeColors.PINK)); - assertThat(colors.get("").get(0), equalTo(RougeColors.PINK)); - assertThat(colors.get("else").get(0), equalTo(RougeColors.GREEN)); - assertThat(colors.get("Math.sqrt").get(0), equalTo(RougeColors.LIGHT_BLUE)); + assertThat(colors.get("program").get(0)).isEqualTo(RougeColors.GREY); + assertThat(colors.get("System.out.println").get(0)).isEqualTo(RougeColors.LIGHT_BLUE); + + assertThat(colors.get("printHello").get(0)).isEqualTo(RougeColors.DARK_BLUE); + assertThat(colors.get("HelloWorld").get(0)).isEqualTo(RougeColors.PINK); + assertThat(colors.get("").get(0)).isEqualTo(RougeColors.PINK); + assertThat(colors.get("else").get(0)).isEqualTo(RougeColors.GREEN); + assertThat(colors.get("Math.sqrt").get(0)).isEqualTo(RougeColors.LIGHT_BLUE); outputFile1.delete(); } @@ -86,10 +86,11 @@ public void pdf_source_code_should_be_highlighted() throws IOException { @Test public void pdf_should_not_fail_with_empty_tables() { String filename = "empty-table"; - File inputFile = this.classpath.getResource(filename + ".adoc"); + File inputFile = classpath.getResource(filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); asciidoctor.convertFile(inputFile, options().backend("pdf").safe(SafeMode.SAFE).get()); - assertThat(outputFile1.exists(), is(true)); + + assertThat(outputFile1).exists(); } } diff --git a/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsRevealJs.java b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsRevealJs.java index e86eafdf9..5427c53c7 100644 --- a/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsRevealJs.java +++ b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsRevealJs.java @@ -4,22 +4,21 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.IOException; import java.util.List; import static java.util.stream.Collectors.toList; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class WhenBackendIsRevealJs { private Asciidoctor asciidoctor; - @Before + @BeforeEach public void initAsciidoctor() { this.asciidoctor = Asciidoctor.Factory.create(); } @@ -40,23 +39,22 @@ public void should_create_simple_slides() throws IOException { Document doc = Jsoup.parse(outputFile1, "UTF-8"); - assertThat(outputFile1.exists(), is(true)); + assertThat(outputFile1).exists(); List stylesheets = doc.head().getElementsByTag("link").stream() .filter(element -> "stylesheet".equals(element.attr("rel"))) .map(element -> element.attr("href")) .collect(toList()); - assertThat(stylesheets, - hasItems( - "https://cdn.jsdelivr.net/npm/reveal.js@3.9.2/css/reveal.css", - "https://cdn.jsdelivr.net/npm/reveal.js@3.9.2/css/theme/black.css")); + assertThat(stylesheets) + .contains("https://cdn.jsdelivr.net/npm/reveal.js@3.9.2/css/reveal.css", + "https://cdn.jsdelivr.net/npm/reveal.js@3.9.2/css/theme/black.css"); Element diagramSlide = doc.selectFirst("#diagram"); - assertThat(diagramSlide, notNullValue()); + assertThat(diagramSlide).isNotNull(); Element diagram = diagramSlide.selectFirst("div.imageblock img"); - assertThat(diagram, notNullValue()); - assertThat(diagram.attr("src"), startsWith("data:image/svg+xml;base64,")); + assertThat(diagram).isNotNull(); + assertThat(diagram.attr("src")).startsWith("data:image/svg+xml;base64,"); } private void removeFileIfItExists(File file) throws IOException { diff --git a/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenDitaaDiagramIsRendered.java b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenDitaaDiagramIsRendered.java new file mode 100644 index 000000000..207bef81b --- /dev/null +++ b/asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenDitaaDiagramIsRendered.java @@ -0,0 +1,89 @@ +package org.asciidoctor; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.File; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +public class WhenDitaaDiagramIsRendered { + + private static final String ASCIIDOCTOR_DIAGRAM = "asciidoctor-diagram"; + + private Asciidoctor asciidoctor; + + @BeforeEach + public void initAsciidoctor() { + this.asciidoctor = Asciidoctor.Factory.create(); + } + + @Test + void should_render_ditaa_diagram_to_HTML(@TempDir File testFolder) { + // given + final String imageFileName = String.format("%s", UUID.randomUUID()); + final File imagesOutDir = new File(testFolder, "images-dir"); + final File createdCacheImage = new File(testFolder, String.format(".asciidoctor/diagram/%s.png.cache", imageFileName)); + final String document = sourceWithDiagram(imageFileName); + + // when + asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM); + String result = asciidoctor.convert(document, Options.builder() + .toFile(false) + .toDir(testFolder) + .safe(SafeMode.UNSAFE) + .attributes(Attributes.builder() + .attribute("imagesdir", imagesOutDir.getName()) + .attribute("outdir", testFolder.getAbsolutePath()) + .build()) + .build()); + + // then + assertThat(result).contains(String.format("src=\"%s/%s.png", imagesOutDir.getName(), imageFileName)); + assertThat(new File(imagesOutDir, String.format("%s.png", imageFileName))).exists(); + assertThat(createdCacheImage).exists(); + } + + @Test + void should_render_ditaa_diagram_to_PDF(@TempDir File testFolder) { + // given + final File destinationFile = new File("test.pdf"); + final String imageFileName = UUID.randomUUID().toString(); + final File createdPdf = new File(testFolder, destinationFile.getName()); + final File createdImage = new File(testFolder, String.format("%s.png", imageFileName)); + final File createdCacheImage = new File(testFolder, String.format(".asciidoctor/diagram/%s.png.cache", imageFileName)); + final String document = sourceWithDiagram(imageFileName); + + // when + asciidoctor.requireLibrary(ASCIIDOCTOR_DIAGRAM); + asciidoctor.convert(document, Options.builder() + .toDir(testFolder) + .toFile(destinationFile) + .safe(SafeMode.UNSAFE) + .backend("pdf") + .build()); + + //then + assertThat(createdPdf).exists(); + assertThat(createdImage).exists(); + assertThat(createdCacheImage).exists(); + } + + private static String sourceWithDiagram(String imageFileName) { + return new StringBuffer() + .append("= Document Title").append("\n") + .append("\n") + .append("Hello World").append("\n") + .append("\n") + .append(String.format("[ditaa,%s]", imageFileName)).append("\n") + .append("....").append("\n") + .append("\n") + .append("+---+").append("\n") + .append("| A |").append("\n") + .append("+---+").append("\n") + .append("....").append("\n") + .toString(); + } +} diff --git a/asciidoctorj-documentation/build.gradle b/asciidoctorj-documentation/build.gradle index 8bc3e7c8f..18b7bd2c9 100644 --- a/asciidoctorj-documentation/build.gradle +++ b/asciidoctorj-documentation/build.gradle @@ -1,10 +1,10 @@ -import org.apache.tools.ant.filters.* - jar.enabled = false dependencies { testImplementation project(':asciidoctorj') - testImplementation project(':asciidoctorj-arquillian-extension') + testImplementation (project(':asciidoctorj-test-support')) { + exclude group: 'junit', module: 'junit' + } testImplementation "commons-io:commons-io:$commonsioVersion" testImplementation "org.jsoup:jsoup:$jsoupVersion" testImplementation("org.asciidoctor:asciidoctorj-pdf:$asciidoctorjPdfVersion") { @@ -21,7 +21,3 @@ compileTestJava { exclude('**/PrismJsHighlighter*.java') } } - - -test.enabled = testClasses.enabled = JavaVersion.current().isJava7Compatible() - diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/AsciidoctorInterface.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/AsciidoctorInterface.java index 53cb4d6b7..6cf157e8f 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/AsciidoctorInterface.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/AsciidoctorInterface.java @@ -2,13 +2,14 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.OptionsBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + public class AsciidoctorInterface { diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/OptionsTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/OptionsTest.java index 507e38d4d..7d513eec3 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/OptionsTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/OptionsTest.java @@ -5,31 +5,33 @@ import org.asciidoctor.Attributes; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; -import org.asciidoctor.util.ClasspathResources; -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.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.CleanupMode; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.FileReader; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(Arquillian.class) public class OptionsTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @TempDir(cleanup = CleanupMode.NEVER) + public File tempDir; - @ArquillianResource - private TemporaryFolder temporaryFolder; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void simple_options_example_embeddable_document() { @@ -46,12 +48,12 @@ public void simple_options_example_embeddable_document() { } @Test - public void options_for_pdf_document() throws Exception { + public void options_for_pdf_document() { //tag::optionsPDFBackend[] File targetFile = // ... //end::optionsPDFBackend[] - temporaryFolder.newFile("test.pdf"); - assertTrue(targetFile.exists()); + new File(tempDir, "test.pdf"); + //tag::optionsPDFBackend[] asciidoctor.convert( "Hello World", @@ -95,7 +97,7 @@ public void convert_to_dedicated_file() throws Exception { //tag::optionToFile[] File targetFile = //... //end::optionToFile[] - temporaryFolder.newFile("toFileExample.html"); + new File(tempDir, "toFileExample.html"); //tag::optionToFile[] asciidoctor.convert( diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/converter/TextConverterTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/converter/TextConverterTest.java index a95d83f70..712954c3f 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/converter/TextConverterTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/converter/TextConverterTest.java @@ -2,11 +2,9 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.OptionsBuilder; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.net.URL; @@ -15,22 +13,27 @@ import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; -@RunWith(Arquillian.class) public class TextConverterTest { - @ArquillianResource - private ClasspathResources classpathResources; + private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; + + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test - public void should_use_text_converter_for_conversion(@ArquillianResource Asciidoctor asciidoctor) { + public void should_use_text_converter_for_conversion() { //tag::include[] File test_adoc = //... //end::include[] - classpathResources.getResource("textconvertertest.adoc"); + classpathResources.getResource("textconvertertest.adoc"); //tag::include[] @@ -63,7 +66,7 @@ public void should_use_text_converter_for_conversion_registered_as_service_impl( try { URL serviceDir = classpathResources.getResource("converterregistry").toURI().toURL(); - URLClassLoader tccl = new URLClassLoader(new URL[] { serviceDir }); + URLClassLoader tccl = new URLClassLoader(new URL[]{serviceDir}); Thread.currentThread().setContextClassLoader(tccl); Asciidoctor asciidoctor = Asciidoctor.Factory.create(); @@ -80,7 +83,6 @@ public void should_use_text_converter_for_conversion_registered_as_service_impl( } finally { Thread.currentThread().setContextClassLoader(oldTCCL); } - } } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ASTShowcase.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ASTShowcase.java index 3cc79bcfe..b341a00cf 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ASTShowcase.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ASTShowcase.java @@ -2,41 +2,39 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.OptionsBuilder; -import org.asciidoctor.ast.Document; import org.asciidoctor.jruby.internal.IOUtils; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.FileReader; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class ASTShowcase { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; - + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void createAstStructure() throws Exception { asciidoctor.javaExtensionRegistry().treeprocessor(ASTExtractorTreeprocessor.class); - Document document = asciidoctor.loadFile(classpathResources.getResource("ast-demo.adoc"), OptionsBuilder.options().asMap()); + asciidoctor.loadFile(classpathResources.getResource("ast-demo.adoc"), OptionsBuilder.options().asMap()); assertThat( ASTExtractorTreeprocessor.result.toString(), is(IOUtils.readFull(new FileReader(classpathResources.getResource("ast-demo-result.txt"))).replaceAll("\\r", ""))); - - } } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CommentPreprocessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CommentPreprocessorTest.java index 132f7c3e0..f5857bdec 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CommentPreprocessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CommentPreprocessorTest.java @@ -2,26 +2,27 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; -import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class CommentPreprocessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_render_comments_as_notes() { diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessorTest.java index ff8041cd8..c496d86f7 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessorTest.java @@ -3,19 +3,14 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; -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 static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -@RunWith(Arquillian.class) public class ContextMenuInlineMacroProcessorTest { - @ArquillianResource - private Asciidoctor asciidoctor; + private final Asciidoctor asciidoctor = Asciidoctor.Factory.create(); @Test public void should_create_context_menu() { @@ -24,7 +19,6 @@ public void should_create_context_menu() { String result = asciidoctor.convert("rightclick:New|Class[]", Options.builder().toFile(false).safe(SafeMode.UNSAFE).build()); - assertThat( result, containsString( diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CopyrightFooterPostprocessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CopyrightFooterPostprocessorTest.java index 4d28d3340..fc45450de 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CopyrightFooterPostprocessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/CopyrightFooterPostprocessorTest.java @@ -2,25 +2,27 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class CopyrightFooterPostprocessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_render_comments_as_notes() { diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/GistBlockMacroProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/GistBlockMacroProcessorTest.java index 5f41ea647..b22570ecc 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/GistBlockMacroProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/GistBlockMacroProcessorTest.java @@ -2,26 +2,27 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; -import org.asciidoctor.OptionsBuilder; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class GistBlockMacroProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_create_script_element_for_block_macro() { @@ -68,5 +69,4 @@ public void should_create_script_element_for_block_macro_with_positional_attribu "")); } - } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMacroProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMacroProcessorTest.java index 06e1372f7..a3b0dcfbf 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMacroProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMacroProcessorTest.java @@ -3,19 +3,25 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class ImageInlineMacroProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; + + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_create_context_menu() { diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMacroProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMacroProcessorTest.java index e91b3206c..44592515f 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMacroProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMacroProcessorTest.java @@ -2,25 +2,27 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class IssueInlineMacroProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_create_anchor_elements_for_inline_macros() { @@ -69,5 +71,4 @@ public void should_create_anchor_elements_for_inline_macros_with_positional_attr } - } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/KeyboardInlineMacroProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/KeyboardInlineMacroProcessorTest.java index bd9eda54f..13f848140 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/KeyboardInlineMacroProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/KeyboardInlineMacroProcessorTest.java @@ -3,21 +3,25 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; - -import java.io.File; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class KeyboardInlineMacroProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; + + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_create_keyboard_elements() { diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LoggingBlockMacroProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LoggingBlockMacroProcessorTest.java index ca7af8db7..3c703009b 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LoggingBlockMacroProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LoggingBlockMacroProcessorTest.java @@ -3,27 +3,29 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.log.LogRecord; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + -@RunWith(Arquillian.class) public class LoggingBlockMacroProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_log_from_extension() { @@ -50,5 +52,4 @@ public void should_log_from_extension() { //end::include[] } - } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LsIncludeProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LsIncludeProcessorTest.java index 02eb1584b..a728ac652 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LsIncludeProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/LsIncludeProcessorTest.java @@ -2,25 +2,27 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class LsIncludeProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_create_anchor_elements_for_inline_macros() { @@ -43,5 +45,4 @@ public void should_create_anchor_elements_for_inline_macros() { //end::include[] } - } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/RobotsDocinfoProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/RobotsDocinfoProcessorTest.java index 64eea5e13..9fa67546c 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/RobotsDocinfoProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/RobotsDocinfoProcessorTest.java @@ -3,25 +3,27 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; +import org.asciidoctor.util.ClasspathHelper; import org.jsoup.Jsoup; import org.jsoup.nodes.Element; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class RobotsDocinfoProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_create_anchor_elements_for_inline_macros() { @@ -48,5 +50,4 @@ public void should_create_anchor_elements_for_inline_macros() { //end::include[] } - } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/TerminalCommandTreeprocessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/TerminalCommandTreeprocessorTest.java index 54e28a1b2..e9383ff6d 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/TerminalCommandTreeprocessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/TerminalCommandTreeprocessorTest.java @@ -3,27 +3,29 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.OptionsBuilder; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import java.net.URL; import java.net.URLClassLoader; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -@RunWith(Arquillian.class) + public class TerminalCommandTreeprocessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_process_terminal_listings() { @@ -39,7 +41,7 @@ public void should_process_terminal_listings() { //tag::include[] File src = //... //end::include[] - classpathResources.getResource("treeprocessorcontent.adoc"); + classpathResources.getResource("treeprocessorcontent.adoc"); //tag::include[] asciidoctor.javaExtensionRegistry() @@ -68,7 +70,7 @@ public void should_process_terminal_listings_after_registering_via_extension_reg //tag::include-extension-registry[] File src = //... //end::include-extension-registry[] - classpathResources.getResource("treeprocessorcontent.adoc"); + classpathResources.getResource("treeprocessorcontent.adoc"); ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader(); @@ -80,12 +82,12 @@ public void should_process_terminal_listings_after_registering_via_extension_reg Asciidoctor asciidoctor = Asciidoctor.Factory.create(); //tag::include-extension-registry[] - String result = asciidoctor.convertFile( - src, - Options.builder() - .standalone(false) - .toFile(false) - .build()); + String result = asciidoctor.convertFile( + src, + Options.builder() + .standalone(false) + .toFile(false) + .build()); //end::include-extension-registry[] assertThat(result, is(referenceResult)); } finally { @@ -93,5 +95,4 @@ public void should_process_terminal_listings_after_registering_via_extension_reg } } - } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/YellBlockProcessorTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/YellBlockProcessorTest.java index 54867eb56..8a4688295 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/YellBlockProcessorTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/YellBlockProcessorTest.java @@ -3,28 +3,30 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; import org.asciidoctor.OptionsBuilder; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.File; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + -@RunWith(Arquillian.class) public class YellBlockProcessorTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test - public void should_invoke_block_processor() throws Exception { + public void should_invoke_block_processor() { //tag::include[] File yellblock_adoc = //... //end::include[] diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/HighlightJsHighlighterTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/HighlightJsHighlighterTest.java index c46ff8410..893fc814f 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/HighlightJsHighlighterTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/HighlightJsHighlighterTest.java @@ -5,31 +5,33 @@ import org.asciidoctor.AttributesBuilder; import org.asciidoctor.OptionsBuilder; import org.asciidoctor.SafeMode; -import org.asciidoctor.util.ClasspathResources; -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.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.io.FileReader; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertTrue; + -@RunWith(Arquillian.class) public class HighlightJsHighlighterTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @TempDir + public File tempDir; - @ArquillianResource - public TemporaryFolder tempDir; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_invoke_syntax_highlighter() { @@ -105,7 +107,7 @@ public void should_invoke_stylesheet_writing_syntax_highlighter() throws Excepti //tag::includestylesheetwriter[] File toDir = // ... //end::includestylesheetwriter[] - tempDir.newFolder(); + tempDir; //tag::includestylesheetwriter[] asciidoctor.syntaxHighlighterRegistry() diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/OrderTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/OrderTest.java index bf5a248ab..3ad2e2757 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/OrderTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/OrderTest.java @@ -4,62 +4,64 @@ import org.asciidoctor.Attributes; import org.asciidoctor.Options; import org.asciidoctor.SafeMode; -import org.asciidoctor.util.ClasspathResources; -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.asciidoctor.util.ClasspathHelper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.CleanupMode; +import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.util.stream.Collectors; import static org.apache.commons.io.FileUtils.readFileToString; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; -@RunWith(Arquillian.class) public class OrderTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @TempDir(cleanup = CleanupMode.NEVER) + public File tempDir; - @ArquillianResource - public TemporaryFolder tempDir; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_invoke_syntax_highlighter() throws Exception { File sources_adoc = //... - classpathResources.getResource("syntax-highlighting-order.adoc"); + classpathResources.getResource("syntax-highlighting-order.adoc"); String expectedHighlighterMessages = - readFileToString(classpathResources.getResource("syntax-highlighting-order-output.txt")) - .replaceAll("\r\n","\n"); + readFileToString(classpathResources.getResource("syntax-highlighting-order-output.txt")) + .replaceAll("\r\n", "\n"); File toDir = // ... - tempDir.newFolder(); + tempDir; asciidoctor.syntaxHighlighterRegistry() - .register(OrderDocumentingHighlighter.class, "order"); + .register(OrderDocumentingHighlighter.class, "order"); asciidoctor.convertFile(sources_adoc, - Options.builder() - .standalone(true) - .toDir(toDir) - .safe(SafeMode.UNSAFE) - .attributes(Attributes.builder() - .sourceHighlighter("order") - .copyCss(true) - .linkCss(true) - .build()) - .build()); + Options.builder() + .standalone(true) + .toDir(toDir) + .safe(SafeMode.UNSAFE) + .attributes(Attributes.builder() + .sourceHighlighter("order") + .copyCss(true) + .linkCss(true) + .build()) + .build()); String actual = OrderDocumentingHighlighter.messages.stream() .map(msg -> ". " + msg + "\n") .collect(Collectors.joining()); - assertEquals(expectedHighlighterMessages, actual); + assertThat(expectedHighlighterMessages).isEqualTo(actual); } } diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/PrismJsHighlighterTest.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/PrismJsHighlighterTest.java index ae8081787..a1793ac1f 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/PrismJsHighlighterTest.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/PrismJsHighlighterTest.java @@ -4,32 +4,35 @@ import org.asciidoctor.AttributesBuilder; import org.asciidoctor.OptionsBuilder; import org.asciidoctor.SafeMode; -import org.asciidoctor.util.ClasspathResources; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.arquillian.test.api.ArquillianResource; +import org.asciidoctor.util.ClasspathHelper; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.CleanupMode; +import org.junit.jupiter.api.io.TempDir; import java.io.File; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; -@RunWith(Arquillian.class) + public class PrismJsHighlighterTest { - @ArquillianResource private Asciidoctor asciidoctor; + private ClasspathHelper classpathResources; - @ArquillianResource - private ClasspathResources classpathResources; + @TempDir(cleanup = CleanupMode.NEVER) + public File tempDir; - @ArquillianResource - public TemporaryFolder tempDir; + @BeforeEach + public void beforeEach() { + asciidoctor = Asciidoctor.Factory.create(); + classpathResources = new ClasspathHelper(); + classpathResources.setClassloader(this.getClass()); + } @Test public void should_invoke_syntax_highlighter() throws Exception { @@ -41,7 +44,7 @@ public void should_invoke_syntax_highlighter() throws Exception { //tag::include[] File toDir = // ... //end::include[] - tempDir.newFolder(); + tempDir; //tag::include[] asciidoctor.syntaxHighlighterRegistry() @@ -59,7 +62,7 @@ public void should_invoke_syntax_highlighter() throws Exception { File docFile = new File(toDir, "sources.html"); - Document document = Jsoup.parse(new File(toDir, "sources.html"), "UTF-8"); + Document document = Jsoup.parse(docFile, "UTF-8"); Elements keywords = document.select("div.content pre.highlight code span.token.keyword"); // <2> assertThat(keywords, not(empty())); assertThat(keywords.first().text(), is("public")); diff --git a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/threeparams/HighlightJsHighlighter.java b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/threeparams/HighlightJsHighlighter.java index 61dc8b48f..91445f39d 100644 --- a/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/threeparams/HighlightJsHighlighter.java +++ b/asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/syntaxhighlighter/threeparams/HighlightJsHighlighter.java @@ -6,17 +6,18 @@ import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; public class HighlightJsHighlighter implements SyntaxHighlighterAdapter { //tag::include[] public HighlightJsHighlighter(String name, String backend, Map options) { - assertEquals("myhighlightjs", name); - assertEquals("html5", backend); + assertThat("myhighlightjs").isEqualTo(name); + + assertThat("html5").isEqualTo(backend); Document document = (Document) options.get("document"); - assertEquals("Syntax Highlighter Test", document.getDoctitle()); + assertThat("Syntax Highlighter Test").isEqualTo(document.getDoctitle()); } //end::include[] @@ -28,8 +29,8 @@ public boolean hasDocInfo(LocationType location) { @Override public String getDocinfo(LocationType location, Document document, Map options) { // <3> return "\n" + - "\n" + - ""; + "\n" + + ""; } } diff --git a/asciidoctorj-springboot-integration-test/build.gradle b/asciidoctorj-springboot-integration-test/build.gradle index 4c23b843c..8dcbc9ea1 100644 --- a/asciidoctorj-springboot-integration-test/build.gradle +++ b/asciidoctorj-springboot-integration-test/build.gradle @@ -2,12 +2,13 @@ jar.enabled = false dependencies { testCompileOnly project(':asciidoctorj') - testImplementation "junit:junit:$junitVersion" - testImplementation "org.assertj:assertj-core:$assertjVersion" + testImplementation "commons-io:commons-io:$commonsioVersion" testImplementation "org.awaitility:awaitility:4.2.0" - testImplementation "com.squareup.okhttp3:okhttp:4.9.3" - testImplementation "com.google.code.gson:gson:2.9.0" + testImplementation "com.squareup.okhttp3:okhttp:4.10.0" + testImplementation "com.google.code.gson:gson:2.10.1" } -test.dependsOn(':asciidoctorj-springboot-integration-test:springboot-app:assemble') +tasks.withType(Test) { + dependsOn(':asciidoctorj-springboot-integration-test:springboot-app:assemble') +} diff --git a/asciidoctorj-springboot-integration-test/springboot-app/build.gradle b/asciidoctorj-springboot-integration-test/springboot-app/build.gradle index 215697699..a313ab83c 100644 --- a/asciidoctorj-springboot-integration-test/springboot-app/build.gradle +++ b/asciidoctorj-springboot-integration-test/springboot-app/build.gradle @@ -40,7 +40,3 @@ def getToolchainVersion() { bootJar { requiresUnpack '**/asciidoctorj-*.jar' } - -test { - useJUnitPlatform() -} diff --git a/asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/SpringBootTest.java b/asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/SpringBootTest.java index 87e2244b2..38771f181 100644 --- a/asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/SpringBootTest.java +++ b/asciidoctorj-springboot-integration-test/src/test/java/org/asciidoctor/it/springboot/SpringBootTest.java @@ -5,8 +5,8 @@ import kotlin.collections.ArrayDeque; import okhttp3.*; import org.awaitility.Awaitility; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -16,7 +16,6 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; -import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static org.asciidoctor.it.springboot.ProcessHelper.run; import static org.assertj.core.api.Assertions.assertThat; @@ -49,7 +48,7 @@ public void should_start_SpringBoot_service_with_requiresUnpack() throws IOExcep .contains("

Second chapter

"); } - @After + @AfterEach public void cleanup() { testProcesses.forEach(Process::destroy); } diff --git a/asciidoctorj-test-support/build.gradle b/asciidoctorj-test-support/build.gradle index a7830ca3d..eafd4f734 100644 --- a/asciidoctorj-test-support/build.gradle +++ b/asciidoctorj-test-support/build.gradle @@ -1,7 +1,7 @@ apply plugin: 'java' dependencies { - api "junit:junit:${junitVersion}" + api "junit:junit:${junit4Version}" } def javaApiUrl = "https://docs.oracle.com/javase/8/docs/api/" diff --git a/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathHelper.java b/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathHelper.java index 520ba5b36..06fc289c2 100644 --- a/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathHelper.java +++ b/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathHelper.java @@ -6,22 +6,21 @@ import java.net.URL; /** - * Hels getting files from the classpath. + * Helps to get files from the classpath. */ public class ClasspathHelper { private ClassLoader classloader; /** - * Gets a resourse in a similar way as {@link File#File(String)} + * Gets a resource in a similar way as {@link File#File(String)} */ public File getResource(String pathname) { try { URL resource = classloader.getResource(pathname); if (resource != null) { return new File(classloader.getResource(pathname).toURI()); - } - else { + } else { throw new RuntimeException(new FileNotFoundException(pathname)); } } catch (URISyntaxException e) { @@ -30,7 +29,7 @@ public File getResource(String pathname) { } /** - * Gets a resourse in a similar way as {@link File#File(String, String)} + * Gets a resource in a similar way as {@link File#File(String, String)} */ public File getResource(String parent, String child) { return new File(getResource(parent), child); @@ -43,7 +42,7 @@ public ClassLoader getClassloader() { public void setClassloader(ClassLoader classloader) { this.classloader = classloader; } - + public void setClassloader(Class clazz) { this.classloader = clazz.getClassLoader(); } diff --git a/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java b/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java index 6daeb2b85..abf81ba38 100644 --- a/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java +++ b/asciidoctorj-test-support/src/main/java/org/asciidoctor/util/ClasspathResources.java @@ -6,12 +6,13 @@ /** * JUnit TestRule to handle classpath files. - * - * Delegates to {@link ClasspathHelper} + *

+ * Delegates to {@link ClasspathHelper}. */ public class ClasspathResources extends ClasspathHelper implements TestRule { - public ClasspathResources() {} + public ClasspathResources() { + } public ClasspathResources(Class clazz) { setClassloader(clazz); diff --git a/asciidoctorj-wildfly-integration-test/build.gradle b/asciidoctorj-wildfly-integration-test/build.gradle index 4c0cde00b..99730186d 100644 --- a/asciidoctorj-wildfly-integration-test/build.gradle +++ b/asciidoctorj-wildfly-integration-test/build.gradle @@ -2,7 +2,6 @@ jar.enabled = false ext { arquillianWildflyVersion = '3.0.1.Final' - wildflyVersion = '26.0.1.Final' } @@ -28,12 +27,13 @@ dependencies { jbossdist group: 'org.wildfly', name: 'wildfly-dist', version: wildflyVersion, ext: 'zip' - testImplementation "javax:javaee-api:7.0" testCompileOnly project(':asciidoctorj') - testImplementation "junit:junit:$junitVersion" - testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion" - testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion" + testImplementation "javax:javaee-api:7.0" + // Arquillian Unit5 support requires 1.7.0.Alpha5 + // https://github.com/arquillian/arquillian-core/issues/137#issuecomment-726596414 + testImplementation("org.junit.vintage:junit-vintage-engine") testImplementation "org.jsoup:jsoup:$jsoupVersion" + testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion" testRuntimeOnly "org.wildfly.arquillian:wildfly-arquillian-container-managed:$arquillianWildflyVersion" } @@ -74,10 +74,7 @@ task createModule(type: Copy) { dependsOn createModuleDescriptor } - test { - useJUnit() - testLogging { // events 'passed', 'failed', 'skipped', 'standard_out', 'standard_error' // events 'standard_out', 'standard_error' @@ -105,7 +102,6 @@ test { systemProperty('arquillian.launch', 'wildfly-java11') } - dependsOn createModule dependsOn unpackWildfly dependsOn configurations.jbossmodule diff --git a/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/WildflyIntegrationTest.java b/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/WildflyIntegrationTest.java index 5717490ca..b494ee2cb 100644 --- a/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/WildflyIntegrationTest.java +++ b/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/WildflyIntegrationTest.java @@ -1,6 +1,5 @@ package org.asciidoctor; -import org.asciidoctor.categories.Wildfly; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.junit.Arquillian; @@ -11,7 +10,6 @@ import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.junit.Test; -import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.io.File; @@ -20,18 +18,17 @@ import java.net.URL; import java.util.Scanner; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(Arquillian.class) @RunAsClient -@Category(Wildfly.class) public class WildflyIntegrationTest { @Deployment public static WebArchive deploy() { return ShrinkWrap.create(WebArchive.class) - .addClasses(AsciidoctorServlet.class) - .setManifest(new File("src/test/resources/MANIFEST.MF")); + .addClasses(AsciidoctorServlet.class) + .setManifest(new File("src/test/resources/MANIFEST.MF")); } @ArquillianResource @@ -44,18 +41,14 @@ public void test() throws Exception { conn.setRequestMethod("POST"); conn.getOutputStream().write("Hello World".getBytes()); - byte[] buf = new byte[65535]; try (InputStream in = conn.getInputStream()) { - final Document doc = Jsoup.parse(readFull(in)); final Element first = doc.body().children().first(); - assertEquals("div", first.tagName()); - assertEquals("paragraph", first.className()); + assertThat(first.tagName()).isEqualTo("div"); + assertThat(first.className()).isEqualTo("paragraph"); final Element paragraph = first.children().first(); - assertEquals("p", paragraph.tagName()); - assertEquals("Hello World", paragraph.ownText()); - - + assertThat(paragraph.tagName()).isEqualTo("p"); + assertThat(paragraph.ownText()).isEqualTo("Hello World"); } } diff --git a/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/categories/Wildfly.java b/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/categories/Wildfly.java deleted file mode 100644 index b7685be3d..000000000 --- a/asciidoctorj-wildfly-integration-test/src/test/java/org/asciidoctor/categories/Wildfly.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.asciidoctor.categories; - -public class Wildfly { -} diff --git a/build.gradle b/build.gradle index b2d60624b..ee6e9ff6b 100644 --- a/build.gradle +++ b/build.gradle @@ -73,8 +73,9 @@ ext { jcommanderVersion = '1.82' jrubyVersion = '9.4.1.0' jsoupVersion = '1.14.3' - junitVersion = '4.13.2' - assertjVersion = '3.23.1' + junit4Version = '4.13.2' + junit5Version = '5.9.2' + assertjVersion = '3.24.2' nettyVersion = '4.1.58.Final' saxonVersion = '9.9.0-2' xmlMatchersVersion = '1.0-RC1' @@ -86,14 +87,14 @@ ext { coderayGemVersion = '1.1.3' rougeGemVersion = '3.30.0' - codenarcVersion = '2.1.0' - groovyVersion = '2.4.21' + codenarcVersion = '3.2.0' + groovyVersion = '3.0.17' erubisGemVersion = '2.7.0' hamlGemVersion = '5.2.2' openUriCachedGemVersion = '0.0.5' slimGemVersion = '4.1.0' concurrentRubyGemVersion = '1.1.7' - spockVersion = '1.3-groovy-2.4' + spockVersion = '2.3-groovy-3.0' threadSafeGemVersion = '0.3.6' tiltGemVersion = '2.0.11' osgiVersion = '7.0.0' @@ -112,7 +113,6 @@ subprojects { status = _status - plugins.withType(JavaPlugin) { project.tasks.withType(JavaCompile) { task -> if (project.hasProperty("showDeprecation")) { @@ -131,35 +131,60 @@ subprojects { mavenCentral() } - apply plugin: 'codenarc' - codenarc { - configFile = rootProject.file('config/codenarc/codenarc.groovy') + dependencies { + testImplementation(platform("org.junit:junit-bom:$junit5Version")) + testImplementation("org.junit.jupiter:junit-jupiter-api") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine") + + testImplementation "org.assertj:assertj-core:$assertjVersion" + testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion" } - if (!isIntegrationTestProject(it)) { + if (usesSpock(it)) { + apply plugin: 'codenarc' + + codenarc { + configFile = rootProject.file('config/codenarc/codenarc.groovy') + } dependencies { - testImplementation "junit:junit:$junitVersion" - testImplementation "org.assertj:assertj-core:$assertjVersion" - testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion" testImplementation("org.spockframework:spock-core:$spockVersion") { exclude group: 'org.hamcrest', module: 'hamcrest-core' } testImplementation "org.codehaus.groovy:groovy-all:$groovyVersion" - testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion" - testImplementation "org.jboss.arquillian.spock:arquillian-spock-container:$arquillianSpockVersion" - codenarc "org.codehaus.groovy:groovy:$groovyVersion" - codenarc "org.codehaus.groovy:groovy-xml:$groovyVersion" - codenarc "org.codehaus.groovy:groovy-ant:$groovyVersion" - codenarc("org.codenarc:CodeNarc:$codenarcVersion") { - exclude group: 'org.codehaus.groovy' + testRuntimeOnly("org.junit.vintage:junit-vintage-engine") + + codenarc("org.codenarc:CodeNarc:$codenarcVersion") + + constraints { + ["groovy", + "groovy-ant", + "groovy-groovydoc", + "groovy-json", + "groovy-xml", + ].each { + codenarc ("org.codehaus.groovy:$it") { + version { + strictly "$groovyVersion" + because "Use same groovy version as project" + } + } + } } } } + if (usesArquillian(it)) { + dependencies { + testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion" + testImplementation "org.jboss.arquillian.spock:arquillian-spock-container:$arquillianSpockVersion" + } + } test { + useJUnitPlatform() + forkEvery = 10 minHeapSize = '128m' maxHeapSize = '1024m' @@ -177,19 +202,21 @@ subprojects { } -boolean isIntegrationTestProject(def project) { - project.name in ['asciidoctorj-wildfly-integration-test', - 'asciidoctorj-springboot-integration-test', - 'springboot-app'] +boolean usesSpock(def project) { + project.name in ['asciidoctorj'] } +boolean usesArquillian(def project) { + project.name in ['asciidoctorj'] +} + + // apply JRuby and sources/javadocs packaging stuff for all subprojects except the distribution configure(subprojects.findAll { !it.isDistribution() }) { apply from: rootProject.file('gradle/eclipse.gradle') apply plugin: 'idea' - javadoc { // Oracle JDK11+ likes to fail the build over spoiled HTML options.addStringOption('Xdoclint:none', '-quiet')