Skip to content

refactor: replace repetitive command/query integration tests with mock harness tests - #189

Merged
andreasgrill merged 1 commit into
mainfrom
refactor/mock-harness-tests
Sep 13, 2026
Merged

andreasgrill merged 1 commit into
mainfrom
refactor/mock-harness-tests

Conversation

@andreasgrill

Copy link
Copy Markdown
Collaborator

Summary

Closes #187.

Most command and query integration tests started a Mosquitto container and simulated the backend over MQTT. The extension functions they test are thin wrappers around sendCommandAsync / queryListAsync, so MQTT transport, login and correlation were tested ~95 times.

  • New test harness util/MockedXesarConnect: mocked MqttAsyncClient, published messages are recorded, respondTo(topic) { emitMessage(...) } simulates the backend. No Docker required.
  • 94 tests converted to command/ and query/. Calls, events, assertions and expected JSON payloads are unchanged. Each test still checks the extension function wiring: topic, argument mapping into the command/query, and awaited events.
  • Kept as integration tests: it/command/LockMediumTest (single event), it/command/ChangeAuthorizationProfileTest (multiple events), it/query/QueryCalendarTest, plus the lifecycle/connection tests (ConnectAndLoginTest, MqttConnectionLostTest, ListenerTest, DelayUntilCloseTest, SubscribedTopicsTest, QueryStreamTest, …) and it/event/.
  • Small changes:
    • RequestNewRegistrationCodeMapi test renamed to RequestNewRegistrationCodeTest.
    • The "no result" medium identifier query now asserts the published payload.
    • CLAUDE.md documents the harness.

Unlike the issue's proposal (pure encoding/decoding tests), the harness keeps coverage of the extension function wiring.

Test plan

  • ./gradlew spotlessApply test with JDK 11: 269 tests pass

🤖 Generated with Claude Code

…k harness tests

Most command and query integration tests started a Mosquitto container and
simulated the backend over MQTT, although the extension functions under test
are thin wrappers around sendCommandAsync/queryListAsync.

- add MockedXesarConnect test harness (mocked MqttAsyncClient, recorded
  publishes, responders simulating the backend)
- convert 94 command/query integration tests into harness tests in command/
  and query/ with unchanged calls, events, assertions and expected payloads
- keep LockMediumTest, ChangeAuthorizationProfileTest and QueryCalendarTest
  as representative integration tests
- rename RequestNewRegistrationCodeMapi test to RequestNewRegistrationCodeTest
- assert the published payload for the "no result" medium identifier query
- document the harness in CLAUDE.md

Closes: #187

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

refactor: replace repetitive command/query integration tests with unit tests

1 participant