fix(ocr): replace IllegalStateException with DomainException in triggerSenderTraining
Some checks failed
CI / Unit & Component Tests (push) Failing after 2m33s
CI / OCR Service Tests (push) Successful in 36s
CI / Backend Unit Tests (push) Failing after 2m46s
CI / Unit & Component Tests (pull_request) Failing after 2m37s
CI / OCR Service Tests (pull_request) Successful in 36s
CI / Backend Unit Tests (pull_request) Failing after 2m50s

Consistent with triggerManualSenderTraining — both defensive paths now use
DomainException.internal(OCR_TRAINING_CONFLICT) when the expected RUNNING row
is not found after creation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-18 09:55:22 +02:00
parent fc892f0f59
commit 16bcd0f73c
2 changed files with 12 additions and 1 deletions

View File

@@ -154,7 +154,8 @@ public class SenderModelService {
OcrTrainingRun run = Objects.requireNonNull(txTemplate.execute(status ->
trainingRunRepository.findFirstByPersonIdAndStatus(personId, TrainingStatus.RUNNING)
.orElseThrow(() -> new IllegalStateException(
.orElseThrow(() -> DomainException.internal(
ErrorCode.OCR_TRAINING_CONFLICT,
"Expected RUNNING row for person " + personId + " but none found"))));
String runId = run.getId().toString();

View File

@@ -297,6 +297,16 @@ class SenderModelServiceTest {
verify(senderModelRepository, never()).save(any());
}
@Test
void triggerSenderTraining_throwsDomainException_whenRunningRowMissingAfterDispatch() {
when(trainingRunRepository.findFirstByPersonIdAndStatus(personId, TrainingStatus.RUNNING))
.thenReturn(Optional.empty());
org.assertj.core.api.Assertions.assertThatThrownBy(
() -> service.triggerSenderTraining(personId, 0))
.isInstanceOf(DomainException.class);
}
// ─── triggerSenderTraining — queue promotion ──────────────────────────────
// ─── triggerManualSenderTraining ──────────────────────────────────────────