Unit tests for MapItems class #118
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 MapItems feature in the mobile claims module. The tests validate that item mapping logic, list binding, user interactions, filtering, persistence behavior, and dialog handling are correctly processed and exposed by the activity layer.
The Android environment and database interactions are mocked to isolate UI and business logic, ensuring deterministic behavior without relying on a real database.
Type of change
Chore (Testing / CI)
CheckLists
Unit Tests added:
MapItems – Item loading and binding
bindItemList_loadsItemsCorrectly – PASSED ✅
Ensures items retrieved from the database cursor are correctly loaded into the ItemsList, with proper handling of unmapped items and resource cleanup.
MapItems – Item selection handling
clickingItem_togglesIsMapped – PASSED ✅
Ensures clicking on a list item correctly toggles its isMapped state.
MapItems – Bulk selection logic
checkAll_setsAllItemsMapped – PASSED ✅
Ensures the “check/uncheck all” action correctly updates the isMapped flag for all items in the list.
MapItems – Save and persistence logic
save_returnsCorrectCodes – PASSED ✅
Ensures the save operation returns the correct status code depending on whether items are mapped or unmapped.
save_returns2_whenInsertFails – PASSED ✅
Ensures the save operation returns error code 2 when database insertion fails.
MapItems – Filtering logic
filter_searchWorksCorrectly – PASSED ✅
Ensures the adapter filter correctly narrows the item list based on the search query.
MapItems – Adapter view rendering
adapter_getView_setsCorrectValues – PASSED ✅
Ensures the adapter correctly inflates and populates the list item view.
MapItems – Dialog handling
showDialog_createsAlertDialog – PASSED ✅
Ensures the activity correctly creates and returns an AlertDialog when requested.
Notes
Database operations are fully mocked via SQLHandler to isolate activity logic.
Cursor behavior is simulated to control dataset iteration and edge cases.
UI components and lifecycle are handled using Robolectric.
Tests ensure correct item mapping behavior, filtering, persistence logic, and user interaction handling without real database access.