[Tests] Improve coverage for Statistic default method, SimpleStatistic, StatisticCache, ItemBuilderConfigurationKeys - #88
Conversation
…c, StatisticCache, and ItemBuilderConfigurationKeys - Cover Statistic interface getMaxSetSize() default method via a minimal implementation that does not override it (0% → 100%) - Cover ItemBuilderConfigurationKeys constructor (97% → 100%) - Expand SimpleStatisticTest from 4 to 16 tests: add equals/hashCode edge cases (self, null, different type, differing fields), toString, all StatisticType variants, and record accessor verification - Expand StatisticCacheTest from 6 to 15 tests: add multi-player isolation, overwrite behavior, empty cache invalidation safety, cross-player size tracking, and entry-level invalidation isolation - Reorganize both test files into @nested classes with @DisplayName - Rename carried-over test methods to follow methodUnderTest_expectedOutcome_whenCondition convention Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UCFoMUMd82qrg3uw7GJaPs
|
Claude finished @DiamondDagger590's task in 49s —— View job Claude PR ReviewNo blocking issues found. All 3 changed files are under I read through the diff directly: the new/reorganized tests follow the
|
📝 WalkthroughWalkthroughThe pull request expands JUnit coverage for ChangesStatistics and Builder Test Coverage
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Note
Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.
🟡 Other comments (2)
src/test/java/com/diamonddagger590/mccore/statistic/cache/StatisticCacheTest.java-184-197 (1)
184-197: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winMake the TTL test deterministic.
Thread.sleep(1500)depends on wall-clock timing and scheduler availability. Inject a fixedTimeProviderinto the cache test path and advance it explicitly before the expiry assertion.As per coding guidelines, “In tests that assert time-dependent behavior, inject a mock or fixed
TimeProviderrather than depending on wall-clock time.”🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/diamonddagger590/mccore/statistic/cache/StatisticCacheTest.java` around lines 184 - 197, The TTL expiration test method get_returnsEmpty_whenTtlExpires currently relies on Thread.sleep and wall-clock timing; inject a fixed or mock TimeProvider when constructing StatisticCache, then explicitly advance that provider past the TTL before the empty-result assertion. Preserve the existing assertions that the entry is initially present and absent after expiration.Source: Coding guidelines
src/test/java/com/diamonddagger590/mccore/statistic/SimpleStatisticTest.java-122-122 (1)
122-122: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winReplace the direct null equality call.
PMD flags
stat.equals(null). UseassertNotEquals(stat, null)to retain the equality-contract check without the direct null comparison.Proposed fix
- assertFalse(stat.equals(null)); + assertNotEquals(stat, null);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/test/java/com/diamonddagger590/mccore/statistic/SimpleStatisticTest.java` at line 122, In SimpleStatisticTest, replace the direct stat.equals(null) assertion with assertNotEquals(stat, null), preserving the existing equality-contract check without invoking equals directly with null.Source: Linters/SAST tools
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Other comments:
In
`@src/test/java/com/diamonddagger590/mccore/statistic/cache/StatisticCacheTest.java`:
- Around line 184-197: The TTL expiration test method
get_returnsEmpty_whenTtlExpires currently relies on Thread.sleep and wall-clock
timing; inject a fixed or mock TimeProvider when constructing StatisticCache,
then explicitly advance that provider past the TTL before the empty-result
assertion. Preserve the existing assertions that the entry is initially present
and absent after expiration.
In
`@src/test/java/com/diamonddagger590/mccore/statistic/SimpleStatisticTest.java`:
- Line 122: In SimpleStatisticTest, replace the direct stat.equals(null)
assertion with assertNotEquals(stat, null), preserving the existing
equality-contract check without invoking equals directly with null.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: QUIET
Plan: Pro Plus
Run ID: 57fc2d71-d0b8-48c9-8e66-0d02c7e4707c
📒 Files selected for processing (3)
src/test/java/com/diamonddagger590/mccore/builder/item/ItemBuilderConfigurationKeysTest.javasrc/test/java/com/diamonddagger590/mccore/statistic/SimpleStatisticTest.javasrc/test/java/com/diamonddagger590/mccore/statistic/cache/StatisticCacheTest.java
Summary
Statistic.getMaxSetSize()default method (0% → 100%): Added a test using a minimalStatisticimplementation that does not override the default method, verifying it returns-1.ItemBuilderConfigurationKeysconstructor (97% → 100%): Added a test that instantiates the utility class to cover the implicit constructor.SimpleStatisticTestfrom 4 to 16 tests: Added equals/hashCode edge cases (self-reference, null, different type, differingStatisticType, differingmaxSetSize),toStringverification, allStatisticTypevariants (INT, LONG, DOUBLE, STRING, TIMESTAMP, SET_STRING), and record accessor consistency checks. Reorganized into@Nestedclasses.StatisticCacheTestfrom 6 to 15 tests: Added multi-player isolation (separate values per player, cross-player query returns empty), overwrite behavior, empty cache invalidation safety (no-op on empty cache for both UUID and key invalidation), cross-player size tracking, and entry-level invalidation isolation. Reorganized into@Nestedclasses.methodUnderTest_expectedOutcome_whenConditionconvention.Overall coverage: 80.7% line / 70.7% branch (up from 80.6% / 70.7%). These were the only remaining non-PR-covered gaps — all other classes with < 100% coverage are addressed by existing open PRs.
Test plan
SimpleStatisticTesttests passStatisticCacheTesttests passItemBuilderConfigurationKeysTestconstructor test passes./gradlew test)StatisticandItemBuilderConfigurationKeysat 100% line/branchGenerated by Claude Code
Summary by CodeRabbit