Skip to content

Commit cd58160

Browse files
authored
Merge pull request #23 from abelsromero/chore/bump-versions
Remove unused gradle properties & migrate tests to Junit5
2 parents 2b3f27a + 5b9b7a6 commit cd58160

File tree

4 files changed

+59
-69
lines changed

4 files changed

+59
-69
lines changed
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
package org.asciidoctor;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

55
import java.io.File;
66

7-
import static org.asciidoctor.OptionsBuilder.options;
8-
import static org.hamcrest.CoreMatchers.is;
9-
import static org.junit.Assert.assertThat;
7+
import static org.assertj.core.api.Assertions.assertThat;
108

119
public class WhenDocumentContainsDitaaDiagram {
1210

1311
private Asciidoctor asciidoctor = Asciidoctor.Factory.create();
1412

1513
@Test
1614
public void png_should_be_rendered_for_diagram() {
15+
File sourceDir = new File("build/resources/test");
16+
File inputFile = new File(sourceDir, "sample.adoc");
1717

18-
File buildDir = new File("build/resources/test");
18+
File outputDiagram = new File(sourceDir, "asciidoctor-diagram-process.png");
19+
File outputDiagramCache = new File(sourceDir, ".asciidoctor/diagram/asciidoctor-diagram-process.png.cache");
1920

20-
File inputFile = new File(buildDir, "sample.adoc");
21-
File outputFile1 = new File(inputFile.getParentFile(), "asciidoctor-diagram-process.png");
22-
File outputFile2 = new File(inputFile.getParentFile(), ".asciidoctor/diagram/asciidoctor-diagram-process.png.cache");
2321
asciidoctor.requireLibrary("asciidoctor-diagram");
2422
asciidoctor.convertFile(inputFile,
25-
options()
26-
.backend("html5")
27-
.toFile(new File(buildDir, "sample.html"))
28-
.get());
29-
assertThat(outputFile1.exists(), is(true));
30-
assertThat(outputFile2.exists(), is(true));
31-
outputFile1.delete();
32-
outputFile2.delete();
23+
Options.builder()
24+
.backend("html5")
25+
.toFile(new File(sourceDir, "sample.html"))
26+
.build());
27+
28+
assertThat(outputDiagram).exists();
29+
assertThat(outputDiagramCache).exists();
3330
}
3431
}

asciidoctorj-diagram/src/test/java/org.asciidoctor/WhenDocumentWantsDataUris.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,48 @@
33
import org.jsoup.Jsoup;
44
import org.jsoup.nodes.Document;
55
import org.jsoup.select.Elements;
6-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
77

88
import java.io.File;
99
import java.io.IOException;
1010
import java.nio.charset.StandardCharsets;
1111
import java.nio.file.Files;
1212

13-
import static org.asciidoctor.OptionsBuilder.options;
14-
import static org.hamcrest.CoreMatchers.is;
15-
import static org.hamcrest.CoreMatchers.startsWith;
16-
import static org.junit.Assert.assertEquals;
17-
import static org.junit.Assert.assertThat;
13+
import static org.assertj.core.api.Assertions.assertThat;
1814

1915
public class WhenDocumentWantsDataUris {
2016

2117
private Asciidoctor asciidoctor = Asciidoctor.Factory.create();
2218

2319
@Test
2420
public void png_should_be_rendered_for_diagram() throws IOException {
25-
File buildDir = new File("build/resources/test");
21+
File sourceDir = new File("build/resources/test");
22+
File inputFile = new File(sourceDir, "data-uri.adoc");
23+
24+
File expectedOutput = new File(sourceDir, "data-uri.html");
25+
File expectedDiagram = new File(sourceDir, "data-uri-test.png");
26+
File expectedDiagramCache = new File(sourceDir, ".asciidoctor/diagram/data-uri-test.png.cache");
2627

27-
File inputFile = new File(buildDir, "data-uri.adoc");
28-
File outputFile = new File(buildDir, "data-uri.html");
29-
File outputFile1 = new File(inputFile.getParentFile(), "data-uri-test.png");
30-
File outputFile2 = new File(inputFile.getParentFile(), ".asciidoctor/diagram/data-uri-test.png.cache");
3128
asciidoctor.requireLibrary("asciidoctor-diagram");
3229
asciidoctor.convertFile(inputFile,
33-
options().backend("html5")
34-
.toFile(outputFile)
35-
.safe(SafeMode.SERVER)
36-
.get());
37-
assertThat(outputFile1.exists(), is(true));
38-
assertThat(outputFile2.exists(), is(true));
39-
outputFile1.delete();
40-
outputFile2.delete();
41-
42-
String html = new String(Files.readAllBytes(outputFile.toPath()), StandardCharsets.UTF_8);
43-
final Document doc = Jsoup.parse(html);
44-
System.out.println(doc);
30+
Options.builder()
31+
.backend("html5")
32+
.mkDirs(true)
33+
.toFile(expectedOutput)
34+
.safe(SafeMode.SERVER)
35+
.build());
36+
37+
assertThat(expectedOutput).isNotEmpty();
38+
assertThat(expectedDiagram).exists();
39+
assertThat(expectedDiagramCache).exists();
40+
41+
final Document doc = Jsoup.parse(readString(expectedOutput));
4542
Elements images = doc.getElementsByTag("img");
46-
assertEquals(1, images.size());
47-
assertThat(images.get(0).attr("src"), startsWith("data:image/png;base64,"));
43+
assertThat(images).hasSize(1);
44+
assertThat(images.get(0).attr("src")).startsWith("data:image/png;base64,");
45+
}
4846

