Skip to content

[Unit Tests] Add coverage for event classes: ability cooldown, quest cancel/reward, chain lifecycle - #328

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

[Unit Tests] Add coverage for event classes: ability cooldown, quest cancel/reward, chain lifecycle#328
DiamondDagger590 wants to merge 1 commit into
recodefrom
claude/magical-cray-1dy01a

Conversation

@DiamondDagger590

@DiamondDagger590 DiamondDagger590 commented Aug 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add unit tests for 7 event classes that previously had 0% test coverage
  • All tests pass (./gradlew test — zero failures across the full suite)
  • Testing audit persona (persona-testing.mdc) run against changes with no blocking concerns

Classes Covered

Class Key behaviors tested
AbilityPutOnCooldownEvent Cooldown clamping (Math.max(0, cooldown)) in constructor and setCooldown(), large values (Long.MAX_VALUE), getters for holder/ability
QuestCancelEvent 3-arg constructor (expiration flag), deprecated 2-arg and 1-arg constructors, getQuestDefinitionKey() fallback to instance key when definition is null
QuestRewardGrantEvent Cancellation state (default false, set/toggle), mutable reward list (add/remove/clear), RewardGrantContext values, nullable QuestInstance
QuestRewardGrantedEvent Immutable reward list via List.copyOf() (throws UnsupportedOperationException on add/remove), defensive copy independence from original list, RewardGrantContext values
QuestChainExpireEvent Cancellation state, nullable Player wrapped in Optional.ofNullable(), UUID always available even with null player
QuestChainRestartEvent RestartReason enum (parameterized test over all values), nullable player (raw null), handler list
QuestChainStepRetryEvent Retry number (1-based), max retries (-1 for unlimited, 0, positive), QuestChainStep getter, nullable player

Test plan

  • All 7 new test files compile and pass
  • Full test suite passes (./gradlew test — zero failures)
  • Testing audit persona reviewed — no blocking concerns
  • Tests follow action_outcome_whenCondition naming convention with @DisplayName annotations
  • Tests extend McRPGBaseTest and use server.addPlayer() for PlayerMock where needed
  • Edge cases covered: zero values, negative values, null parameters, enum variants, boundary values

Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive coverage for ability cooldown events.
    • Added tests for quest cancellation, reward granting, and reward completion behavior.
    • Added coverage for quest-chain expiration, restarting, and step retry scenarios.
    • Verified constructor handling, getters, nullable values, state transitions, boundary conditions, reward mutability, and event handler consistency.

…ard grant, and chain lifecycle

Cover 7 event classes that previously had 0% test coverage:
- AbilityPutOnCooldownEvent: cooldown clamping (negative→0), setter, getters
- QuestCancelEvent: 3 constructors (incl. 2 deprecated), expiration flag, definition key fallback
- QuestRewardGrantEvent: cancellation, mutable reward list, RewardGrantContext
- QuestRewardGrantedEvent: immutable reward list (defensive copy, UnsupportedOperationException)
- QuestChainExpireEvent: cancellation, Optional-wrapped nullable player
- QuestChainRestartEvent: RestartReason enum, nullable player, handler list
- QuestChainStepRetryEvent: retry number, max retries (-1 unlimited), step getter

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

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

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


Review complete — 0 important, 2 nits

This PR adds 7 new JUnit test files covering previously-untested event classes (AbilityPutOnCooldownEvent, QuestCancelEvent, QuestRewardGrantEvent/GrantedEvent, and three quest-chain lifecycle events). It's test-only — no src/main changes — so only the review-testing lens applied per the routing table; security/architecture/concurrency/error-handling/performance/extensibility were skipped as there's no production code in the diff.

I verified each new test against its production class and confirmed the assertions genuinely exercise the constructor clamping (AbilityPutOnCooldownEvent), the deprecated-constructor fallback paths (QuestCancelEvent), the mutable-vs-immutable reward list distinction (QuestRewardGrantEvent vs QuestRewardGrantedEvent), and the nullable-player/Optional handling across the chain events. No correctness or coverage problems found — only two style nits:

