Skip to content

refactor: readability cleanups (shared resolve helper, decompose server creation) - #209

Merged
tomasbjerre merged 3 commits into
mainfrom
refactor/readability-cleanups
Sep 19, 2026
Merged

tomasbjerre merged 3 commits into
mainfrom
refactor/readability-cleanups

Conversation

@tomasbjerre

Copy link
Copy Markdown
Collaborator

Summary

Two independent readability refactorings, as separate commits:

  1. Extract shared resolveConfigureWireMocks helper. WireMockTestExecutionListener.resetWireMockServersIfConfigured had two near-identical blocks (EnableWireMock-derived entries, then standalone ones) doing the same filter(resetWireMockServer).map(lookup).forEach(resetAll) afterward. Extracted the "flatten EnableWireMock + standalone ConfigureWireMock entries for a class" step into WireMockContextCustomizerFactory.resolveConfigureWireMocks(Class<?>), shrinking the method to one loop. Left parseDefinitions and configureWireMockForDefaultInstance alone - both have their own validation/selection semantics that don't map cleanly onto a flat resolve, and configureWireMockForDefaultInstance's branching (e.g. a multi-entry group still picks index 0 with just a warning) deserves its own pass with dedicated coverage.

  2. Split WireMockServerCreator.createWireMockServer (~120 lines, ~9 distinct concerns) into named steps: buildServerOptions, registerShutdownHooks, publishServerProperties (with small publishProperties/publishProperty helpers replacing 4 repeated near-identical blocks for HTTP/HTTPS base URL/port properties). The top-level method now reads as a short sequence of steps instead of a wall of code. Derives httpEnabled/httpsEnabled from the started server (isHttpEnabled()/isHttpsEnabled()) instead of threading locals through, since they're equivalent. Log message text is unchanged (verified nothing asserts on it).

No behavior changes in either commit - pure decomposition/dedup, same results, same ordering.

Test plan

  • Full test suite passes after each commit, run 3x.

🤖 Generated with Claude Code

tomasbjerre and others added 3 commits September 19, 2026 22:25
WireMockTestExecutionListener.resetWireMockServersIfConfigured had
two near-identical blocks - one iterating EnableWireMock-derived
ConfigureWireMock entries, one iterating standalone ones - that both
did the same filter(resetWireMockServer).map(lookup).forEach(resetAll)
afterward. The "flatten EnableWireMock + standalone ConfigureWireMock
entries for a class" step itself was also duplicated with
WireMockContextCustomizerFactory.parseDefinitions.

Extracts that resolution into
WireMockContextCustomizerFactory.resolveConfigureWireMocks(Class<?>),
and uses it in resetWireMockServersIfConfigured, which shrinks from
two loops to one. parseDefinitions is left as-is since it has
different semantics (validates via add(), skips by name via
addIfAbsent()) that don't map cleanly onto a flat resolve.

configureWireMockForDefaultInstance also duplicates this resolution
step, but its "pick the one default candidate" branching has enough
particular behavior (e.g. a multi-entry EnableWireMock group still
picks index 0 with just a log warning, while multiple groups aborts
entirely) that folding it into this helper deserves its own pass with
dedicated test coverage rather than being bundled here.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… steps

The method mixed ~9 distinct concerns inline - resolving ports and TLS,
mappings/extensions/templating/customizers, starting the server,
registering shutdown hooks, publishing 4 groups of Spring properties in
near-identical blocks, and Spring bean registration - in one ~120 line
method. Split into buildServerOptions, registerShutdownHooks and
publishServerProperties (plus small publishProperties/publishProperty
helpers replacing the 4 repeated blocks), so the top-level method now
reads as a short sequence of named steps.

Derives httpEnabled/httpsEnabled from the started WireMockServer
(isHttpEnabled()/isHttpsEnabled()) instead of threading local booleans
computed earlier in the method through to the property-publishing
step - same values, one less thing to pass around.

Log message text is unchanged (verified no test asserts on it).
Behavior and ordering are otherwise identical.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Resolves the conflict in WireMockServerCreator.java against #208
(merged to main after this branch was opened) by keeping this
branch's decomposed version, which already removes the same
unnecessary collect(toList()) calls as part of splitting
createWireMockServer into named steps. WireMockContextCustomizerFactory.java
merged cleanly, picking up #208's O(n^2) duplicate-detection fix
alongside this branch's resolveConfigureWireMocks addition.
@tomasbjerre
tomasbjerre merged commit 6556077 into main Sep 19, 2026
6 checks passed
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.

1 participant