Skip to content

Replace MarketDataClient builder with explicit constructors#4

Merged
MarketDataDev03 merged 3 commits into
mainfrom
04_change_marketdataclient_ctr
May 8, 2026
Merged

Replace MarketDataClient builder with explicit constructors#4
MarketDataDev03 merged 3 commits into
mainfrom
04_change_marketdataclient_ctr

Conversation

@MarketDataDev03

Copy link
Copy Markdown
Collaborator

Replace MarketDataClient builder with explicit constructors

Summary

Removes the MarketDataClient.Builder pattern in favour of two public
constructors — a no-arg one for the production happy path (everything resolved
from the §4 cascade) and a 4-arg one for tests and short-lived runtimes that
need explicit control. All fields stay final; the client remains immutable.

Motivation

The previous MarketDataClient.builder()...build() shape carried more
ceremony than the surface warrants: the type has 4 settable knobs, three of
which are routinely left at their default. The team chose to favour a direct
constructor surface — new MarketDataClient() for production and new MarketDataClient(apiKey, baseUrl, apiVersion, validateOnStartup) for explicit
control — over the fluent builder, accepting the trade-off that adding a 5th
knob in the future will require either a new overload or a SemVer bump.

Changes

MarketDataClient (src/main/java/com/marketdata/sdk/MarketDataClient.java)

  • Removed the inner Builder class and the static Builder builder() factory.
  • Added two public constructors:
    • MarketDataClient() — production constructor. Delegates via this(...) to
      the master constructor with null, null, null, true. All settings come
      from the cascade (env var → .env → built-in default); startup validation
      is enabled.
    • MarketDataClient(@Nullable String apiKey, @Nullable String baseUrl, @Nullable String apiVersion, boolean validateOnStartup) — master
      constructor. Holds the cascade-resolution and initialisation logic. Each
      nullable parameter still falls back to the cascade for that single value.
  • Fields are unchanged in shape and remain final. The client is immutable.
  • Class-level Javadoc rewritten to describe both constructors and to call out
    that instances are immutable.

Test suite (src/test/java/com/marketdata/sdk/MarketDataClientTest.java)

  • Migrated all 5 existing call sites from .builder()...build() to the
    matching constructor invocation.
  • Added a new test, noArgConstructorAppliesProductionDefaults, that
    exercises new MarketDataClient() directly and asserts the contract:
    • isValidateOnStartup() is true (env-independent — encoded in the no-arg
      constructor).
    • getUserAgent() starts with marketdata-sdk-java/.
    • getBaseUrl() and getApiVersion() fall back to the documented defaults
      when no MARKETDATA_* env override is set (gated on System.getenv like
      the existing demoModeWhenNoTokenAvailable test).
  • The demoModeWhenNoTokenAvailable test now uses new MarketDataClient()
    (its assertion was already valid; the call site just dropped the
    three-null clutter).

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

The author of this PR, MarketDataDev03, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at support@codecov.io with any questions.

Comment thread README.md Outdated
Comment thread README.md Outdated
MarketDataDev03 and others added 2 commits May 8, 2026 10:46
The previous commit dropped the (ADR-002) parentheticals from the exception
javadoc but the resulting reflow placed the leading words ("a", "{@code") at
the start of the next line. Spotless prefers them at the end of the previous
line; CI's spotlessJavaCheck flagged both files. This applies the
spotlessApply output verbatim — no behaviour or content change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MarketDataDev03 MarketDataDev03 merged commit 326e19d into main May 8, 2026
3 checks passed
@MarketDataDev03 MarketDataDev03 deleted the 04_change_marketdataclient_ctr branch May 8, 2026 13:54
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