Nits (2)
  • AbilityPutOnCooldownEventTest.java:17 — the class extends McRPGBaseTest (which boots a full MockBukkit server + loads the McRPG plugin via MockBukkit.load() in its constructor), but every test only uses plain Mockito mocks (AbilityHolder, CooldownableAbility) and never touches server/mcRPG. This pays real Bukkit-bootstrap overhead for a test that has no Bukkit dependency. Consider dropping extends McRPGBaseTest and making it a plain JUnit test. Fix this →

  • QuestChainExpireEventTest.java:25, QuestChainRestartEventTest.java:26, QuestChainStepRetryEventTest.java:24 — each declares its own byte-for-byte identical private buildDefinition(String key) helper, mirroring the same duplication already present in the pre-existing QuestChainStartEventTest and QuestChainCompleteEventTest. A future change to QuestChainDefinition.Builder's constructor signature now requires hand-editing 5 files. Worth extracting a QuestChainTestHelper under src/testFixtures/java/us/eunoians/mcrpg/quest/chain/ (mirroring the existing QuestTestHelper pattern) — not blocking for this PR since it matches existing convention, but a good follow-up. Fix this →

Neither nit blocks merge.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added comprehensive tests for ability, quest, and quest-chain events. The tests cover constructors, accessors, state changes, reward collections, player UUID handling, cancellation, retry limits, and handler-list consistency.

Changes

Event contract tests

