1
0

M3-AP-008: Testabdeckung vervollständigt

This commit is contained in:
2026-04-01 22:50:25 +02:00
parent 092e83340f
commit c0cdd0ed6e
2 changed files with 87 additions and 0 deletions

View File

@@ -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 ---
/**