Skip to content

Add unit tests for ApkArchitectureHelper#17

Merged
samyak2403 merged 2 commits intosamyak2403:mainfrom
SubhrajyotiSen:unit-tests
Feb 10, 2026
Merged

Add unit tests for ApkArchitectureHelper#17
samyak2403 merged 2 commits intosamyak2403:mainfrom
SubhrajyotiSen:unit-tests

Conversation

@SubhrajyotiSen
Copy link
Copy Markdown
Contributor

@SubhrajyotiSen SubhrajyotiSen commented Feb 10, 2026

Summary by CodeRabbit

  • Refactor

    • Improved APK selection and install-flow: app more accurately detects compatible package variants, falls back to “View release” when no installable APK is found, and handles multiple architecture scenarios more robustly.
  • Tests

    • Added comprehensive unit tests covering APK selection and compatibility across various device architecture scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Refactors APK selection to return a sealed ApkSelectionResult, adds AbiProvider for ABI sourcing and testability, updates DetailActivity to handle selection variants, introduces unit tests for selection logic, and adds MockK as a test dependency/version entry.

Changes

Cohort / File(s) Summary
Dependency Management
gradle/libs.versions.toml, app/build.gradle.kts
Added MockK (version entry and library) and added testImplementation(libs.mockk) to the app module for unit testing.
APK Selection Core
app/src/main/java/com/samyak/repostore/util/ApkArchitectureHelper.kt
Reworked selectBestApk to return ApkSelectionResult sealed class (NoApkFound, Single, ExactMatch, Universal, Fallback); introduced AbiProvider; made ABI helpers private; exposed ApkSelectionResult types.
UI Integration
app/src/main/java/com/samyak/repostore/ui/activity/DetailActivity.kt
Replaced nullable APK logic with a when over ApkSelectionResult; added logging and unified install/view-action handling via currentApkAsset.
Tests
app/src/test/java/com/samyak/repostore/util/ApkArchitectureHelperTest.kt
Added comprehensive tests for APK selection behavior, mocking AbiProvider with MockK and adding helpers to construct ReleaseAsset test data.

Sequence Diagram(s)

sequenceDiagram
    participant DetailActivity
    participant ApkArchitectureHelper
    participant AbiProvider
    participant ApkSelectionResult

    DetailActivity->>ApkArchitectureHelper: selectBestApk(assets)
    ApkArchitectureHelper->>AbiProvider: supportedAbis()
    AbiProvider-->>ApkArchitectureHelper: [abi1, abi2, ...]
    ApkArchitectureHelper->>ApkArchitectureHelper: evaluate assets vs ABIs
    alt Exact primary ABI match
        ApkArchitectureHelper-->>ApkSelectionResult: ExactMatch(abi, asset)
    else Universal APK match
        ApkArchitectureHelper-->>ApkSelectionResult: Universal(asset)
    else Secondary ABI fallback
        ApkArchitectureHelper-->>ApkSelectionResult: Fallback(asset)
    else Single asset only
        ApkArchitectureHelper-->>ApkSelectionResult: Single(asset)
    else No APKs found
        ApkArchitectureHelper-->>ApkSelectionResult: NoApkFound
    end
    ApkSelectionResult-->>DetailActivity: selection result
    DetailActivity->>DetailActivity: when(result) { setupInstallButton() / showViewRelease() }
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble code and make a plan,
Sealed results to help you scan.
MockK joins the testing burrow,
ABIs matched — no more sorrow.
Hop, test, and ship — hooray, we ran! 🚀

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.39% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary change: adding unit tests for ApkArchitectureHelper. It is concise, specific, and directly relates to the main content of the pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@gradle/libs.versions.toml`:
- Line 22: Update the MockK dependency entries named "mockk" in the
libs.versions.toml to the latest stable release by changing their version
strings from "1.13.12" to "1.14.9"; locate both occurrences of the "mockk" key
(the one shown and the other occurrence later in the file) and replace the
version value so both references use "1.14.9".
🧹 Nitpick comments (2)
app/src/test/java/com/samyak/repostore/util/ApkArchitectureHelperTest.kt (2)

89-101: Misleading test method name.

The method name selectBestApk_returnsNullWhenNoApkAssets is inaccurate since the method now returns ApkSelectionResult.NoApkFound rather than null. Consider renaming for clarity.

Suggested rename
     `@Test`
-    fun selectBestApk_returnsNullWhenNoApkAssets() {
+    fun selectBestApk_returnsNoApkFoundWhenNoApkAssets() {
         setSupportedAbis("arm64-v8a")

26-101: Consider adding a test for the Single variant.

The ApkSelectionResult.Single variant is returned when exactly one APK is present, but there's no dedicated test for this case. Adding coverage would ensure all branches are tested.

Suggested test case
`@Test`
fun selectBestApk_returnsSingleWhenOnlyOneApk() {
    setSupportedAbis("arm64-v8a")

    val assets = listOf(
        apk("app-release.apk")
    )

    val selected = ApkArchitectureHelper.selectBestApk(assets)

    assertTrue(selected is ApkSelectionResult.Single)
    assertEquals("app-release.apk", (selected as ApkSelectionResult.Single).asset.name)
}

@samyak2403 samyak2403 merged commit d1973ad into samyak2403:main Feb 10, 2026
1 check passed
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