Repository navigation
refactor: readability cleanups (shared resolve helper, decompose server creation) - #209
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two independent readability refactorings, as separate commits:
Extract shared
resolveConfigureWireMockshelper.WireMockTestExecutionListener.resetWireMockServersIfConfiguredhad two near-identical blocks (EnableWireMock-derived entries, then standalone ones) doing the samefilter(resetWireMockServer).map(lookup).forEach(resetAll)afterward. Extracted the "flattenEnableWireMock+ standaloneConfigureWireMockentries for a class" step intoWireMockContextCustomizerFactory.resolveConfigureWireMocks(Class<?>), shrinking the method to one loop. LeftparseDefinitionsandconfigureWireMockForDefaultInstancealone - both have their own validation/selection semantics that don't map cleanly onto a flat resolve, andconfigureWireMockForDefaultInstance's branching (e.g. a multi-entry group still picks index 0 with just a warning) deserves its own pass with dedicated coverage.Split
WireMockServerCreator.createWireMockServer(~120 lines, ~9 distinct concerns) into named steps:buildServerOptions,registerShutdownHooks,publishServerProperties(with smallpublishProperties/publishPropertyhelpers 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. DeriveshttpEnabled/httpsEnabledfrom 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
🤖 Generated with Claude Code