Layer / File(s) Summary
Ability cooldown event tests
src/test/java/us/eunoians/mcrpg/event/ability/AbilityPutOnCooldownEventTest.java
Tests cover cooldown clamping, updates, getters, and handler-list access.
Quest event tests
src/test/java/us/eunoians/mcrpg/event/quest/QuestCancelEventTest.java, src/test/java/us/eunoians/mcrpg/event/quest/QuestRewardGrantEventTest.java, src/test/java/us/eunoians/mcrpg/event/quest/QuestRewardGrantedEventTest.java
Tests cover quest cancellation constructors, reward contexts, cancellation state, mutable rewards, defensive copying, ordering, and handler lists.
Quest-chain event tests
src/test/java/us/eunoians/mcrpg/event/quest/chain/*EventTest.java
Tests cover expiration, restart reasons, retry limits, player and UUID handling, cancellation, and handler-list access.

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

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the added unit-test coverage for the listed ability, quest, and quest-chain event classes.
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 💡 1
📝 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-1dy01a

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.

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/event/quest/chain/QuestChainExpireEventTest.java-25-32 (1)

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

Centralize and document the fixture helpers.

The repeated fixture helpers lack required Javadoc and @NotNull declarations. Extract the common buildDefinition helper into a shared test fixture. Document and annotate all remaining helper parameters and return values.

  • src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainExpireEventTest.java#L25-L32: replace the local buildDefinition helper with the shared fixture.
  • src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainRestartEventTest.java#L26-L33: replace the local buildDefinition helper with the shared fixture.
  • src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainStepRetryEventTest.java#L24-L35: replace buildDefinition with the shared fixture and add Javadoc plus @NotNull declarations to buildStep.

As per coding guidelines, “Do not duplicate logic across two or more classes” and “Annotate all non-null return types and parameters with IntelliJ v12 @NotNull.”

🤖 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/event/quest/chain/QuestChainExpireEventTest.java`
around lines 25 - 32, Centralize the duplicated buildDefinition fixture and
document all remaining test helpers with IntelliJ v12 `@NotNull` annotations. In
src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainExpireEventTest.java
lines 25-32 and
src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainRestartEventTest.java
lines 26-33, remove the local buildDefinition methods and use the shared
fixture; in
src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainStepRetryEventTest.java
lines 24-35, use the shared fixture and add Javadoc plus `@NotNull` annotations to
buildStep’s non-null parameters and return value.

Source: Coding guidelines

src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainStepRetryEventTest.java-120-142 (1)

120-142: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Enforce the QuestChainStepRetryEvent retry-number contract.

QuestChainStepRetryEvent documents retryNumber as 1-based, and there is no dispatch or source-side range check, so invalid cases like retryNumber <= 0, maxRetries < -1, and maxRetries == 0 with retryNumber == 1 can still be created and used. Add range validation in the event/API boundary and reject these states with IllegalArgumentException.

🤖 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/event/quest/chain/QuestChainStepRetryEventTest.java`
around lines 120 - 142, Update QuestChainStepRetryEvent construction or its API
boundary to validate the documented retry-number contract: reject retryNumber
values less than 1, maxRetries values less than -1, and the combination of
maxRetries == 0 with retryNumber == 1 by throwing IllegalArgumentException.
Preserve valid unlimited (-1) and positive-max-retry behavior.

Source: Coding guidelines

🧹 Nitpick comments (1)
src/test/java/us/eunoians/mcrpg/event/ability/AbilityPutOnCooldownEventTest.java (1)

6-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use a plain JUnit test for this event contract.

This test does not use MockBukkit server interaction or McRPGPlayer tracking. Remove the McRPGBaseTest import and superclass.

Proposed change
-import us.eunoians.mcrpg.McRPGBaseTest;
-
-class AbilityPutOnCooldownEventTest extends McRPGBaseTest {
+class AbilityPutOnCooldownEventTest {

As per coding guidelines: tests that require neither MockBukkit server interaction nor McRPGPlayer tracking must use plain JUnit instead of extending McRPGBaseTest.

Also applies to: 17-17

🤖 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/event/ability/AbilityPutOnCooldownEventTest.java`
at line 6, Update AbilityPutOnCooldownEventTest to use plain JUnit by removing
the McRPGBaseTest import and changing the test class so it no longer extends
McRPGBaseTest; leave the event assertions and other test behavior unchanged.

Source: Coding guidelines

🤖 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/event/quest/chain/QuestChainExpireEventTest.java`:
- Around line 25-32: Centralize the duplicated buildDefinition fixture and
document all remaining test helpers with IntelliJ v12 `@NotNull` annotations. In
src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainExpireEventTest.java
lines 25-32 and
src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainRestartEventTest.java
lines 26-33, remove the local buildDefinition methods and use the shared
fixture; in
src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainStepRetryEventTest.java
lines 24-35, use the shared fixture and add Javadoc plus `@NotNull` annotations to
buildStep’s non-null parameters and return value.

In
`@src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainStepRetryEventTest.java`:
- Around line 120-142: Update QuestChainStepRetryEvent construction or its API
boundary to validate the documented retry-number contract: reject retryNumber
values less than 1, maxRetries values less than -1, and the combination of
maxRetries == 0 with retryNumber == 1 by throwing IllegalArgumentException.
Preserve valid unlimited (-1) and positive-max-retry behavior.

---

Nitpick comments:
In
`@src/test/java/us/eunoians/mcrpg/event/ability/AbilityPutOnCooldownEventTest.java`:
- Line 6: Update AbilityPutOnCooldownEventTest to use plain JUnit by removing
the McRPGBaseTest import and changing the test class so it no longer extends
McRPGBaseTest; leave the event assertions and other test behavior unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: e7b6ab2f-0251-4629-98ad-9cef09e0b9d4

📥 Commits

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

📒 Files selected for processing (7)
  • src/test/java/us/eunoians/mcrpg/event/ability/AbilityPutOnCooldownEventTest.java
  • src/test/java/us/eunoians/mcrpg/event/quest/QuestCancelEventTest.java
  • src/test/java/us/eunoians/mcrpg/event/quest/QuestRewardGrantEventTest.java
  • src/test/java/us/eunoians/mcrpg/event/quest/QuestRewardGrantedEventTest.java
  • src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainExpireEventTest.java
  • src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainRestartEventTest.java
  • src/test/java/us/eunoians/mcrpg/event/quest/chain/QuestChainStepRetryEventTest.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