Skip to content

[Unit Tests] Add coverage for StateTypeWarningLog, McRPGPlayerStat, TimeGateCondition, and QuestChainStartConditionTypeRegistry - #331

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

[Unit Tests] Add coverage for StateTypeWarningLog, McRPGPlayerStat, TimeGateCondition, and QuestChainStartConditionTypeRegistry#331
DiamondDagger590 wants to merge 1 commit into
recodefrom
claude/magical-cray-ifoz7k

Conversation

@DiamondDagger590

@DiamondDagger590 DiamondDagger590 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • StateTypeWarningLogTest (5 tests): Covers warn-once deduplication by NamespacedKey, independent keys logging independently, null cause handling, and no-interaction baseline. Pure Mockito — no MockBukkit needed.
  • McRPGPlayerStatTest (6 tests): Covers every enum value having a non-null key in the mcrpg namespace, specific key strings for HEALTH and MANA, distinct keys, and enum cardinality. Uses @ParameterizedTest with @EnumSource.
  • TimeGateConditionTest (8 tests): Covers time boundary evaluation — before/at/after boundary, timezone-aware comparison (UTC vs Asia/Tokyo), far-past and far-future boundaries, and record accessor verification.
  • QuestChainStartConditionTypeRegistryTest (8 tests): Covers register/get round-trip, registered() true/false, silent replacement on duplicate key, getAll() with multiple types, empty registry, and independent key registration.
  • PlayerLoginTimeDAOTest (+2 tests): Adds missing attemptCreateTable coverage — creates table when absent, returns false when already exists. Follows the established mock JDBC pattern.

Total: 29 new tests across 4 new test files and 1 modified test file.

