Skip to content

fix(test): update RouterHandlerTest mocks to 4-arg buildRouteJson signature#157

Merged
vharseko merged 6 commits intocopilot/add-openapi-mock-response-handlerfrom
copilot/update-tests-for-4-arg-method
Apr 3, 2026
Merged

fix(test): update RouterHandlerTest mocks to 4-arg buildRouteJson signature#157
vharseko merged 6 commits intocopilot/add-openapi-mock-response-handlerfrom
copilot/update-tests-for-4-arg-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

  • Update onChanges_deploysRoute_whenOpenApiSpecFileIsAdded stub and verify to 4 args
  • Update stop_destroysAllRoutes stub to 4 args
  • Update onChanges_ignoresOpenApiSpecFile_whenEnabledIsFalse verify(never()) to 4 args
  • Update buildRouteJson_isCalledWithFalse_whenFailOnResponseViolationIsFalse stub and verify to 4 args
  • Update buildRouteJson_isCalledWithTrue_whenFailOnResponseViolationIsTrue stub and verify to 4 args
  • Merge from master (resolved conflict in .github/workflows/build.yml)
Original prompt

Problem

PR #155 introduced a mockMode parameter to OpenApiRouteBuilder.buildRouteJson(), making it a 4-argument method (OpenAPI, File, boolean failOnResponseViolation, boolean mockMode). The production code in RouterHandler.loadOpenApiSpec() (line 450-452) correctly calls this 4-arg overload:

final JsonValue routeJson = openApiRouteBuilder.buildRouteJson(
        specOpt.get(), specFile, openApiValidationSettings.failOnResponseViolation,
        openApiValidationSettings.mockMode);

However, the tests in RouterHandlerTest.java still set up mocks and verifications using the old 3-argument signature. Since Mockito's strict stubbing doesn't match the actual 4-argument call, the mocks return null, causing 4 test failures:

  1. buildRouteJson_isCalledWithFalse_whenFailOnResponseViolationIsFalse (line 407)
  2. buildRouteJson_isCalledWithTrue_whenFailOnResponseViolationIsTrue (line 429)
  3. onChanges_deploysRoute_whenOpenApiSpecFileIsAdded (line 331)
  4. stop_destroysAllRoutes (line 366)

Required Fix

In openig-core/src/test/java/org/forgerock/openig/handler/router/RouterHandlerTest.java, update all when() stubs and verify() calls for mockOpenApiRouteBuilder.buildRouteJson(...) to use the 4-argument version, adding the mockMode boolean (which defaults to false since OpenApiValidationSettings() defaults mockMode to false).

Specific changes:

1. onChanges_deploysRoute_whenOpenApiSpecFileIsAdded test (~line 324, 331):

  • Line 324 stub: change anyBoolean() (3 args) → anyBoolean(), anyBoolean() (4 args)
    when(mockOpenApiRouteBuilder.buildRouteJson(eq(fakeSpec), eq(specFile), anyBoolean(), anyBoolean())).thenReturn(routeJson);
  • Line 331 verify: add false for mockMode
    verify(mockOpenApiRouteBuilder).buildRouteJson(fakeSpec, specFile, false, false);

2. stop_destroysAllRoutes test (~line 358):

  • Line 358 stub: change anyBoolean() (3 args) → anyBoolean(), anyBoolean() (4 args)
    when(mockOpenApiRouteBuilder.buildRouteJson(eq(fakeSpec), eq(specFile), anyBoolean(), anyBoolean())).thenReturn(routeJson);

3. buildRouteJson_isCalledWithFalse_whenFailOnResponseViolationIsFalse test (~lines 399, 407):

  • Line 399 stub: add false for mockMode
    when(mockOpenApiRouteBuilder.buildRouteJson(fakeSpec, specFile, false, false))
            .thenReturn(routeJson);
  • Line 407 verify: add false for mockMode
    verify(mockOpenApiRouteBuilder).buildRouteJson(fakeSpec, specFile, false, false);

4. buildRouteJson_isCalledWithTrue_whenFailOnResponseViolationIsTrue test (~lines 422, 429):

  • Line 422 stub: add false for mockMode
    when(mockOpenApiRouteBuilder.buildRouteJson(fakeSpec, specFile, true, false))
            .thenReturn(routeJson);
  • Line 429 verify: add false for mockMode
    verify(mockOpenApiRouteBuilder).buildRouteJson(fakeSpec, specFile, true, false);

Also update line 383 in onChanges_ignoresOpenApiSpecFile_whenEnabledIsFalse:

verify(mockOpenApiRouteBuilder, never()).buildRouteJson(any(), any(), any(Boolean.class), any(Boolean.class));

No other files need changes. This is purely a test mock signature fix.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

Assistant:

I'll start by fetching the job logs and the workflow definition to understand the failure.

Assistant: Let me look at the failing test file and the source file where the issue is occurring.

Assistant:

Failing Job Analysis

The build is failing with 4 test failures in RouterHandlerTest, all related to a method signature mismatch in RouterHandler.loadOpenApiSpec().

Root Cause

The tests expect openApiRouteBuilder.buildRouteJson() to be called with 3 arguments (OpenAPI, File, boolean), but the actual production code at RouterHandler.java:450-452 calls it with 4 arguments (OpenAPI, File, boolean, boolean) — the additional mockMode parameter was added but the tests were not updated:

// Production code (line 450-452):
final JsonValue routeJson = openApiRouteBuilder.buildRouteJson(
        specOpt.get(), specFile, openApiValidationSettings.failOnResponseViolation,
        openApiValidationSettings.mockMode);  // <-- 4th arg added

The test mocks are set up for 3 parameters:

// Test code (e.g., line 324):
when(mockOpenApiRouteBuilder.buildRouteJson(eq(fakeSpec), eq(specFile), anyBoolean())).thenReturn(routeJson)...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

vharseko and others added 2 commits April 2, 2026 17:00
Removed pull request branch specification from build workflow.
Copilot AI changed the title [WIP] Update RouterHandlerTest to use new 4-argument buildRouteJson fix(test): update RouterHandlerTest mocks to 4-arg buildRouteJson signature Apr 2, 2026
Copilot AI requested a review from vharseko April 2, 2026 16:54
@vharseko
Copy link
Copy Markdown
Member

vharseko commented Apr 2, 2026

@copilot merge from master

Copilot AI and others added 3 commits April 2, 2026 20:13
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Removed pull request branch specification from build workflow.
Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 2, 2026

@copilot merge from master

Done — merged master into this branch (commit b2f7d1d1). The only conflict was a trivial blank-line difference in .github/workflows/build.yml, which was resolved by taking the master version.

@vharseko vharseko marked this pull request as ready for review April 2, 2026 19:51
@vharseko vharseko merged commit ac58d14 into copilot/add-openapi-mock-response-handler Apr 3, 2026
15 of 16 checks passed
@vharseko vharseko deleted the copilot/update-tests-for-4-arg-method branch April 3, 2026 06:52
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