Skip to content

Add unit tests for BaseHyphenatedIdentifierValidator#6124

Open
JasonWang-0401 wants to merge 1 commit into
openmrs:masterfrom
JasonWang-0401:add-base-hyphenated-identifier-validator-tests
Open

Add unit tests for BaseHyphenatedIdentifierValidator#6124
JasonWang-0401 wants to merge 1 commit into
openmrs:masterfrom
JasonWang-0401:add-base-hyphenated-identifier-validator-tests

Conversation

@JasonWang-0401
Copy link
Copy Markdown

Description of what I changed

Adds BaseHyphenatedIdentifierValidatorTest, a unit test for the abstract base class
BaseHyphenatedIdentifierValidator that all of the "hyphenated check-digit" patient-identifier
validators (LuhnIdentifierValidator, VerhoeffIdentifierValidator) inherit from. The base
class previously had no direct test — its behaviour was only exercised indirectly through the
two subclass tests, where it is entangled with each subclass's own check-digit algorithm
(LuhnIdentifierValidatorTest even carries a // TODO split this into multiple tests note).

The new test uses a tiny stub subclass with a fixed, caller-controlled check digit so the shared
base-class contract can be verified in isolation, independent of any real check-digit math:

  • getValidIdentifier appends - + the correct check letter (the full 0→A … 9→J mapping,
    and X for an out-of-range digit)
  • isValid returns true/false correctly, accepts the check letter case-insensitively, and
    works whether the check digit is supplied as a letter (id-D) or an integer (id-3)
  • malformed input throws UnallowedIdentifierException (no hyphen, trailing hyphen, multi-character
    check digit, a check character that is neither A–J nor a digit)
  • the allowed-character rules reject null / empty / whitespace / disallowed characters

Pure JUnit 5; no Spring context and no database, so it runs in milliseconds. No production code is
changed.

Issue I worked on

Test-coverage improvement for a previously-untested base class. This change is purely additive
test code with no production changes.

see https://issues.openmrs.org/browse/TRUNK-

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project. (Tabs for indentation,
    line length ≤ 125, and import ordering match the surrounding test files.)
  • I have added tests to cover my changes.
  • I ran mvn clean package right before creating this pull request. (Verified the change with
    ./mvnw -pl api test -Dtest=BaseHyphenatedIdentifierValidatorTestTests run: 10, Failures: 0, Errors: 0.)
  • All new and existing tests passed.
  • My pull request is based on the latest changes of the master branch.

🤖 Generated with Claude Code

The abstract base class for hyphenated check-digit identifier validators had no direct test; its logic was only exercised indirectly through the Luhn and Verhoeff subclass tests, where it is tangled with each subclass's check-digit algorithm.

This adds a focused unit test that uses a stub subclass with a fixed, caller-controlled check digit to verify the base-class contract in isolation: hyphen/check-digit parsing, the 0-9 <-> A-J mapping (including the out-of-range 'X' default), case-insensitive check letters, and the allowed-character rules (null/empty/whitespace/disallowed).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@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.

1 participant