Skip to content

Commit

Permalink
Set Junit5 as default test engine
Browse files Browse the repository at this point in the history
* Remove use of Arquillian Sputnik components: not compatible
  • Loading branch information
abelsromero committed Apr 22, 2023
1 parent f1625ce commit f9cb8d7
Show file tree
Hide file tree
Showing 76 changed files with 773 additions and 905 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -31,14 +30,19 @@ public class WhenAsciidoctorIsCalledUsingCli {

private static final String SOURCE_EXTENSION_PATTERN = "\\.asciidoc$";

@ArquillianResource
private ClasspathResources classpath;
private ClasspathHelper classpath;

@ArquillianResource
public TemporaryFolder temporaryFolder;
@TempDir
public File temporaryFolder;

public String pwd = new File("").getAbsolutePath();

@BeforeAll
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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions asciidoctorj-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jar {
}

test {
useJUnit {
excludeCategories 'org.asciidoctor.categories.Polluted'
useJUnitPlatform() {
excludeTags("polluted")
}
}

Expand All @@ -119,8 +119,8 @@ version.asciidoctor: $asciidoctorGemVersion
jar.dependsOn createVersionFile

task pollutedTest(type: Test) {
useJUnit {
includeCategories 'org.asciidoctor.categories.Polluted'
useJUnitPlatform() {
includeTags 'polluted'
}
forkEvery = 10
minHeapSize = '128m'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -106,6 +101,7 @@ Hello, World!
TestConverter(String backend, Map<String, Object> opts) {
super(backend, opts)
}

@Override
String convert(ContentNode node, String transform, Map<Object, Object> opts) {
if (transform == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {

Expand Down Expand Up @@ -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"]
|===
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,18 @@ 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
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'() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {

Expand Down
Loading

0 comments on commit f9cb8d7

Please sign in to comment.