M3-AP-008: Testabdeckung vervollständigt
This commit is contained in:
@@ -15,6 +15,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -125,6 +126,28 @@ class PdfTextExtractionPortAdapterTest {
|
||||
assertNotNull(success.extractedText()); // May be empty, but not null
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCorruptedPdfReturnsTechnicalError() throws Exception {
|
||||
// Create a file with binary garbage content – exists on disk but is not a valid PDF
|
||||
Path corruptFile = tempDir.resolve("corrupt.pdf");
|
||||
Files.write(corruptFile, "THIS IS NOT A PDF - RANDOM GARBAGE XYZ123!@#".getBytes());
|
||||
|
||||
SourceDocumentCandidate candidate = new SourceDocumentCandidate(
|
||||
"corrupt.pdf",
|
||||
Files.size(corruptFile),
|
||||
new SourceDocumentLocator(corruptFile.toAbsolutePath().toString())
|
||||
);
|
||||
|
||||
PdfExtractionResult result = adapter.extractTextAndPageCount(candidate);
|
||||
|
||||
// PDFBox cannot load a garbage file; the adapter must catch this and return TechnicalError
|
||||
assertInstanceOf(PdfExtractionTechnicalError.class, result,
|
||||
"Binary garbage file (not a real PDF) must yield TechnicalError, not Success");
|
||||
PdfExtractionTechnicalError error = (PdfExtractionTechnicalError) result;
|
||||
assertNotNull(error.errorMessage(), "TechnicalError must carry a non-null error message");
|
||||
assertFalse(error.errorMessage().isBlank(), "TechnicalError message must not be blank");
|
||||
}
|
||||
|
||||
// --- Helper methods to create test PDFs ---
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user