M3-AP-006: Fehlerklassifikation vereinfacht und Logging auf korrekte
Ergebnisfälle ausgerichtet
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
package de.gecheckt.pdf.umbenenner.domain.model;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Tests for M3 document processing outcome types.
|
||||
* <p>
|
||||
* Verifies that all four outcome types are properly created and validated.
|
||||
*/
|
||||
class M3DocumentProcessingOutcomeTest {
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
private SourceDocumentCandidate candidate;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
Path pdfFile = tempDir.resolve("doc.pdf");
|
||||
Files.createFile(pdfFile);
|
||||
SourceDocumentLocator locator = new SourceDocumentLocator(pdfFile.toString());
|
||||
candidate = new SourceDocumentCandidate("doc.pdf", 1024L, locator);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testM3TechnicalDocumentError_ValidConstruction() {
|
||||
// Act
|
||||
var error = new M3TechnicalDocumentError(candidate, "I/O error", null);
|
||||
|
||||
// Assert
|
||||
assertEquals(candidate, error.candidate());
|
||||
assertEquals("I/O error", error.errorMessage());
|
||||
assertNull(error.cause());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3TechnicalDocumentError_WithCause() {
|
||||
// Arrange
|
||||
var cause = new RuntimeException("File not found");
|
||||
|
||||
// Act
|
||||
var error = new M3TechnicalDocumentError(candidate, "I/O error", cause);
|
||||
|
||||
// Assert
|
||||
assertEquals(cause, error.cause());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3TechnicalDocumentError_WithNullCandidate_ThrowsException() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> new M3TechnicalDocumentError(null, "Error", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3TechnicalDocumentError_WithNullErrorMessage_ThrowsException() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> new M3TechnicalDocumentError(candidate, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3TechnicalDocumentError_WithEmptyErrorMessage_ThrowsException() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new M3TechnicalDocumentError(candidate, "", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3TechnicalDocumentError_IsM3DocumentProcessingOutcome() {
|
||||
// Verify type relationship
|
||||
var error = new M3TechnicalDocumentError(candidate, "Error", null);
|
||||
assertInstanceOf(M3DocumentProcessingOutcome.class, error);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3PreCheckPassed_IsM3DocumentProcessingOutcome() {
|
||||
// Verify type relationship
|
||||
var extraction = new PdfExtractionSuccess("text", new PdfPageCount(1));
|
||||
var passed = new M3PreCheckPassed(candidate, extraction);
|
||||
assertInstanceOf(M3DocumentProcessingOutcome.class, passed);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testM3PreCheckFailed_IsM3DocumentProcessingOutcome() {
|
||||
// Verify type relationship
|
||||
var failed = new M3PreCheckFailed(candidate, "Test failure reason");
|
||||
assertInstanceOf(M3DocumentProcessingOutcome.class, failed);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAllThreeOutcomesAreExhaustive() {
|
||||
// This test verifies that the three outcome types are the only implementations
|
||||
// M3 has exactly three outcome types: passed, failed (deterministic), and technical error
|
||||
|
||||
var extraction = new PdfExtractionSuccess("text", new PdfPageCount(1));
|
||||
|
||||
M3DocumentProcessingOutcome[] outcomes = {
|
||||
new M3PreCheckPassed(candidate, extraction),
|
||||
new M3PreCheckFailed(candidate, "Deterministic content failure"),
|
||||
new M3TechnicalDocumentError(candidate, "Technical extraction error", null)
|
||||
};
|
||||
|
||||
for (M3DocumentProcessingOutcome outcome : outcomes) {
|
||||
assertInstanceOf(M3DocumentProcessingOutcome.class, outcome);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user