47+
private String readString(File outputFile) throws IOException {
48+
return new String(Files.readAllBytes(outputFile.toPath()), StandardCharsets.UTF_8);
4949
}
5050
}

build.gradle

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,14 @@ ext {
4545
statusIsRelease = (status == 'release')
4646

4747
// jar versions
48-
arquillianVersion = '1.1.10.Final'
49-
arquillianSpockVersion = '1.0.0.Beta3'
50-
commonsioVersion = '2.4'
51-
guavaVersion = '18.0'
52-
hamcrestVersion = '2.2'
5348
jrubyVersion = '9.2.4.0'
54-
junitVersion = '4.13.2'
55-
jsoupVersion = '1.11.2'
56-
saxonVersion = '9.5.1-6'
57-
xmlMatchersVersion = '1.0-RC1'
58-
pdfboxVersion = '1.8.10'
49+
junitVersion = '5.8.2'
50+
assertjVersion = '3.22.0'
51+
jsoupVersion = '1.14.3'
5952

6053
// gem versions
61-
asciidoctorJVersion = project.hasProperty('asciidoctorJVersion') ? project.asciidoctorJVersion : '2.4.3'
54+
asciidoctorJVersion = project.hasProperty('asciidoctorJVersion') ? project.asciidoctorJVersion : '2.5.3'
6255
asciidoctorDiagramGemVersion = project.hasProperty('asciidoctorDiagramGemVersion') ? project.asciidoctorDiagramGemVersion : project(':asciidoctorj-diagram').version.replace('-', '.')
63-
6456
}
6557

6658
allprojects {
@@ -102,17 +94,18 @@ subprojects {
10294
}
10395

10496
dependencies {
105-
testImplementation "junit:junit:$junitVersion"
106-
testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion"
107-
testImplementation "org.jboss.arquillian.junit:arquillian-junit-container:$arquillianVersion"
108-
97+
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
98+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
99+
testImplementation "org.assertj:assertj-core:$assertjVersion"
109100
}
101+
110102
apply plugin: 'codenarc'
111103
codenarc {
112104
configFile = rootProject.file('config/codenarc/codenarc.groovy')
113105
}
114106

115107
test {
108+
useJUnitPlatform()
116109
forkEvery = 10
117110
minHeapSize = '128m'
118111
maxHeapSize = '1024m'
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package org.asciidoctor;
22

3-
import org.junit.Test;
3+
import org.junit.jupiter.api.Test;
44

55
import java.io.File;
66

7-
import static org.asciidoctor.OptionsBuilder.options;
8-
import static org.hamcrest.CoreMatchers.is;
9-
import static org.junit.Assert.assertThat;
7+
import static org.assertj.core.api.Assertions.assertThat;
108

119
public class WhenDocumentContainsDitaaDiagram {
1210

@@ -15,14 +13,16 @@ public class WhenDocumentContainsDitaaDiagram {
1513
@Test
1614
public void png_should_be_rendered_for_diagram() {
1715

18-
File inputFile = new File("src/test/resources/sample.adoc");
19-
File outputFile1 = new File(inputFile.getParentFile(), "asciidoctor-diagram-process.png");
20-
File outputFile2 = new File(inputFile.getParentFile(), ".asciidoctor/diagram/asciidoctor-diagram-process.png.cache");
16+
File sourceDir = new File("build/resources/test");
17+
18+
File sourceDocument = new File(sourceDir, "sample.adoc");
19+
File expectedDiagram = new File(sourceDir, "asciidoctor-diagram-process.png");
20+
File expectedDiagramCache = new File(sourceDir, ".asciidoctor/diagram/asciidoctor-diagram-process.png.cache");
21+
2122
asciidoctor.requireLibrary("asciidoctor-diagram");
22-
asciidoctor.convertFile(inputFile, options().backend("html5").get());
23-
assertThat(outputFile1.exists(), is(true));
24-
assertThat(outputFile2.exists(), is(true));
25-
outputFile1.delete();
26-
outputFile2.delete();
23+
asciidoctor.convertFile(sourceDocument, Options.builder().backend("html5").build());
24+
25+
assertThat(expectedDiagram).isNotEmpty();
26+
assertThat(expectedDiagramCache).isNotEmpty();
2727
}
2828
}

0 commit comments

Comments
 (0)