Add unit tests for BaseHyphenatedIdentifierValidator#1
Closed
JasonWang-0401 wants to merge 1 commit into
Closed
Conversation
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>
Owner
Author
|
Superseded by the upstream PR openmrs#6124 (same commit, opened against the official repository). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BaseHyphenatedIdentifierValidatoris the abstract base class that implements the sharedframework for OpenMRS's "hyphenated check-digit" patient identifier validators
(
LuhnIdentifierValidator,VerhoeffIdentifierValidator). It had no direct unit test —its behaviour was only exercised indirectly through the two subclass tests, where it is
entangled with each subclass's own check-digit algorithm. (
LuhnIdentifierValidatorTesteven carries a
// TODO split this into multiple testsnote on its single validation method.)What this adds
A new test,
BaseHyphenatedIdentifierValidatorTest, that uses a tiny stub subclass with afixed, caller-controlled check digit so the base-class contract can be verified in isolation,
independent of any real check-digit math:
getValidIdentifierappends-+ the correct check letter (the full0→A … 9→Jmapping), and uses
Xas the check character for an out-of-range digit.isValidreturnstrue/falsecorrectly, accepts the check letter case-insensitively,and works whether the check digit is supplied as a letter (
id-D) or an integer (id-3).UnallowedIdentifierException: no hyphen, a trailing hyphen, amulti-character check digit (
id-10), and a check character that is neitherA–Jnor adigit (
id-K).null, empty, whitespace, and disallowedcharacters are all rejected.
The test doubles as living documentation of what a valid hyphenated identifier looks like,
in one place and independent of the Luhn/Verhoeff algorithms.
Testing
→
Tests run: 10, Failures: 0, Errors: 0, Skipped: 0— BUILD SUCCESS.Pure JUnit 5 unit test; no Spring context and no database.
🤖 Generated with Claude Code