From f498c3322dee123c6b1c7b1f00a77030762eb4cf Mon Sep 17 00:00:00 2001 From: Abel Salgado Romero Date: Sun, 3 Sep 2023 19:02:27 +0200 Subject: [PATCH] Migrate test to JUnit 5 and AssertJ * Remove Goorvy/Spock un-necessary build config * Remove un-used AppVeyor * Remove un-used Bintray from build --- CHANGELOG.adoc | 1 + README.adoc | 3 - appveyor.yml | 20 ------ .../org/asciidoctor/WhenBackendIsPdf.java | 64 +++++++++---------- .../org/asciidoctor/util/RougeColors.java | 2 + .../java/org/asciidoctor/util/pdf/Image.java | 2 +- build.gradle | 19 +++--- gradle/deploy.gradle | 51 --------------- .../diagram/WhenDitaaDiagramIsRendered.java | 16 ++--- 9 files changed, 51 insertions(+), 127 deletions(-) delete mode 100644 appveyor.yml delete mode 100644 gradle/deploy.gradle diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ba50009..60fb422 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -16,3 +16,4 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co Improvement:: * Remove 'rouge' gem, already provided by AsciidoctorJ (#87) (@abelsromero) +* Migrate test to JUnit 5 and AssertJ (#97) (@abelsromero) diff --git a/README.adoc b/README.adoc index d62b338..9c0202a 100644 --- a/README.adoc +++ b/README.adoc @@ -25,9 +25,6 @@ ifndef::awestruct[:uri-docs: http://asciidoctor.org/docs] :uri-maven-artifact-query: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.asciidoctor%22%20AND%20a%3A%22asciidoctorj%22%20AND%20v%3A%22{artifact-version}%22 :uri-maven-artifact-detail: http://search.maven.org/#artifactdetails%7Corg.asciidoctor%7Casciidoctorj%7C{artifact-version}%7Cjar :uri-maven-artifact-file: http://search.maven.org/remotecontent?filepath=org/asciidoctor/asciidoctorj/{artifact-version}/asciidoctorj-{artifact-version} -:uri-bintray-artifact-query: https://bintray.com/asciidoctor/maven/asciidoctorj/view/general -:uri-bintray-artifact-detail: https://bintray.com/asciidoctor/maven/asciidoctorj/{artifact-version}/view -:uri-bintray-artifact-file: http://dl.bintray.com/asciidoctor/maven/org/asciidoctor/asciidoctorj/{artifact-version}/asciidoctorj-{artifact-version} :uri-jruby-startup: http://github.com/jruby/jruby/wiki/Improving-startup-time :uri-maven-guide: {uri-docs}/install-and-use-asciidoctor-maven-plugin :uri-gradle-guide: {uri-docs}/install-and-use-asciidoctor-gradle-plugin diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d5524c2..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,20 +0,0 @@ -version: '{build}' -skip_tags: true -skip_commits: - message: /\[ci skip\]/ -clone_depth: 10 -environment: - TERM: dumb - matrix: - - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 -install: - - SET PATH=%JAVA_HOME%\bin;%PATH% - # remove Ruby entry (C:\Ruby193\bin;) from PATH - - SET PATH=%PATH:C:\Ruby193\bin;=% - - echo %PATH% - - java -version - - gradlew.bat --version -build_script: - - gradlew.bat -u -i assemble -test_script: - - gradlew.bat -u -i -S check diff --git a/asciidoctorj-pdf/src/test/java/org/asciidoctor/WhenBackendIsPdf.java b/asciidoctorj-pdf/src/test/java/org/asciidoctor/WhenBackendIsPdf.java index 685a097..723905c 100644 --- a/asciidoctorj-pdf/src/test/java/org/asciidoctor/WhenBackendIsPdf.java +++ b/asciidoctorj-pdf/src/test/java/org/asciidoctor/WhenBackendIsPdf.java @@ -1,33 +1,35 @@ package org.asciidoctor; -import org.apache.pdfbox.pdmodel.graphics.color.PDColor; import org.asciidoctor.util.RougeColors; import org.asciidoctor.util.pdf.ColorsProcessor; +import org.asciidoctor.util.pdf.Image; import org.asciidoctor.util.pdf.ImageProcessor; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.awt.*; import java.io.File; import java.io.IOException; +import java.util.Arrays; import java.util.List; import java.util.Map; -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.asciidoctor.util.RougeColors.DARK_CHARCOAL; +import static org.assertj.core.api.Assertions.assertThat; -public class WhenBackendIsPdf { + +class WhenBackendIsPdf { private Asciidoctor asciidoctor; - @Before - public void initAsciidoctor() { + @BeforeEach + void initAsciidoctor() { this.asciidoctor = Asciidoctor.Factory.create(); } @Test - public void pdf_should_include_images() throws IOException { + void pdf_should_include_images() throws IOException { String filename = "image-sample"; File inputFile = new File("build/resources/test/" + filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); @@ -35,15 +37,15 @@ public void pdf_should_include_images() throws IOException { asciidoctor.convertFile(inputFile, Options.builder().backend("pdf").safe(SafeMode.UNSAFE).build()); - 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)); + List images = imageProcessor.getImages(); + assertThat(images).hasSize(2); } @Test - public void pdf_source_code_should_be_highlighted() throws IOException { + void pdf_source_code_should_be_highlighted() throws IOException { String filename = "code-sample"; File inputFile = new File("build/resources/test/" + filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); @@ -51,23 +53,23 @@ public void pdf_source_code_should_be_highlighted() throws IOException { asciidoctor.convertFile(inputFile, Options.builder().backend("pdf").safe(SafeMode.UNSAFE).build()); - assertThat(outputFile1.exists(), is(true)); + assertThat(outputFile1).exists(); 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); } @Test - public void pdf_text_should_be_hyphenated_german() throws IOException { + void pdf_text_should_be_hyphenated_german() throws IOException { String filename = "hyphenation-de-sample"; File inputFile = new File("build/resources/test/" + filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); @@ -75,16 +77,15 @@ public void pdf_text_should_be_hyphenated_german() throws IOException { asciidoctor.convertFile(inputFile, Options.builder().backend("pdf").safe(SafeMode.UNSAFE).build()); - assertThat(outputFile1.exists(), is(true)); + assertThat(outputFile1).exists(); ColorsProcessor colorsProcessor = new ColorsProcessor("Feh\u00adler"); colorsProcessor.parse(outputFile1.getAbsolutePath()); - Map> words = colorsProcessor.getColors(); - assertThat(words.keySet(), hasItem("Feh\u00adler")); + assertThat(colorsProcessor.getColors()).containsEntry("Feh\u00adler", Arrays.asList(DARK_CHARCOAL)); } @Test - public void pdf_text_should_be_hyphenated_english() throws IOException { + void pdf_text_should_be_hyphenated_english() throws IOException { String filename = "hyphenation-en-sample"; File inputFile = new File("build/resources/test/" + filename + ".adoc"); File outputFile1 = new File(inputFile.getParentFile(), filename + ".pdf"); @@ -92,19 +93,16 @@ public void pdf_text_should_be_hyphenated_english() throws IOException { asciidoctor.convertFile(inputFile, Options.builder().backend("pdf").safe(SafeMode.UNSAFE).build()); - assertThat(outputFile1.exists(), is(true)); + assertThat(outputFile1).exists(); ColorsProcessor colorsProcessor = new ColorsProcessor("van\u00adquish"); colorsProcessor.parse(outputFile1.getAbsolutePath()); - Map> words = colorsProcessor.getColors(); - assertThat(words.keySet(), hasItem("van\u00adquish")); + assertThat(colorsProcessor.getColors()).containsKey("van\u00adquish"); } private void removeFileIfItExists(File file) throws IOException { - if (file.exists()) { - if (!file.delete()) { - throw new IOException("Can't delete file"); - } + if (file.exists() && !file.delete()) { + throw new IOException("Can't delete file: " + file.getAbsolutePath()); } } } diff --git a/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/RougeColors.java b/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/RougeColors.java index 236c941..72ac931 100644 --- a/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/RougeColors.java +++ b/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/RougeColors.java @@ -19,4 +19,6 @@ public final class RougeColors { public static final Color PINK = new Color(187,0,102); + public static final Color DARK_CHARCOAL = new Color(51,51,51); + } diff --git a/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/pdf/Image.java b/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/pdf/Image.java index d7fdcf7..c97fc4a 100644 --- a/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/pdf/Image.java +++ b/asciidoctorj-pdf/src/test/java/org/asciidoctor/util/pdf/Image.java @@ -5,7 +5,7 @@ * * @author abelsromero */ -final class Image { +public final class Image { // Page where the image is localed private final int page; diff --git a/build.gradle b/build.gradle index 1107f3c..7adf6ab 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ adding the plugin jars to the classpath to apply them later. currently the new plugins DSL does apply them directly. there are other limitations too. See https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block - we don't need to apply the jruby and bintray plugin on the rootProject. + we don't need to apply the jruby plugin on the rootProject. */ buildscript { repositories { @@ -31,12 +31,10 @@ ext { statusIsRelease = (status == 'release') // jar versions - arquillianVersion = '1.1.10.Final' - arquillianSpockVersion = '1.0.0.Beta3' jrubyVersion = '9.4.0.0' pdfboxVersion = '3.0.0' - junitVersion = '4.13.2' - hamcrestVersion = '2.2' + junitVersion = '5.10.0' + assertjVersion = '3.24.2' // gem versions asciidoctorJVersion = project.hasProperty('asciidoctorJVersion') ? project.asciidoctorJVersion : '2.5.7' @@ -47,7 +45,6 @@ ext { public_suffixVersion = '1.4.6' prawnGemVersion=project.hasProperty('prawnGemVersion') ? project.prawnGemVersion : '2.4.0' rghostGemVersion = '0.9.7' - spockVersion = '0.7-groovy-2.0' threadSafeGemVersion = '0.3.6' ttfunkGemVersion = '1.7.0' cssParserGemVersion = '1.12.0' @@ -63,7 +60,6 @@ subprojects { // NOTE applying Java plugin changes the status; take steps to preserve value def _status = status apply plugin: 'java' - apply plugin: 'groovy' apply from: "$rootDir/gradle/providedConfiguration.gradle" status = _status @@ -100,13 +96,14 @@ subprojects { } dependencies { - testImplementation "junit:junit:$junitVersion" - testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion" - testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion" - testImplementation "org.jboss.arquillian.spock:arquillian-spock-container:$arquillianSpockVersion" + testImplementation(platform("org.junit:junit-bom:$junitVersion")) + testImplementation "org.junit.jupiter:junit-jupiter-api" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" + testImplementation "org.assertj:assertj-core:$assertjVersion" } test { + useJUnitPlatform() forkEvery = 10 minHeapSize = '128m' maxHeapSize = '1024m' diff --git a/gradle/deploy.gradle b/gradle/deploy.gradle deleted file mode 100644 index 3c3724b..0000000 --- a/gradle/deploy.gradle +++ /dev/null @@ -1,51 +0,0 @@ -apply plugin: 'com.jfrog.bintray' - -bintray { - user = System.env['BINTRAY_USER'] ?: (project.hasProperty('bintrayUsername') ? project.bintrayUsername : '') - key = System.env['BINTRAY_KEY'] ?: (project.hasProperty('bintrayApiKey') ? project.bintrayApiKey : '') - - publications = ['jars'] - - if ( !project.hasProperty('skip.signing') ) { - // Copy the signed pom to bintrayDestination - filesSpec { - from signPom - into signPom.bintrayDestination - } - bintrayUpload.dependsOn signPom - } - - dryRun = project.hasProperty('dryRun') && project.dryRun.toBoolean() - publish = project.statusIsRelease - - pkg { - repo = System.env['BINTRAY_REPO'] ?: (project.hasProperty('bintrayRepo') ? project.bintrayRepo : 'maven') - if (!project.hasProperty('bintrayPersonal')) { - userOrg = 'asciidoctor' - } - - name = project.name - desc = project.description - - // NOTE use this instead if we want to list all artifacts under the same package - //name = project(':asciidoctorj').name - //desc = project(':asciidoctorj').description - - licenses = ['Apache-2.0'] - labels = ['asciidoctor', 'asciidoctorj', 'asciidoc'] - websiteUrl = 'https://github.com/asciidoctor/asciidoctorj-pdf/blob/main/README.adoc' - issueTrackerUrl = 'https://github.com/asciidoctor/asciidoctorj-pdf/issues' - vcsUrl = 'https://github.com/asciidoctor/asciidoctorj-pdf' - publicDownloadNumbers = true - - version { - name = project.version - // NOTE customize the vcsTag if you're only releasing a subproject - vcsTag = "${rootProject.name}-${rootProject.version}" - //released = "$buildDateOnly" - // desc = ... - } - } -} - -bintrayUpload.dependsOn build diff --git a/itest/src/test/java/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.java b/itest/src/test/java/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.java index 9e3451c..cb75f15 100644 --- a/itest/src/test/java/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.java +++ b/itest/src/test/java/org/asciidoctor/diagram/WhenDitaaDiagramIsRendered.java @@ -2,20 +2,20 @@ import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.UUID; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.io.FileMatchers.anExistingFile; +import static org.assertj.core.api.Assertions.assertThat; -public class WhenDitaaDiagramIsRendered { + +class WhenDitaaDiagramIsRendered { static final String ASCIIDOCTOR_DIAGRAM = "asciidoctor-diagram"; @Test - public void should_render_ditaa_diagram_to_PDF() { + void should_render_ditaa_diagram_to_PDF() { final Asciidoctor asciidoctor = Asciidoctor.Factory.create(); @@ -40,10 +40,10 @@ public void should_render_ditaa_diagram_to_PDF() { .backend("pdf") .build()); - assertThat(new File(destinationFileName), anExistingFile()); + assertThat(new File(destinationFileName)).exists(); File png = new File("build", imageFileName + ".png"); - assertThat(png, anExistingFile()); + assertThat(png).exists(); File pngCache = new File("build/.asciidoctor/diagram/", imageFileName + ".png.cache"); - assertThat(pngCache, anExistingFile()); + assertThat(pngCache).exists(); } }