Skip to content

Commit

Permalink
#1 Check for empty document before convert
Browse files Browse the repository at this point in the history
  • Loading branch information
jpnffigueiredo committed Feb 6, 2018
1 parent 78bab31 commit f3f5ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/dcomp/tools/Latex.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public Input pdf() throws IOException {
final File dir = Files.createTempDir();
final File doc = new File(dir, "document.tex");
try {
new LengthOf(new TeeInput(this.source, doc)).intValue();
if (new LengthOf(new TeeInput(this.source, doc)).intValue() == 0) {
throw new IOException("Found empty document");
}
Latex.compile(dir, doc.getName());
return new InputOf(
java.nio.file.Files.newInputStream(
Expand Down
12 changes: 11 additions & 1 deletion src/test/java/com/dcomp/tools/LatexTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class LatexTest {
/**
* Latex can render pdf.
*
* @throws IOException If some problem inside
* @throws IOException If some problem found
*/
@Test
public void renders() throws IOException {
Expand All @@ -63,4 +63,14 @@ public void renders() throws IOException {
);
}

/**
* Latex can not render empty documents.
*
* @throws IOException If some problem found
*/
@Test(expected = IOException.class)
public void throwsExceptionForEmptyDocument() throws IOException {
new Latex("").pdf();
}

}

0 comments on commit f3f5ae8

Please sign in to comment.