TRUNK-6557: Add unit test for OpenmrsDateFormat 2-digit-year rejection#6123
Open
KrimsonSun wants to merge 1 commit into
Open
TRUNK-6557: Add unit test for OpenmrsDateFormat 2-digit-year rejection#6123KrimsonSun wants to merge 1 commit into
KrimsonSun wants to merge 1 commit into
Conversation
OpenmrsDateFormat is a strict-mode wrapper around SimpleDateFormat whose central reason for existing is to reject two-digit years when the pattern explicitly asks for four. Under plain SimpleDateFormat, parsing "12/25/25" against pattern "MM/dd/yyyy" silently produces the year 25 AD — the kind of clinical-timestamp bug that only surfaces months later in reports. This adds OpenmrsDateFormatTest with a single focused test that pins down that guarantee: parse() must throw ParseException with a message that calls out the 4-digit-year requirement. Asserting the message text guards both the rejection itself and the human-facing wording a downstream UI may show to a user. No production code is changed.
|
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.



Description of what I changed
Adds
OpenmrsDateFormatTestwith a single focused unit test for the centralcorrectness guarantee of
OpenmrsDateFormat.OpenmrsDateFormatis a strict-mode wrapper aroundSimpleDateFormatwhosereason for existing is to reject two-digit years when the pattern explicitly
asks for four. Under plain
SimpleDateFormat, parsing"12/25/25"againstpattern
"MM/dd/yyyy"silently produces the year 25 AD — the kind ofclinical-timestamp bug that only surfaces months later in reports. Until now
that guarantee was not pinned down by any test, so a future refactor of the
regex check in
parse()could weaken the contract unnoticed.The new test asserts both the rejection (a
ParseExceptionis thrown) andthe human-facing error message (must contain
"year must have 4 digits"),since downstream UIs may rely on that wording to explain the rejection to
a user typing a short-form date.
No production code is changed.
Verification
Issue I worked on
see https://openmrs.atlassian.net/browse/TRUNK-6557
Checklist: I completed these to help reviewers :)
mvn clean packageright before creating this pull request and added all formatting changes to my commit.