fix/frequency-assertions #4

Closed
forgejo wants to merge 44 commits from fix/frequency-assertions into main
Owner
No description provided.
- Create @RestControllerAdvice GlobalExceptionHandler for constraint violation (400) and illegal argument (404)
- Remove @ExceptionHandler methods from WordFrequencyController (now pure routing layer)
- Add GlobalExceptionHandlerTest with @WebMvcTest and @MockBean (2 tests)
- No behavioral changes, same 59 tests passing
- Controller returns just the frequency count, matching analyzer's int return type
- Removed word property from controller test assertions

Changes: controller + 2 test assertions updated. 59 tests passing.
- Service method returns int directly, removing WordFrequency model wrapping
- Removed WordFrequencyMapper dependency from service (no longer needed)
- Controller no longer calls .getFrequency()
- Updated service test to assert int instead of WordFrequency
- Same 59 tests passing
- Create InvalidInputException (400) for validation errors (blank/null text, word, n)
- Create ResourceNotFoundException (404) for not-found errors (missing words, empty text results)
- Create ErrorResponse DTO with title and error fields for structured error responses
- Update GlobalExceptionHandler to handle MissingServletRequestParameterException, ConstraintViolationException, InvalidInputException, and ResourceNotFoundException
- Validators throw InvalidInputException instead of IllegalArgumentException
- Service throws InvalidInputException for validation and ResourceNotFoundException for not-found
- Controller tests updated: empty text now returns 400 (validation) instead of 404
- Add unit tests for exception classes and ErrorResponse
- 64 tests passing (5 new test files, 5 new source files)
- Single @ExceptionHandler handles both InvalidInputException and ConstraintViolationException
- No separate ConstraintViolation handler — both return same ErrorResponse format
- ConstraintViolationException import retained only for handler parameter typing
- Remove InvalidInputException and ErrorResponse (no error bodies)
- GlobalExceptionHandler: 2 custom handlers + ConstraintViolationException
  for @Min (all return status-only responses)
- Validators and service throw IllegalArgumentException instead of
  InvalidInputException
- Update tests: IllegalArgumentException assertions, remove InvalidInputException
  and ErrorResponse tests
- 61 tests passing (64 - 3 deleted)
- Remove @Min from controller parameter — n validation handled by
  service layer validator (throws IllegalArgumentException)
- Remove ConstraintViolationException handler from GlobalExceptionHandler
- Remove @Validated from controller — no more validation annotations
- GlobalExceptionHandler now has exactly 2 handlers:
  IllegalArgumentException → 400, ResourceNotFoundException → 404
- ValidateTextNotBlankTest: 4 → 2 tests (parameterize null/empty/blank)
- ValidateTextAndWordNotBlankTest: 5 → 3 tests (parameterize text and word)
- ValidateTextNotBlankAndNPositiveTest: 5 → 3 tests (parameterize text and n)
- WordFrequencyAnalyzerImplTest: 12 → 11 tests (parameterize case variants)
- Total: 18 individual tests → 9 parameterized test methods (64 test invocations)
- missingParam_returns400 → covered by highestFrequencyMissingText
- illegalArgument_returns400 → covered by highestFrequencyEmptyText
- Kept resourceNotFound_returns404 as it's unique to the handler layer
- 62 tests passing (was 64, removed 2 duplicates)
- handler has no logic beyond RNF → 404
- frequencyForWordNotFound in controller test covers this end-to-end
- 61 tests passing
- Removed: valid/delegation and zero/empty-result → RNF tests
- Kept: 5 input validation tests (service concern) + word lowercasing (service-specific behavior)
- 61 → 55 tests, no loss of unique coverage
- Analyzer tests verify case-insensitivity directly (caseInsensitiveMatching)
- Controller test frequencyForWordCaseInsensitive covers full-stack scenario
- Removed Mockito dependency from service tests entirely
- 55 → 54 tests, no loss of coverage
- Remove ResourceNotFoundException exception and its test
- Service inlines analyzer calls (no intermediate variables, no throws)
- GlobalExceptionHandler: only IllegalArgumentException handler remains
- Controller test: word not found → 200 with body 0 (was 404)
- 54 → 53 tests
- @RequestParam int n instead of defaultValue = 3
- Removed mostFrequentDefaultN test — no longer valid
- 53 → 52 tests
- Add lombok dependency to pom.xml
- Replace manual constructors with @RequiredArgsConstructor on 6 classes
- 32 lines removed, 15 added (imports + annotations)
- All 52 tests pass
- calculateFrequencyForWord: removed intermediate frequencies variable
- calculateHighestFrequency: compacted method chain
- calculateMostFrequentNWords: use .toList() + assign to correctly-typed variable
- All 52 tests pass
- Wrapped .toList() result directly in new ArrayList<>(...) for type coercion
- WordFrequencyModel implements WordFrequency but List<WordFrequencyModel>
  is not assignable to List<WordFrequency> (Java generics are invariant)
- ArrayList wrapper required for type conversion
- 52 tests pass
- Replace all WordFrequency interface references with WordFrequencyModel in return types
- Remove ArrayList wrapper from stream collection in analyzer
- Add missing blank lines after fields in 5 source files
forgejo closed this pull request 2026-08-29 16:40:15 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo/wordcount!4
No description provided.