-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #97 from abelsromero/bump-junit-to-v5
Bump JUnit to v5 and remove unused build elements
- Loading branch information
Showing
9 changed files
with
51 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
64 changes: 31 additions & 33 deletions
64
asciidoctorj-pdf/src/test/java/org/asciidoctor/WhenBackendIsPdf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters