Skip to content

Commit

Permalink
adds more code coverage (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
codyfrehr committed Mar 1, 2024
1 parent dc9cb4a commit 3f496ba
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 22 deletions.
4 changes: 2 additions & 2 deletions common-api/src/main/java/io/xpdf/api/common/XpdfTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @since 1.0.0
*/
public interface XpdfTool<Request extends XpdfRequest, Response extends XpdfResponse> {
public interface XpdfTool<RequestT extends XpdfRequest, ResponseT extends XpdfResponse> {

/**
* Invokes an <em>Xpdf</em> executable against a PDF file.
Expand All @@ -33,6 +33,6 @@ public interface XpdfTool<Request extends XpdfRequest, Response extends XpdfResp
* @throws XpdfException if exception
* @since 1.0.0
*/
Response process(Request request) throws XpdfException;
ResponseT process(RequestT request) throws XpdfException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
*/
package io.xpdf.api.common.exception;

import lombok.experimental.StandardException;

/**
* An <em>Xpdf</em> {@code Exception}.
*
* @since 1.0.0
*/
@StandardException
public class XpdfException extends Exception {

public XpdfException(String message) {
super(message);
}

public XpdfException(Throwable cause) {
super(cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class XpdfExecutionException extends XpdfException {
*/
private final String errorOutput;

public XpdfExecutionException(String standardOutput,
String errorOutput,
String message) {
public XpdfExecutionException(String message,
String standardOutput,
String errorOutput) {
super(message);
this.standardOutput = standardOutput;
this.errorOutput = errorOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package io.xpdf.api.common.exception;

import lombok.experimental.StandardException;

/**
* An {@link XpdfException} thrown during the processing of an <em>Xpdf</em> request.
*
* @since 1.0.0
*/
@StandardException
public class XpdfProcessingException extends XpdfException {

public XpdfProcessingException(Throwable cause) {
super(cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package io.xpdf.api.common.exception;

import lombok.experimental.StandardException;

/**
* An <em>Xpdf</em> {@code RuntimeException}.
*
* @since 1.0.0
*/
@StandardException
public class XpdfRuntimeException extends RuntimeException {

public XpdfRuntimeException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package io.xpdf.api.common.exception;

import lombok.experimental.StandardException;

/**
* An {@link XpdfException} thrown when the shell process invoking an <em>Xpdf</em> executable exceeds the configured timeout length.
*
* @since 1.0.0
*/
@StandardException
public class XpdfTimeoutException extends XpdfException {

public XpdfTimeoutException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/
package io.xpdf.api.common.exception;

import lombok.experimental.StandardException;

/**
* An {@link XpdfException} thrown when attempting to invoke an <em>Xpdf</em> executable with invalid command options.
*
* @since 1.0.0
*/
@StandardException
public class XpdfValidationException extends XpdfException {

public XpdfValidationException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Common - The components shared between Xpdf APIs.
* 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.common.exception

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

class XpdfExecutionExceptionTest {

@Test
fun `should initialize`() {
// given
val exception = XpdfExecutionException("some message", "some standard output", "some error output")

// when then
exception.message shouldBe "some message"
exception.standardOutput shouldBe "some standard output"
exception.errorOutput shouldBe "some error output"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public PdfTextResponse process(PdfTextRequest request) throws XpdfException {
message = "Unknown Xpdf error";
break;
}
throw new XpdfExecutionException(standardOutput, errorOutput, message);
throw new XpdfExecutionException(message, standardOutput, errorOutput);
}
} else {
// handle process timeout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,11 @@ class PdfTextToolTest {
}

// when then
shouldThrowWithMessage<XpdfExecutionException>(message) {
val exception = shouldThrowWithMessage<XpdfExecutionException>(message) {
pdfTextToolSpy.process(mockk())
}
exception.standardOutput shouldBe "standardOutput"
exception.errorOutput shouldBe "errorOutput"

capturedOutput.all shouldContain "Process starting"
capturedOutput.all shouldContain "Validating request"
Expand Down

0 comments on commit 3f496ba

Please sign in to comment.