test(#148): add PersonController, DocumentSpecifications, and PersonRepository tests
- PersonControllerTest: expand from 2 to 26 tests — covers all endpoints (GET persons/id/correspondents/documents, POST create/merge, PUT update) and all validation branches (missing/blank firstName, lastName, targetPersonId → 400). Reveals and fixes a real bug: ResponseStatusException thrown by controllers was caught by the catch-all ExceptionHandler(Exception) in GlobalExceptionHandler, returning 500 instead of the intended status. Fix: add explicit ExceptionHandler(ResponseStatusException) handler. - DocumentSpecificationsTest: 18 @DataJpaTest tests covering every branch in DocumentSpecifications (hasText null/blank/match/case, hasSender null/match, hasReceiver null/match, isBetween both-null/both-set/start-only/end-only, hasTags null/empty/match/AND-logic/case/whitespace-skip). This is the primary driver of the 0% repository branch coverage reported in #148. - PersonRepositoryTest: 10 new tests for previously untested native queries — findCorrespondents (order by doc count), findCorrespondentsWithFilter (case-insensitive), reassignSender, insertMissingReceiverReference (no-duplicate guard), deleteReceiverReferences. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -30,6 +31,12 @@ public class GlobalExceptionHandler {
|
||||
return ResponseEntity.badRequest().body(new ErrorResponse(ErrorCode.VALIDATION_ERROR, message));
|
||||
}
|
||||
|
||||
@ExceptionHandler(ResponseStatusException.class)
|
||||
public ResponseEntity<ErrorResponse> handleResponseStatus(ResponseStatusException ex) {
|
||||
return ResponseEntity.status(ex.getStatusCode())
|
||||
.body(new ErrorResponse(ErrorCode.VALIDATION_ERROR, ex.getReason()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<ErrorResponse> handleGeneric(Exception ex) {
|
||||
log.error("Unhandled exception", ex);
|
||||
|
||||
Reference in New Issue
Block a user