Test plan

  • All new tests pass individually
  • Full ./gradlew verifiedShadowJar passes with zero failures
  • Tests follow project conventions: McRPGBaseTest, @DisplayName, action_outcome_whenCondition naming
  • DAO tests use mock JDBC pattern (no real database)
  • No McRPG.getInstance() coupling in test targets (except PlayerLoginTimeDAO's saveLoggedOutInSafeZone which is already handled by the existing test via mcRPG.getTimeProvider())

Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage for warning-log suppression, including duplicate warnings, independent keys, null causes, and no-call scenarios.
    • Added database table creation tests for existing and missing tables.
    • Added registry tests for lookup, registration, replacement, status, and empty states.
    • Added time-gate tests covering boundaries, time zones, and record accessors.
    • Added player-stat tests validating namespaces, keys, uniqueness, and supported values.

…ition, QuestChainStartConditionTypeRegistry, and PlayerLoginTimeDAO

New test coverage for four previously untested classes:
- StateTypeWarningLogTest: warn-once deduplication, independent keys, null cause
- McRPGPlayerStatTest: enum keys, namespace, distinct values
- TimeGateConditionTest: time boundary evaluation, timezone handling, edge cases
- QuestChainStartConditionTypeRegistryTest: register, get, replace, getAll

Also adds missing attemptCreateTable coverage to PlayerLoginTimeDAOTest.

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

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Claude finished @DiamondDagger590's task in 3m 2s —— View job


Review complete ✅

  • Gather PR context (diff, changed files)
  • Route to review lenses — test-only PR (no src/main or resource changes); routed review-testing to assess the new tests
  • Read all 5 changed test files plus their corresponding source implementations (StateTypeWarningLog, PlayerLoginTimeDAO, QuestChainStartConditionTypeRegistry, TimeGateCondition, McRPGPlayerStat)
  • Consolidate findings
  • Post final review

No blocking issues found. 1 nit.

Summary

This PR is test-only (408 lines across 5 files under src/test/java/, no src/main or resource changes), so no persona lens in the routing table auto-matched — I read the tests directly against the implementations they cover instead of fanning out to the full persona panel.

All 29 new/added tests are correct and align with the actual behavior of the code under test:

  • StateTypeWarningLogTest — dedup-by-key logic (warnedKeys.add(key)), null-cause path, and independent-key behavior all match StateTypeWarningLog.warnOnce.
  • PlayerLoginTimeDAOTest (+2) — attemptCreateTable tests correctly mock Database.tableExists(...) for both branches and assert on the CREATE TABLE statement / executeUpdate() call.
  • QuestChainStartConditionTypeRegistryTest — round-trip, silent-replace-on-duplicate-key, and empty-registry cases match the LinkedHashMap-backed registry.
  • TimeGateConditionTest — boundary math (!localNow.isBefore(after)) and the UTC/Asia-Tokyo timezone case are correct (verified the JST offset arithmetic by hand: 03:00 UTC = 12:00 JST).
  • McRPGPlayerStatTest — namespace/key assertions match the enum's NamespacedKey construction.

All follow the project's McRPGBaseTest / @DisplayName / action_outcome_whenCondition conventions, matching how other simple enum/registry tests in this repo already extend McRPGBaseTest even when Bukkit isn't strictly required.

Nit

1 nit
  • src/test/java/us/eunoians/mcrpg/database/table/PlayerLoginTimeDAOTest.java:20assertNotNull is imported but never used anywhere in the file (only assertEquals, assertFalse, and assertTrue are called). Harmless, but worth trimming.

Note on verification

I was not able to execute ./gradlew test/verifiedShadowJar in this sandbox — Bash commands required interactive approval that wasn't available in this run, so I couldn't confirm the build/test-pass claim mechanically. Verification here is based on manually reading each test against its corresponding source file, which is consistent. If you'd like the actual test run confirmed in CI, that should happen via the normal build workflow on this PR.
(branch)

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds unit tests for warning-log deduplication, database table creation, quest condition registries and time gates, and McRPGPlayerStat enum values.

Changes

Unit test coverage

Layer / File(s) Summary
Quest condition and registry tests
src/test/java/us/eunoians/mcrpg/quest/chain/condition/...
Tests cover registry lookup, registration, replacement, collection retrieval, time boundaries, timezone conversion, and record accessors.
Database table creation tests
src/test/java/us/eunoians/mcrpg/database/table/PlayerLoginTimeDAOTest.java
Tests verify table creation when absent and no creation when the table already exists.
Warning log behavior tests
src/test/java/us/eunoians/mcrpg/combat/state/StateTypeWarningLogTest.java
Tests verify first-warning logging, duplicate suppression, independent keys, null causes, and unused logger behavior.
Player statistic enum tests
src/test/java/us/eunoians/mcrpg/stat/McRPGPlayerStatTest.java
Tests verify namespaces, key values, uniqueness, non-null keys, and the exact enum size.

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

Possibly related PRs

🚥 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 clearly identifies the primary unit-test coverage added, although it omits the PlayerLoginTimeDAO test.
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-ifoz7k

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.

@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.

Actionable comments posted: 1

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/database/table/PlayerLoginTimeDAOTest.java-36-63 (1)

36-63: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Strengthen the table-creation test assertions.

The tests do not verify that Database.tableExists(...) controls the branch. The existing-table test also does not verify that no statement is prepared. The creation test matches only CREATE TABLE, so a different table name would still pass.

Verify the database lookup, verify no prepareStatement(...) call for an existing table, and match PlayerLoginTimeDAO.TABLE_NAME in the creation SQL.

Proposed assertions
         assertTrue(created);
-        verify(mockConnection).prepareStatement(contains("CREATE TABLE"));
+        verify(mockDatabase).tableExists(mockConnection, PlayerLoginTimeDAO.TABLE_NAME);
+        verify(mockConnection).prepareStatement(
+                contains("CREATE TABLE `" + PlayerLoginTimeDAO.TABLE_NAME + "`"));
         verify(mockStatement).executeUpdate();

         boolean created = PlayerLoginTimeDAO.attemptCreateTable(mockConnection, mockDatabase);

         assertFalse(created);
+        verify(mockDatabase).tableExists(mockConnection, PlayerLoginTimeDAO.TABLE_NAME);
+        verify(mockConnection, never()).prepareStatement(anyString());
🤖 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/PlayerLoginTimeDAOTest.java`
around lines 36 - 63, Strengthen the tests for
PlayerLoginTimeDAO.attemptCreateTable by verifying tableExists(mockConnection,
PlayerLoginTimeDAO.TABLE_NAME) in both branches. In the existing-table test,
also verify that mockConnection.prepareStatement(...) is never called; in the
creation test, match both "CREATE TABLE" and PlayerLoginTimeDAO.TABLE_NAME in
the SQL assertion.
src/test/java/us/eunoians/mcrpg/combat/state/StateTypeWarningLogTest.java-41-64 (1)

41-64: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject unexpected logger calls.

verify(...).log(...) only verifies matching calls. These tests still pass if warnOnce logs an additional warning with different arguments. Add verifyNoMoreInteractions(mockLogger) after the expected verifications.

Proposed test fix
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoInteractions;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
 
         verify(mockLogger, times(1)).log(Level.WARNING, "something broke", cause);
+        verifyNoMoreInteractions(mockLogger);
 
         verify(mockLogger).log(Level.WARNING, "A failed", causeA);
         verify(mockLogger).log(Level.WARNING, "B failed", causeB);
+        verifyNoMoreInteractions(mockLogger);
🤖 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/combat/state/StateTypeWarningLogTest.java`
around lines 41 - 64, Add verifyNoMoreInteractions(mockLogger) after the
expected log verifications in warnOnce_suppressesDuplicate and
warnOnce_differentKeysAreIndependent, ensuring both tests reject any additional
logger calls.
🤖 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.

Inline comments:
In `@src/test/java/us/eunoians/mcrpg/stat/McRPGPlayerStatTest.java`:
- Around line 7-14: Remove the McRPGBaseTest import and change
McRPGPlayerStatTest to a plain JUnit test class without extending McRPGBaseTest;
leave its enum and NamespacedKey assertions unchanged.

---

Other comments:
In `@src/test/java/us/eunoians/mcrpg/combat/state/StateTypeWarningLogTest.java`:
- Around line 41-64: Add verifyNoMoreInteractions(mockLogger) after the expected
log verifications in warnOnce_suppressesDuplicate and
warnOnce_differentKeysAreIndependent, ensuring both tests reject any additional
logger calls.

In `@src/test/java/us/eunoians/mcrpg/database/table/PlayerLoginTimeDAOTest.java`:
- Around line 36-63: Strengthen the tests for
PlayerLoginTimeDAO.attemptCreateTable by verifying tableExists(mockConnection,
PlayerLoginTimeDAO.TABLE_NAME) in both branches. In the existing-table test,
also verify that mockConnection.prepareStatement(...) is never called; in the
creation test, match both "CREATE TABLE" and PlayerLoginTimeDAO.TABLE_NAME in
the SQL assertion.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: 207e41cb-a4f0-474c-a331-177f61ffcaee

📥 Commits

Reviewing files that changed from the base of the PR and between cc181c0 and d800ada.

📒 Files selected for processing (5)
  • src/test/java/us/eunoians/mcrpg/combat/state/StateTypeWarningLogTest.java
  • src/test/java/us/eunoians/mcrpg/database/table/PlayerLoginTimeDAOTest.java
  • src/test/java/us/eunoians/mcrpg/quest/chain/condition/QuestChainStartConditionTypeRegistryTest.java
  • src/test/java/us/eunoians/mcrpg/quest/chain/condition/builtin/TimeGateConditionTest.java
  • src/test/java/us/eunoians/mcrpg/stat/McRPGPlayerStatTest.java

Comment on lines +7 to +14
import us.eunoians.mcrpg.McRPGBaseTest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

@DisplayName("McRPGPlayerStat")
class McRPGPlayerStatTest extends McRPGBaseTest {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove unnecessary McRPGBaseTest inheritance.

These tests only read enum values and NamespacedKey fields. They do not require MockBukkit server interaction or McRPGPlayer tracking. Use plain JUnit to keep the test isolated.

Proposed fix
-import us.eunoians.mcrpg.McRPGBaseTest;
-
 `@DisplayName`("McRPGPlayerStat")
-class McRPGPlayerStatTest extends McRPGBaseTest {
+class McRPGPlayerStatTest {

As per coding guidelines, “Do not extend McRPGBaseTest when a test requires neither MockBukkit server interaction nor McRPGPlayer tracking; use plain JUnit instead.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import us.eunoians.mcrpg.McRPGBaseTest;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@DisplayName("McRPGPlayerStat")
class McRPGPlayerStatTest extends McRPGBaseTest {
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
`@DisplayName`("McRPGPlayerStat")
class McRPGPlayerStatTest {
🤖 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/stat/McRPGPlayerStatTest.java` around lines 7
- 14, Remove the McRPGBaseTest import and change McRPGPlayerStatTest to a plain
JUnit test class without extending McRPGBaseTest; leave its enum and
NamespacedKey assertions unchanged.

Source: Coding guidelines

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