Skip to content

[Unit Tests] Add McRPGStatisticCacheManager tests and expand scope DAO coverage - #325

Open
DiamondDagger590 wants to merge 1 commit into
recodefrom
claude/magical-cray-nfbx1w
Open

[Unit Tests] Add McRPGStatisticCacheManager tests and expand scope DAO coverage#325
DiamondDagger590 wants to merge 1 commit into
recodefrom
claude/magical-cray-nfbx1w

Conversation

@DiamondDagger590

@DiamondDagger590 DiamondDagger590 commented Jul 30, 2026

Copy link
Copy Markdown
Owner

Summary

  • New test class: McRPGStatisticCacheManagerTest — 10 tests covering getCache(), getOfflineStatistic() (cache hit, DB fallback, DB miss, per-key isolation, cache population on repeat calls, per-player separation), and populateAsync() (DB hit populates cache, DB miss leaves cache empty, SQLException handled gracefully). Coverage goes from 0% to near-complete.
  • Expanded: SinglePlayerQuestScopeDAOTest from 3 → 15 tests covering all 6 public methods
  • Expanded: LandQuestScopeDAOTest from 2 → 14 tests covering all 5 public methods
  • Expanded: PermissionQuestScopeDAOTest from 2 → 13 tests covering all 5 public methods

All scope DAO tests now cover attemptCreateTable (exists/create/exception), updateTable (current version/v0), query methods (found/not-found/exception), and saveScope (valid/exception).

Test plan

  • All 4945 tests pass (./gradlew test)
  • JaCoCo report generates successfully
  • No regressions in existing tests
  • Testing audit persona reviewed changes

Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded automated coverage for quest scope database operations, including table creation, version updates, data retrieval, active quest queries, and persistence.
    • Added validation for successful results, missing data, SQL failures, and prepared-statement parameter handling.
    • Added comprehensive tests for statistic caching, including cache hits, database fallbacks, asynchronous population, player isolation, and error handling.
    • Reorganized tests into clearer, focused groups for easier maintenance.

- Add new McRPGStatisticCacheManagerTest with 10 tests covering getCache,
  getOfflineStatistic (cache hit, DB hit, DB miss, per-key isolation,
  cache population on repeat calls, per-player separation), and
  populateAsync (DB hit, DB miss, SQLException handling)
- Expand SinglePlayerQuestScopeDAOTest from 3 to 15 tests covering all
  public methods: attemptCreateTable, updateTable, findPlayerUuidForQuest,
  getPlayerInScope, findActiveQuestsForPlayer, saveScope
- Expand LandQuestScopeDAOTest from 2 to 14 tests covering all public
  methods: attemptCreateTable, updateTable, getLandName,
  findAllActiveLandQuests, saveScope
- Expand PermissionQuestScopeDAOTest from 2 to 13 tests covering all
  public methods: attemptCreateTable, updateTable, getPermissionNode,
  findAllActivePermissionQuests, saveScope

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012C7Go2ra1RsMPX76BwnAdk
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Expanded three quest-scope DAO test suites with lifecycle, lookup, active-query, persistence, and SQL-error coverage. Added statistic cache tests for synchronous retrieval, cache population, player isolation, and asynchronous database loading.

Changes

Quest scope DAO tests

