Skip to content

Commit

Permalink
adds code coverage (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
codyfrehr committed Mar 1, 2024
1 parent dd0d6f9 commit dc9cb4a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ image:https://github.com/codyfrehr/xpdf-api/actions/workflows/ci.yml/badge.svg?e
image:https://codecov.io/gh/codyfrehr/xpdf-api/graph/badge.svg?branch=main[]
image:https://github.com/codyfrehr/xpdf-api/actions/workflows/codeql.yml/badge.svg?event=schedule&branch=main[]
image:https://snyk.io/test/github/codyfrehr/xpdf-api/main/badge.svg[]

{empty}

Xpdf API is a collection of Java APIs for https://www.xpdfreader.com/about.html[Xpdf], the open source library for operating on PDF files.
Expand Down Expand Up @@ -56,6 +55,7 @@ We strongly recommend downloading sources in your IDE so that you have full acce
We made an extra effort to provide you with all the help you need, directly from your editor.

image::_doc/readme/javadoc_pdftextoptions.jpg[]
{empty}

We also strongly encourage you to read the Xpdf source documentation for a complete overview of each function and the options available to customize its execution.
Documentation can be found alongside the executable files in the package resources, or can be downloaded from https://www.xpdfreader.com/download.html[Xpdf] directly.
Expand Down Expand Up @@ -237,7 +237,7 @@ It will include the text file created from a PDF, as well as any standard output

We have added an SLF4J logger to our `PdfTextTool`, leaving its implementation up to you.

We provide meaningful debug logs for those needing such details. If you want the trace from _pdftotext_ itself, then inject the "-verbose" command option into `PdfTextOptions` and inspect the standard output on your `PdfTextResponse`.
We provide meaningful debug logs for anyone needing more detail. If you want the trace from _pdftotext_ itself, then inject the "-verbose" command option into `PdfTextOptions` and inspect the standard output on your `PdfTextResponse`.

//TODO== Getting Help
//TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
*/
public class XpdfUtils {

private XpdfUtils() {
}

/**
* Gets the temporary directory utilized by native <em>Xpdf</em> executables.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
*/
public class PdfTextUtils {

private PdfTextUtils() {
}

/**
* Gets the resource name of the <em>pdftotext</em> executable native to this system.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* PdfText API - An API for accessing a native pdftotext library.
* Copyright © 2024 xpdf.io (info@xpdf.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.xpdf.api.pdftext

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import java.io.File

class PdfTextRequestTest {

@Test
fun `should throw exception when initializing if pdf file is null`() {
// when then
shouldThrow<NullPointerException> {
PdfTextRequest.builder().build()
}
}

@Test
fun `should convert to string`() {
// given
val request = PdfTextRequest.builder()
.pdfFile(File("some.pdf"))
.textFile(File("some.text"))
.build()

// when then
request.toString() shouldBe "PdfTextRequest(pdfFile=some.pdf, textFile=some.text, options=null)"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* PdfText API - An API for accessing a native pdftotext library.
* Copyright © 2024 xpdf.io (info@xpdf.io)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.xpdf.api.pdftext

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
import java.io.File

class PdfTextResponseTest {

@Test
fun `should convert to string`() {
// given
val request = PdfTextResponse.builder()
.textFile(File("some.text"))
.standardOutput("some standard output")
.build()

// when then
request.toString() shouldBe "PdfTextResponse(textFile=some.text, standardOutput=some standard output)"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldMatch
import io.xpdf.api.common.exception.XpdfException
import io.xpdf.api.common.util.XpdfUtils
import io.xpdf.api.pdftext.options.PdfTextEncoding
import io.xpdf.api.pdftext.options.PdfTextEndOfLine
import io.xpdf.api.pdftext.options.PdfTextFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import io.kotest.matchers.collections.shouldBeEmpty
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldMatch
import io.mockk.*
import io.xpdf.api.common.exception.*
import io.xpdf.api.pdftext.util.PdfTextUtils
import io.xpdf.api.pdftext.options.PdfTextEncoding
import io.xpdf.api.pdftext.options.PdfTextEndOfLine
import io.xpdf.api.pdftext.options.PdfTextFormat
import io.xpdf.api.pdftext.util.PdfTextUtils
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -643,4 +644,15 @@ class PdfTextToolTest {
pdfTextTool.getCommandOptions(options) shouldContainExactly listOf("-option1", "value1", "-option2", "-option3", "-option4")
}

@Test
fun `should convert to string`() {
// given
val pdfTextTool = PdfTextTool.builder()
.timeoutSeconds(100)
.build()

// when then
pdfTextTool.toString() shouldMatch Regex("PdfTextTool\\(executableFile=.+pdftotext(\\.exe)?, timeoutSeconds=100\\)")
}

}

0 comments on commit dc9cb4a

Please sign in to comment.