Skip to content

test: fill in unit test coverage for DataExportParams validation predicates#24469

Open
jason-p-pickering wants to merge 4 commits into
masterfrom
test/DHIS2-21821-dataexportparams-predicate-coverage
Open

test: fill in unit test coverage for DataExportParams validation predicates#24469
jason-p-pickering wants to merge 4 commits into
masterfrom
test/DHIS2-21821-dataexportparams-predicate-coverage

Conversation

@jason-p-pickering

Copy link
Copy Markdown
Contributor

Summary

Follow-up from DHIS2-21821 / #24465. That PR noted:

Before this PR, DataExportParams had no direct unit tests for any of its validation predicates (hasPeriodFilters, hasDataElementFilters, hasOrgUnitFilters, isPeriodOverSpecified, isDateRangeOutOfBounds, isLimitOutOfBounds, isOrgUnitGroupsOverSpecified, isExactOrgUnitsFilter). This is likely how the lastUpdated/lastUpdatedDuration branches were silently dropped from hasPeriodFilters() during the 2.43 SQL-export rewrite (#22406) without any test catching it.

Coverage for the other predicates currently only exists indirectly, via integration tests asserting the resulting ErrorCode after a full service call (e.g. DataExportServiceExportTest, DataValueServiceTest). Those are valuable but slow and don't isolate the predicate logic itself.

This PR fills that gap: test-only change, no production code touched.

  • Added direct unit tests for every branch of hasDataElementFilters, hasOrgUnitFilters, isExactOrgUnitsFilter, isPeriodOverSpecified, isDateRangeOutOfBounds, isLimitOutOfBounds, isOrgUnitGroupsOverSpecified.
  • Also filled in the previously-untested true-branches of hasPeriodFilters itself (periods, periodTypes, startDate+endDate, includedDate — only the false/lastUpdated-exclusion cases existed before).
  • 33 tests total in DataExportParamsTest.

Test plan

  • All 33 tests pass
  • Verified the two multi-condition predicates (isPeriodOverSpecified, isDateRangeOutOfBounds) aren't vacuous: temporarily dropped a conjunct from each in DataExportParams.java, confirmed the corresponding _OnlyFalse test failed for the right reason, then restored the original code (git diff on the production file is empty)
  • Full dhis-api module test suite passes
  • mvn spotless:check clean

🤖 Generated with Claude Code

jason-p-pickering and others added 2 commits July 16, 2026 12:19
…icates

Follow-up from DHIS2-21821 / PR #24465. Before that fix, DataExportParams
had no direct unit tests for any of its validation predicates, which is
likely how the lastUpdated/lastUpdatedDuration branches were silently
dropped from hasPeriodFilters() during the 2.43 SQL-export rewrite
(#22406) without any test catching it. Coverage existed only indirectly
via slow integration tests asserting the resulting ErrorCode.

Adds direct unit tests for every branch of hasDataElementFilters,
hasOrgUnitFilters, isExactOrgUnitsFilter, isPeriodOverSpecified,
isDateRangeOutOfBounds, isLimitOutOfBounds, isOrgUnitGroupsOverSpecified,
plus the previously-untested true-branches of hasPeriodFilters itself
(periods, periodTypes, startDate+endDate, includedDate).

Verified isPeriodOverSpecified and isDateRangeOutOfBounds tests aren't
vacuous by temporarily dropping a conjunct from each in production code,
confirming the corresponding _OnlyFalse test caught it, then restoring
(net diff to DataExportParams.java is zero).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Date.after() is strict (>), so a single-instant/single-day range
(startDate == endDate) is currently treated as valid, not out of
bounds. This boundary — the exact line between valid and invalid —
wasn't covered by the earlier StartBeforeEndFalse/StartAfterEndTrue
tests.

Verified via mutation testing: swapped the strict startDate.after(endDate)
check for an inclusive !startDate.before(endDate) in DataExportParams,
confirmed only the new test failed (all 33 others stayed green), then
restored (net diff to DataExportParams.java is zero).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jason-p-pickering
jason-p-pickering requested review from a team and netroms July 16, 2026 11:37
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants