Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump JUnit to v5 and remove unused build elements #97

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
3 changes: 0 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions appveyor.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,110 +1,108 @@
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");
removeFileIfItExists(outputFile1);

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<Image> 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");
removeFileIfItExists(outputFile1);

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", "<body>", "else", "Math.sqrt");
colorsProcessor.parse(outputFile1.getAbsolutePath());
Map<String, List<Color>> 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("<body>").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("<body>").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");
removeFileIfItExists(outputFile1);

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<String, List<Color>> 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");
removeFileIfItExists(outputFile1);

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<String, List<Color>> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* @author abelsromero
*/
final class Image {
public final class Image {

// Page where the image is localed
private final int page;
Expand Down
19 changes: 8 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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'
Expand Down
51 changes: 0 additions & 51 deletions gradle/deploy.gradle

This file was deleted.

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

Expand All @@ -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();
}
}