Skip to content

Claude/dana#4330

Merged
MilosKozak merged 17 commits intodevfrom
claude/dana-drivers-01Q47YWSz39ES8MjmZcK5fMF
Nov 18, 2025
Merged

Claude/dana#4330
MilosKozak merged 17 commits intodevfrom
claude/dana-drivers-01Q47YWSz39ES8MjmZcK5fMF

Conversation

@MilosKozak
Copy link
Contributor

No description provided.

claude and others added 17 commits November 18, 2025 13:31
…ication classes

This commit adds test coverage for all Dana driver execution services and
communication layer classes that were previously untested:

Execution Services:
- AbstractDanaRExecutionService: Base class tests covering connection management,
  bolus stop, history loading, sanity checks, and Bluetooth socket initialization
- DanaRExecutionService: Tests for Dana R-specific operations including temp basal,
  extended bolus, profile updates, and user options
- DanaRKoreanExecutionService: Tests for Korean variant with specific basal rates
  and profile handling
- DanaRv2ExecutionService: Tests for v2 protocol including high temp basal,
  short duration temp basals, and event loading
- DanaRSService: Tests for BLE-based Dana RS including connection management,
  bolus operations, temp basals, extended bolus, and history loading

Communication Classes:
- SerialIOThread: Tests for Bluetooth Serial communication thread covering
  disconnect, message sending, and thread lifecycle
- BLEComm: Tests for Bluetooth Low Energy communication covering connection,
  disconnection, device bonding, and message sending

All tests follow the existing test patterns in the codebase using JUnit 5,
Mockito, and Google Truth assertions. Tests verify both success and failure
paths, including null checks, connection state validation, and proper error
handling.
Update all Dana driver tests to be compatible with dev branch changes:
- Replace instantiator with pumpEnactResultProvider (Provider<PumpEnactResult>)
- Update bolus() method signature to use DetailedBolusInfo instead of multiple parameters
- Add messageHashTable() abstract method implementation
- Update Preferences import path to app.aaps.core.keys.interfaces.Preferences
- Remove EventOverviewBolusProgress.Treatment references
- Fix all compilation errors caused by API changes in dev branch

These changes ensure tests compile with the updated Dana driver APIs while
maintaining full test coverage.
Add Mock Provider instances and packet mocks for:
- DanaRSPacketGeneralInitialScreenInformation
- DanaRSPacketOptionSetUserOption
- DanaRSPacketBolusSetStepBolusStop
- DanaRSPacketAPSBasalSetTemporaryBasal
- DanaRSPacketBasalSetCancelTemporaryBasal

These providers are used by the service via dependency injection and
were causing UninitializedPropertyAccessException in tests:
- testHighTempBasal
- testSetUserSettings
- testBolusStop
- testTempBasalShortDuration_validDuration15
- testTempBasalShortDuration_validDuration30
Add missing @mock declaration for HasAndroidInjector which was being
used in setup() but not declared, causing MissingMethodInvocationException.
Add mock for PumpEnactResult and configure it to return success=true
in the testLoadEvents test. The loadEvents() method returns
pumpEnactResultProvider.get() which needs to have success set to true
for the test to pass.
…t for DanaPump

Changed from using when() to direct property assignment for DanaPump var
properties. Mockito doesn't work correctly with when() on var properties of
concrete Kotlin classes. This fixes the tests:
- testDoSanityCheck_temporaryBasalInAAPSButNotInPump
- testDoSanityCheck_extendedBolusMismatch

The tests were failing because uiInteraction.addNotification() was not being
called due to incorrect mock setup.
Changed DanaPump from @mock to real instance. The issue was that direct
property assignment doesn't work on Mock objects - mocks need when() for
configuring getters. By using a real DanaPump instance, we can directly
set properties like isTempBasalInProgress, isExtendedInProgress, etc.

This fixes the doSanityCheck tests where uiInteraction.addNotification()
was not being called because the mock properties weren't being set correctly.
Fixed issues with DanaPump property setters that only allow setting to false:
1. Removed direct assignments to isTempBasalInProgress and isExtendedInProgress
2. Instead set underlying properties (tempBasalStart, tempBasalDuration,
   extendedBolusStart, extendedBolusDuration) which the getters use
3. Fixed duration values to be in milliseconds (not minutes)
4. Adjusted dateUtil.now() to return values within the active range

The properties have custom setters that throw IllegalArgumentException when
trying to set to true. The getters calculate the status based on start time,
duration, and current time.
…cturing

Changed from mocking PumpState to creating real instances. The doSanityCheck
method uses Kotlin destructuring: val (temporaryBasal, extendedBolus) = pumpSync.expectedPumpState()

Mockito mocks don't support Kotlin data class destructuring (component1/component2 methods).
By using real PumpState instances with mock TemporaryBasal and ExtendedBolus objects,
the destructuring works correctly.

This fixes tests where uiInteraction.addNotification() was not being called because
the destructuring was failing silently with mocked PumpState.
Removed the assignment of danaPump.tempBasalStart in the extended bolus
mismatch test. Setting tempBasalStart without tempBasalDuration could
interfere with the test logic, even though the temp basal should not be
active in this test case.

Leaving tempBasalStart at its default value (0) ensures that
isTempBasalInProgress returns false, allowing the test to focus solely
on the extended bolus mismatch scenario.
…ions

Fixed two issues:
1. Set dateUtil.now() mock BEFORE accessing danaPump properties that use
   isExtendedInProgress getter (which calls dateUtil.now())
2. Changed extendedBolus.timestamp to 500000L to create a timestamp
   difference of 500000ms (> 10000ms threshold)

This ensures both mismatch conditions are met:
- Rate mismatch: 1.5 != 2.0
- Timestamp mismatch: abs(500000 - 1000000) = 500000 > 10000

The notification should now be triggered as expected.
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.84%. Comparing base (95b9a23) to head (4b522a3).
⚠️ Report is 102 commits behind head on dev.

Additional details and impacted files
@@             Coverage Diff              @@
##                dev    #4330      +/-   ##
============================================
+ Coverage     30.63%   30.84%   +0.21%     
- Complexity     7610     7741     +131     
============================================
  Files          2381     2381              
  Lines        122012   122012              
  Branches      15725    15725              
============================================
+ Hits          37376    37634     +258     
+ Misses        81766    81446     -320     
- Partials       2870     2932      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MilosKozak MilosKozak merged commit f4f602a into dev Nov 18, 2025
6 of 7 checks passed
@MilosKozak MilosKozak deleted the claude/dana-drivers-01Q47YWSz39ES8MjmZcK5fMF branch November 18, 2025 21:43
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