fix: correct data-mask and date-format bugs; add unit tests - #2
Open
Siborne wants to merge 2 commits into
Open
Conversation
added 2 commits
August 12, 2026 15:08
- EmailDataMaskFormatter: drop duplicated '@' in masked email (wangtest1111@126.com -> ***********w@126.com instead of ...w@@126.com) and guard against an email starting with '@' (Stream.limit(-1) crash) - DateTimeDiffFormatter: format any TemporalAccessor instead of casting to LocalDateTime (LocalDate/LocalTime previously threw ClassCastException) - MobileDataMaskFormatter: return null for null input instead of NPE (consistent with Email/IdCard mask formatters) - DiffComparable: fix javadoc, semantics are "true = same" as all built-in comparators and callers already behave
- DiffUtilsTest (19): ignore/exclude fields, alias, format, custom comparators, nested @DiffBean, collections (custom/JDK element types), DiffResult API - DateTimeDiffFormatterTest (7): Date/LocalDateTime/LocalDate/LocalTime, including regressions for the fixed TemporalAccessor cast - Email/Mobile/IdCardDataMaskFormatterTest (15): masking behavior plus regressions for the duplicated '@' and null-NPE fixes - BigDecimalEffectiveDiffComparatorTest (5): effective value comparison, null handling, type validation - pom.xml: add junit-jupiter 5.10.2 (test scope) + surefire 3.2.5 - .gitignore: ignore .reasonix/ tool directory
Siborne
force-pushed
the
fix/diff-bugs-and-tests
branch
from
August 12, 2026 07:16
2399861 to
34d07ea
Compare
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.
背景
java-obj-diff在运行示例与补全测试的过程中,发现并修复了 3 个功能性 bug,同时修正了 1 处接口文档错误;并在此基础上为项目引入了 JUnit 5 单元测试体系(此前项目没有任何自动化测试,只有一个main方法形式的演示程序)。修复内容
1. 邮箱脱敏输出重复的
@(EmailDataMaskFormatter)desensitizeEmail("wangtest1111@126.com")输出***********w@@126.com,多了一个@。email.substring(atIndex)本身已包含@,代码又手动拼接了一个"@"。"@",输出***********w@126.com。@开头(prefix 为空)时,原逻辑Stream.limit(-1)会抛IllegalArgumentException,现直接原样返回。2. 时间格式化对
LocalDate/LocalTime等抛ClassCastException(DateTimeDiffFormatter)format(LocalDate, "yyyy-MM-dd")抛ClassCastException: LocalDate cannot be cast to LocalDateTime。TemporalAccessor分支强制 cast 为LocalDateTime,而LocalDate、LocalTime、OffsetDateTime等同样是TemporalAccessor却非LocalDateTime。TemporalAccessor直接格式化,并移除未使用的LocalDateTimeimport。3. 手机号脱敏 null 输入 NPE(
MobileDataMaskFormatter)desensitizePhoneNumber(null)抛NullPointerException(Pattern.matcher(null))。EmailDataMaskFormatter、IdCardDataMaskFormatter的行为不一致。4. 接口文档语义相反(
DiffComparable)DefaultDiffComparator、BigDecimalEffectiveDiffComparator、示例中的SelfEnumComparator)及调用方DiffBuilder均按「相等 → true」工作。新增单元测试
引入 JUnit Jupiter 5.10.2 与 surefire 3.2.5,新增 6 个测试类、共 46 个用例:
DiffUtilsTest@DiffIgnore忽略、排除字段、@DiffAlias别名、@DiffFormat格式化、@DiffCompare自定义比较器、@DiffBean嵌套对象、集合比较(自定义类型元素 / JDK 类型元素 / 长度不同按索引对齐)、DiffResultAPI(isDiff/getNumberOfDiffs/不可变列表/迭代)DateTimeDiffFormatterTestDate、LocalDateTime、LocalDate、LocalTime(后两者为本次修复的回归用例)、默认 pattern、null、不支持类型EmailDataMaskFormatterTest@回归、单字符前缀、@开头守卫、blank/无@、非法类型MobileDataMaskFormatterTestIdCardDataMaskFormatterTestBigDecimalEffectiveDiffComparatorTestBigDecimal类型校验其中
EmailDataMaskFormatterTest与DateTimeDiffFormatterTest、MobileDataMaskFormatterTest分别包含对上述 bug 的回归用例,防止问题复发。验证结果
其他说明
DiffUtils存在一个既有 API 重载歧义(diffResult(T,T,String...)与diffResult(T,T,String,String...)在传单个 String 时编译不通过),本次未改动 API,测试中以显式数组方式调用规避;是否调整 API 留待后续讨论。