Layer / File(s) Summary
Shared DAO test harness
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/*DAOTest.java
Centralizes Mockito fixtures and JUnit 5 setup for JDBC interactions.
Table lifecycle and version tests
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/*DAOTest.java
Tests table creation results, SQL failures, and schema version updates across the three DAOs.
Scope lookup and active quest queries
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/*DAOTest.java
Covers successful lookups, empty results, parameter bindings, exception behavior, and active quest mappings.
Scope persistence tests
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/*DAOTest.java
Verifies prepared-statement bindings and failure handling for each scope type.

Statistic cache tests

Layer / File(s) Summary
Statistic cache fixture and access
src/test/java/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java
Tests cache access, database fallback, cache population, misses, repeated retrieval, selective queries, and player isolation.
Asynchronous cache population
src/test/java/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java
Tests asynchronous population after database hits, misses, and connection-close SQL exceptions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: new cache manager tests and expanded scope DAO test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/magical-cray-nfbx1w

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

Claude finished @DiamondDagger590's task in 6m 26s —— View job


Claude PR Review — No blocking issues found

Verdict: No blocking issues found (0 important, 0 nits)

Summary: This is a test-only PR — no src/main files changed, so only the review-testing lens applies. I cross-checked the new/expanded test classes (McRPGStatisticCacheManagerTest, LandQuestScopeDAOTest, PermissionQuestScopeDAOTest, SinglePlayerQuestScopeDAOTest) against the production DAO/manager code they exercise. Assertions correctly match actual behavior (cache-hit/DB-fallback ordering in getOfflineStatistic, exception swallowing in attemptCreateTable/findAllActive* vs. rethrow-as-RuntimeException in getLandName/getPermissionNode/findPlayerUuidForQuest, QuestScopeInvalidStateException on missing player, ON CONFLICT upsert bindings). Structure follows repo conventions well: @Nested/@DisplayName grouping per public method, McRPGBaseTest base class, MockedStatic for TableVersionHistoryDAO/PlayerStatisticDAO. Registry mocks (McRPGDatabaseManager) registered per-test in McRPGStatisticCacheManagerTest are safe since McRPGBaseTest's constructor calls resetRegistry()/setupRegistry() fresh for each test instance.

  • Gather context (PR diff, changed files)
  • Route to review lenses — test-only PR, review-testing applicable
  • Fan out to persona subagent
  • Consolidate findings
  • Post final review

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java-214-214 (1)

214-214: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Import ArgumentCaptor rather than qualifying it inline.

Proposed fix
+import org.mockito.ArgumentCaptor;
...
-                var runnableCaptor = org.mockito.ArgumentCaptor.forClass(Runnable.class);
+                var runnableCaptor = ArgumentCaptor.forClass(Runnable.class);

As per coding guidelines, “Do not write fully-qualified type references inline in method bodies …; all types must be imported at the top of the file.”

Also applies to: 241-241, 270-270

🤖 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/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java`
at line 214, Import Mockito’s ArgumentCaptor at the top of
McRPGStatisticCacheManagerTest and replace the fully qualified references in
each affected test with the imported type, including the usages near lines 214,
241, and 270.

Source: Coding guidelines

src/test/java/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java-107-116 (1)

107-116: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Verify the DAO lookup in miss and error-path tests.

These tests only assert an empty cache, so a regression that skips PlayerStatisticDAO.getPlayerStatistic(...) can still pass. The close-error case can also pass if no connection is acquired or closed.

Proposed assertions
+                daoMock.verify(() -> PlayerStatisticDAO.getPlayerStatistic(
+                        mockConnection, playerUUID, statKey));
                 assertTrue(result.isEmpty());
+                daoMock.verify(() -> PlayerStatisticDAO.getPlayerStatistic(
+                        mockConnection, playerUUID, statKey));
                 assertTrue(cached.isEmpty());
+                daoMock.verify(() -> PlayerStatisticDAO.getPlayerStatistic(
+                        closingConnection, playerUUID, statKey));
+                verify(closingConnection).close();
                 assertTrue(cached.isEmpty());

Also applies to: 235-246, 264-275

🤖 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/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java`
around lines 107 - 116, Strengthen the miss and error-path tests around
cacheManager.getOfflineStatistic by verifying
PlayerStatisticDAO.getPlayerStatistic is invoked with mockConnection,
playerUUID, and statKey. In the close-error case, also verify the expected
connection acquisition and close behavior so the test fails when the connection
path is skipped; apply the same assertions to the additional marked test blocks.
🧹 Nitpick comments (3)
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/PermissionQuestScopeDAOTest.java (1)

35-48: 📐 Maintainability & Code Quality | 🔵 Trivial

Duplicated Mockito test-harness setup.

Same @BeforeEach setUp() boilerplate as LandQuestScopeDAOTest and SinglePlayerQuestScopeDAOTest. See consolidated comment.

🤖 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/us/eunoians/mcrpg/database/table/quest/scope/PermissionQuestScopeDAOTest.java`
around lines 35 - 48, Consolidate the duplicated Mockito test-harness
initialization from PermissionQuestScopeDAOTest.setUp() with the shared setup
used by LandQuestScopeDAOTest and SinglePlayerQuestScopeDAOTest. Reuse the
existing common fixture or setup helper for the mock fields and stubbing, while
preserving the current mockConnection, mockStatement, mockResultSet, and
mockDatabase behavior.
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/LandQuestScopeDAOTest.java (1)

35-48: 📐 Maintainability & Code Quality | 🔵 Trivial

Duplicated Mockito test-harness setup.

This @BeforeEach setUp() and mock field block is duplicated verbatim across LandQuestScopeDAOTest, PermissionQuestScopeDAOTest, and SinglePlayerQuestScopeDAOTest. See consolidated comment.

🤖 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/us/eunoians/mcrpg/database/table/quest/scope/LandQuestScopeDAOTest.java`
around lines 35 - 48, Remove the duplicated mock fields and `@BeforeEach` setUp()
logic from LandQuestScopeDAOTest, PermissionQuestScopeDAOTest, and
SinglePlayerQuestScopeDAOTest, and reuse a shared test-harness base or utility
containing the Mockito initialization and stubbing for mockConnection,
mockStatement, mockResultSet, and mockDatabase. Preserve each test’s existing
access to these shared mocks.
src/test/java/us/eunoians/mcrpg/database/table/quest/scope/SinglePlayerQuestScopeDAOTest.java (1)

35-48: 📐 Maintainability & Code Quality | 🔵 Trivial

Duplicated Mockito test-harness setup.

Same @BeforeEach setUp() boilerplate as LandQuestScopeDAOTest and PermissionQuestScopeDAOTest. See consolidated comment.

🤖 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/us/eunoians/mcrpg/database/table/quest/scope/SinglePlayerQuestScopeDAOTest.java`
around lines 35 - 48, Consolidate the duplicated Mockito setup from
SinglePlayerQuestScopeDAOTest.setUp() with the shared test-harness setup used by
LandQuestScopeDAOTest and PermissionQuestScopeDAOTest. Reuse the existing common
setup mechanism and remove redundant mock initialization and stubbing from this
class, preserving the same mock fields and behavior.
🤖 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/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java`:
- Line 214: Import Mockito’s ArgumentCaptor at the top of
McRPGStatisticCacheManagerTest and replace the fully qualified references in
each affected test with the imported type, including the usages near lines 214,
241, and 270.
- Around line 107-116: Strengthen the miss and error-path tests around
cacheManager.getOfflineStatistic by verifying
PlayerStatisticDAO.getPlayerStatistic is invoked with mockConnection,
playerUUID, and statKey. In the close-error case, also verify the expected
connection acquisition and close behavior so the test fails when the connection
path is skipped; apply the same assertions to the additional marked test blocks.

---

Nitpick comments:
In
`@src/test/java/us/eunoians/mcrpg/database/table/quest/scope/LandQuestScopeDAOTest.java`:
- Around line 35-48: Remove the duplicated mock fields and `@BeforeEach` setUp()
logic from LandQuestScopeDAOTest, PermissionQuestScopeDAOTest, and
SinglePlayerQuestScopeDAOTest, and reuse a shared test-harness base or utility
containing the Mockito initialization and stubbing for mockConnection,
mockStatement, mockResultSet, and mockDatabase. Preserve each test’s existing
access to these shared mocks.

In
`@src/test/java/us/eunoians/mcrpg/database/table/quest/scope/PermissionQuestScopeDAOTest.java`:
- Around line 35-48: Consolidate the duplicated Mockito test-harness
initialization from PermissionQuestScopeDAOTest.setUp() with the shared setup
used by LandQuestScopeDAOTest and SinglePlayerQuestScopeDAOTest. Reuse the
existing common fixture or setup helper for the mock fields and stubbing, while
preserving the current mockConnection, mockStatement, mockResultSet, and
mockDatabase behavior.

In
`@src/test/java/us/eunoians/mcrpg/database/table/quest/scope/SinglePlayerQuestScopeDAOTest.java`:
- Around line 35-48: Consolidate the duplicated Mockito setup from
SinglePlayerQuestScopeDAOTest.setUp() with the shared test-harness setup used by
LandQuestScopeDAOTest and PermissionQuestScopeDAOTest. Reuse the existing common
setup mechanism and remove redundant mock initialization and stubbing from this
class, preserving the same mock fields and behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: 4f5ac981-a7ce-492b-8856-6c159fcafd1f

📥 Commits

Reviewing files that changed from the base of the PR and between 71d4ebb and b117147.

📒 Files selected for processing (4)
  • src/test/java/us/eunoians/mcrpg/database/table/quest/scope/LandQuestScopeDAOTest.java
  • src/test/java/us/eunoians/mcrpg/database/table/quest/scope/PermissionQuestScopeDAOTest.java
  • src/test/java/us/eunoians/mcrpg/database/table/quest/scope/SinglePlayerQuestScopeDAOTest.java
  • src/test/java/us/eunoians/mcrpg/statistic/McRPGStatisticCacheManagerTest.java

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.

2 participants