Skip to content

refactor: coroutine dispatchers and modernize testing infrastructure#4901

Merged
jamesarich merged 7 commits intomainfrom
refactor/di
Mar 24, 2026
Merged

refactor: coroutine dispatchers and modernize testing infrastructure#4901
jamesarich merged 7 commits intomainfrom
refactor/di

Conversation

@jamesarich
Copy link
Copy Markdown
Collaborator

This pull request introduces several improvements to dependency injection and coroutine management, particularly focusing on standardizing the use of custom coroutine dispatchers across the codebase. It also updates and modernizes various test classes to use the latest mocking libraries and patterns, ensuring more robust and maintainable tests.

Dependency injection and coroutine dispatchers:

  • Added CoreDiModule to the Koin module includes in AppKoinModule to ensure core dependencies are available throughout the app.
  • Removed the manual provision of CoroutineDispatchers from AppKoinModule, as this is now handled by the new module.
  • Updated MQTTRepositoryImpl and MeshServiceOrchestrator to accept and use an injected CoroutineDispatchers instance instead of directly referencing Dispatchers.Default, promoting consistency and testability. [1] [2] [3] [4] [5] [6]

Test modernization and improvements:

  • Modernized the MeshConnectionManagerImplTest and MeshServiceOrchestratorTest classes by switching to the mokkery mocking library, using autofill mocks, and updating test lifecycle annotations. This results in cleaner, more maintainable, and more reliable tests. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Added the core.testing project as a dependency for common tests, ensuring access to shared test utilities.

… stubs

- Migrate hardcoded `Dispatchers` to an injected `CoroutineDispatchers` abstraction across `MQTTRepository`, `ScannerViewModel`, `DebugViewModel`, and `MeshServiceOrchestrator` to improve testability.
- Update integration and unit tests to utilize `UnconfinedTestDispatcher` through the injected dispatcher provider.
- Introduce `Noop` stubs for firmware management (`FirmwareUpdateManager`, `FirmwareUsbManager`, `FirmwareFileHandler`) in the desktop module.
- Consolidate `CoroutineDispatchers` dependency injection configuration into `CoreDiModule`.
- Add missing feature module dependencies (Firmware, Intro, Map) to the desktop Koin configuration and build script.
- Introduce `FakeMeshLogRepository` and `FakeMeshLogPrefs` in the `core:testing` module to facilitate state-based testing.
- Restore and refactor `MeshServiceOrchestratorTest`, `MeshConnectionManagerImplTest`, and `DebugViewModelTest`, migrating them to Mokkery and utilizing fakes.
- Enhance `FakeRadioController` to track the last set device address for easier verification in tests.
- Update `ScannerViewModelTest` to use the improved fake radio controller and clean up dispatcher initialization.
- Add the `core:testing` dependency to the `core:data` module.
- Introduce `FakeMeshLogRepository` and `FakeMeshLogPrefs` in the `core:testing` module to facilitate state-based testing.
- Restore and refactor `MeshServiceOrchestratorTest`, `MeshConnectionManagerImplTest`, and `DebugViewModelTest`, migrating them to Mokkery and utilizing fakes.
- Enhance `FakeRadioController` to track the last set device address for easier verification in tests.
- Update `ScannerViewModelTest` to use the improved fake radio controller and clean up dispatcher initialization.
- Add the `core:testing` dependency to the `core:data` module.
- Introduce `FakeServiceRepository` to provide a consistent test double for service actions, connection states, and mesh packet flows.
- Update `SharedContactViewModelTest`, `ConnectionsViewModelTest`, and `ScannerViewModelTest` to use `FakeNodeRepository` and `FakeServiceRepository` instead of manual mocks.
- Rename `FakePrefs.kt` to `FakeMeshLogPrefs.kt` and refactor `FakeMeshLogRepository` to improve internal naming consistency and address lint warnings.
- Add `core:testing` as a dependency for `core:ui` tests and expose `kermit` via the testing module.
- Suppress minor lint warnings in stub and fake implementations for empty blocks and function counts.
@github-actions github-actions Bot added the refactor no functional changes label Mar 24, 2026
jamesarich and others added 3 commits March 23, 2026 19:31
…implementation

This commit refactors how connection status notifications are generated by moving the string formatting logic from the common `MeshConnectionManagerImpl` to the platform-specific `MeshServiceNotificationsImpl` on Android. This decouples the core logic from UI resource strings and centralizes notification construction.

Specific changes include:
- **`MeshConnectionManagerImpl`**: Simplified `updateStatusNotification` to pass the raw `ConnectionState` object instead of a pre-formatted string. Removed associated resource imports.
- **`MeshServiceNotifications` interface**: Updated `updateServiceStateNotification` signature to accept `ConnectionState` instead of a nullable string.
- **`MeshServiceNotificationsImpl` (Android)**: Implemented the string mapping logic for `ConnectionState` using localized resources (`meshtastic_app_name`, `connected`, `disconnected`, etc.).
- **`MeshConnectionManagerImplTest`**: Updated mocks to handle the new connection state flow and notification calls.
- **Maintenance**: Added `LargeClass` suppression to `MeshServiceNotificationsImpl` and updated imports.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
…tate`

This commit refactors the `updateServiceStateNotification` method signature within the `MeshServiceNotifications` interface and its implementations. The `summaryString: String?` parameter has been replaced with a more structured `state: ConnectionState` parameter to provide better context for notification updates across platforms.

Specific changes include:
- Updated `DesktopMeshServiceNotifications` to accept `org.meshtastic.core.model.ConnectionState`.
- Updated `Fakes.kt` in the test suite to reflect the new method signature.
- Updated `NoopStubs.kt` in the desktop module to align with the interface change.

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
@jamesarich jamesarich added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 96060a0 Mar 24, 2026
7 checks passed
@jamesarich jamesarich deleted the refactor/di branch March 24, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor no functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant