Skip to content

[Tests] Improve coverage for CreateCoreTablesFunction and UpdateCoreTablesFunction - #93

Open
DiamondDagger590 wants to merge 1 commit into
developfrom
claude/eager-thompson-vk5v13
Open

[Tests] Improve coverage for CreateCoreTablesFunction and UpdateCoreTablesFunction#93
DiamondDagger590 wants to merge 1 commit into
developfrom
claude/eager-thompson-vk5v13

Conversation

@DiamondDagger590

@DiamondDagger590 DiamondDagger590 commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • Expanded CreateCoreTablesFunctionTest from 3 to 7 tests, achieving 100% JaCoCo coverage across all metrics (instruction, line, branch, complexity, method, class)
  • Expanded UpdateCoreTablesFunctionTest from 3 to 6 tests, achieving 100% JaCoCo coverage across all metrics
  • Extracted shared CallerRunsExecutor test fixture to src/testFixtures/java/ for reuse by downstream plugins

Details

New tests added

CreateCoreTablesFunctionTest:

  • Tables already exist path (attemptCreateTable returns false)
  • Tables don't exist path (attemptCreateTable returns true)
  • Mixed table existence (some exist, some don't)
  • Connection close exception handling (try-with-resources catch block)
  • Direct constructor instantiation

UpdateCoreTablesFunctionTest:

  • Connection close exception handling (try-with-resources catch block)
  • DAO method invocation verification (all 4 updateTable methods called)
  • Direct constructor instantiation

CallerRunsExecutor test fixture

A ThreadPoolExecutor that runs tasks on the calling thread, ensuring mockStatic scopes remain valid during task execution. Mockito's mockStatic is thread-local, so production code that submits work to an executor won't see static mocks on a separate thread. This fixture avoids that by running submitted tasks synchronously. Extracted from both test files to eliminate duplication and make it available to downstream plugins.

Test plan

  • All 2131 tests pass (./gradlew clean test)
  • ShadowJar builds successfully (./gradlew shadowJar)
  • JaCoCo coverage report confirms 100% for both target classes
  • Testing audit persona reviewed changes and feedback addressed

Generated by Claude Code

Summary by CodeRabbit

  • Tests
    • Expanded coverage for creating and updating core database tables, including existing, missing, and mixed table states.
    • Added validation for connection-close failures and confirmation that all required table operations are invoked.
    • Improved test execution reliability with synchronous task handling.

…esFunction

Expand CreateCoreTablesFunctionTest from 3 to 7 tests and
UpdateCoreTablesFunctionTest from 3 to 6 tests, achieving 100% coverage
for both classes across all JaCoCo metrics.

New tests cover table creation paths (tables exist, tables don't exist,
mixed), connection close exception handling, DAO method invocation
verification, and direct constructor instantiation.

Extract shared CallerRunsExecutor to testFixtures for reuse by downstream
plugins that need mockStatic-safe executor testing.

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

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

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


Reviewing PR #93

  • Gather context (diff, changed files, CLAUDE.md)
  • Route to review lenses (test-only PR: review-testing, review-architecture, review-extensibility selected; security/performance/error-handling skipped — no src/main changes)
  • Fan out lens subagents (running)
  • Consolidate findings
  • Post final review

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a synchronous test executor and expands tests for core table creation and update functions. The tests cover table states, DAO calls, connection-close failures, asynchronous completion, and direct construction.

Changes

Core table function tests

Layer / File(s) Summary
Synchronous test execution
src/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java
Adds CallerRunsExecutor, which runs submitted commands on the calling thread.
Create table coverage
src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java
Uses the synchronous executor and adds tests for existing, missing, mixed, and connection-close failure states. It also verifies direct construction.
Update table coverage
src/test/java/com/diamonddagger590/mccore/database/table/function/UpdateCoreTablesFunctionTest.java
Uses the synchronous executor and adds tests for connection-close failures, all four DAO update calls, and direct construction.

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

Possibly related PRs

  • DiamondDagger590/McCore#74: Extends the same core table function tests with executor control, DAO mocking, and additional scenarios.
🚥 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 and concisely describes the primary change: expanded test coverage for both core table functions.
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/eager-thompson-vk5v13

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/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java-23-26 (1)

23-26: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reject tasks after shutdown.

execute runs command after shutdown() or shutdownNow(). This bypasses the ExecutorService lifecycle contract and can make post-teardown tests execute unexpectedly.

Proposed fix
+import java.util.concurrent.RejectedExecutionException;
+
 `@Override`
 public void execute(Runnable command) {
+    if (isShutdown()) {
+        throw new RejectedExecutionException("Executor has been shut down");
+    }
     command.run();
 }
🤖 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/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java`
around lines 23 - 26, Update CallerRunsExecutor.execute to reject submissions
after shutdown or shutdownNow by checking the executor’s lifecycle state before
running the command and throwing the standard rejection exception when it is no
longer active; preserve the current caller-runs behavior for accepted tasks.
src/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java-24-24 (1)

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

Annotate the non-null command parameter with IntelliJ @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/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java`
at line 24, Annotate the non-null command parameter in
CallerRunsExecutor.execute with IntelliJ’s `@NotNull` annotation, adding the
necessary import if absent.

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.

Inline comments:
In
`@src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java`:
- Around line 164-192: Move normal CompletableFuture completion until after the
try-with-resources block exits so Connection.close() failures remain
exceptional. Update
createTables_completesExceptionally_whenConnectionCloseThrowsSQLException in
src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java
lines 164-192 and the corresponding close-failure test in
src/test/java/com/diamonddagger590/mccore/database/table/function/UpdateCoreTablesFunctionTest.java
lines 99-122 to assert join() fails with SQLException as its cause, replacing
the insufficient isDone() assertion and stale comments.

---

Other comments:
In
`@src/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java`:
- Around line 23-26: Update CallerRunsExecutor.execute to reject submissions
after shutdown or shutdownNow by checking the executor’s lifecycle state before
running the command and throwing the standard rejection exception when it is no
longer active; preserve the current caller-runs behavior for accepted tasks.
- Line 24: Annotate the non-null command parameter in CallerRunsExecutor.execute
with IntelliJ’s `@NotNull` annotation, adding the necessary import if absent.
🪄 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: 66cec97e-5fcf-4cf9-94ef-f3509af0ade7

📥 Commits

Reviewing files that changed from the base of the PR and between 0fbf220 and 02860ad.

📒 Files selected for processing (3)
  • src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java
  • src/test/java/com/diamonddagger590/mccore/database/table/function/UpdateCoreTablesFunctionTest.java
  • src/testFixtures/java/com/diamonddagger590/mccore/testing/CallerRunsExecutor.java

Comment on lines +164 to +192
@Test
@DisplayName("Given a connection that throws on close, when createTables is called, then the catch block executes and future completes exceptionally")
void createTables_completesExceptionally_whenConnectionCloseThrowsSQLException() throws Exception {
Database mockDatabase = mock(Database.class);
Connection mockConnection = mock(Connection.class);

when(mockDatabase.getDatabaseExecutorService()).thenReturn(executor);
when(mockDatabase.getConnection()).thenReturn(mockConnection);
doThrow(new SQLException("Close failed")).when(mockConnection).close();

try (MockedStatic<TableVersionHistoryDAO> tvhMock = mockStatic(TableVersionHistoryDAO.class);
MockedStatic<MutexDAO> mutexMock = mockStatic(MutexDAO.class);
MockedStatic<PlayerSettingDAO> psMock = mockStatic(PlayerSettingDAO.class);
MockedStatic<PlayerStatisticDAO> pstMock = mockStatic(PlayerStatisticDAO.class)) {

tvhMock.when(() -> TableVersionHistoryDAO.attemptCreateTable(any(Connection.class), any(Database.class))).thenReturn(true);
mutexMock.when(() -> MutexDAO.attemptCreateTable(any(Connection.class), any(Database.class))).thenReturn(true);
psMock.when(() -> PlayerSettingDAO.attemptCreateTable(any(Connection.class), any(Database.class))).thenReturn(true);
pstMock.when(() -> PlayerStatisticDAO.attemptCreateTable(any(Connection.class), any(Database.class))).thenReturn(true);

CreateTableFunction function = CreateCoreTablesFunction.getCreateCoreTablesFunction();

CompletableFuture<Void> result = function.createTables(mockDatabase);
assertNotNull(result);

// The future was already completed normally before close() threw,
// so completeExceptionally is a no-op — the future is done, not exceptionally
assertTrue(result.isDone());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not report a connection-close failure as successful completion.

Both tests configure Connection.close() to throw SQLException, but only assert isDone(). That assertion passes for both normal and exceptional completion. The inline comments also confirm that the current implementation completes normally before resource closure, so completeExceptionally cannot change the result.

Move normal future completion until after the try-with-resources block exits. Then assert that join() fails with SQLException as its cause.

  • src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java#L164-L192: Assert exceptional completion for the close failure.
  • src/test/java/com/diamonddagger590/mccore/database/table/function/UpdateCoreTablesFunctionTest.java#L99-L122: Assert exceptional completion for the close failure.
📍 Affects 2 files
  • src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java#L164-L192 (this comment)
  • src/test/java/com/diamonddagger590/mccore/database/table/function/UpdateCoreTablesFunctionTest.java#L99-L122
🤖 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/database/table/function/CreateCoreTablesFunctionTest.java`
around lines 164 - 192, Move normal CompletableFuture completion until after the
try-with-resources block exits so Connection.close() failures remain
exceptional. Update
createTables_completesExceptionally_whenConnectionCloseThrowsSQLException in
src/test/java/com/diamonddagger590/mccore/database/table/function/CreateCoreTablesFunctionTest.java
lines 164-192 and the corresponding close-failure test in
src/test/java/com/diamonddagger590/mccore/database/table/function/UpdateCoreTablesFunctionTest.java
lines 99-122 to assert join() fails with SQLException as its cause, replacing
the insufficient isDone() assertion and stale comments.

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