Unit tests for Acquire class #225
Open
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.
Description
This PR introduces unit tests for the Acquire feature in the mobile policies module. The tests validate CHFID input handling, scan and camera interactions, image validation, file creation, database updates, menu behavior, and photo processing logic as handled by the activity layer.
The Android environment and external dependencies are mocked to isolate UI and business logic and ensure consistent behavior without relying on real camera hardware, file system, or database access.
Type of change
Chore (Testing / CI)
CheckLists
Unit Tests added:
Acquire – Scan and camera interactions
clickingScan_shouldLaunchZXing – PASSED ✅
Ensures the QR code scanner activity is launched with the correct intent and scan mode.
clickingTakePhoto_withCHF_shouldLaunchCamera – PASSED ✅
Ensures the camera intent is launched when a valid CHFID is provided, with a proper output URI.
Acquire – Activity result handling
onActivityResult_scan_shouldFillCHFID – PASSED ✅
Ensures the CHFID field is correctly populated when a scan result is returned.
Acquire – Validation logic
isValidate_missingImage_returnsFalse – PASSED ✅
Ensures validation fails when the insuree image is missing.
isValidate_valid_returnsTrue – PASSED ✅
Ensures validation succeeds when both CHFID and image are present.
Acquire – Menu handling
menuStatistics_withoutInternet_returnsFalse – PASSED ✅
Ensures the statistics menu action is not processed when network connectivity is unavailable.
Acquire – Data submission and persistence
submitData_shouldCreateFile_andUpdateSql – PASSED ✅
Ensures image data is written to a file and insuree data is correctly updated in the local database.
submitData_emptyFile_returnsZero – PASSED ✅
Ensures no database update occurs when the generated image file is empty.
Notes
Backend and network calls are not executed; database access and external services are fully mocked.
Android system components (Intents, ImageView, EditText, MenuItem) are simulated using Robolectric.
Image handling, file creation, and compression logic are tested without accessing the real filesystem.
Network availability and application configuration are mocked via the Global dependency.
Tests ensure reliable validation, correct intent triggering, robust error handling, and proper data persistence behavior.