ADFA-4312 Mock NetworkUtils in CloneRepositoryViewModelTest#1400
ADFA-4312 Mock NetworkUtils in CloneRepositoryViewModelTest#1400hal-eisen-adfa wants to merge 1 commit into
Conversation
Surfaced by the nightly Jacoco/SonarQube analyze.yml run after the ADFA-4306 (#1385) fixes landed. Four :app testV8DebugUnitTest cases failed: * cloneRepository fails if destination directory does not exist after clone * cloneRepository failure updates UI with error message * test clone repository with auth is successful * cloneRepository success updates UI state correctly CloneRepositoryViewModel.cloneRepository() calls blankj.utilcode.NetworkUtils.isConnected(), which lazily fires Utils.init() -> android.util.Log.e(). Under the plain JVM test runner Log is not stubbed, so the call throws RuntimeException("Method e in android.util.Log not mocked.") before any assertion runs. ADFA-4306 suggested mockkStatic(Log::class) (mirroring the FileDeleteUtilsTest fix), but for this VM that only patches the transitive symptom and still leaves NetworkUtils.getActiveNetworkInfo() walking into Utils.getApp().getSystemService(...) with no Application context. The more surgical fix is to mock NetworkUtils directly: mockkStatic(NetworkUtils::class) every { NetworkUtils.isConnected() } returns true That matches the semantic intent of these tests (they exercise the clone attempt path, which presumes connectivity) without depending on blankj internals. The existing @after unmockkAll() already covers cleanup. Verified locally by re-running the analyze.yml gradle command (:testing:tooling:assemble :testing:common:assemble sonarqube --info --no-build-cache -x lint --continue): CloneRepositoryViewModelTest now reports tests=9 failures=0 errors=0.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughRelease Notes
Notes and Considerations
WalkthroughAdds static mocking of ChangesNetworkUtils Static Mock in CloneRepositoryViewModelTest
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes ADFA-4312 — four
:app testV8DebugUnitTestcases inCloneRepositoryViewModelTestfail under the nightlyanalyze.ymlJacoco/SonarQube run withRuntimeException: Method e in android.util.Log not mocked.CloneRepositoryViewModel.cloneRepository()callsblankj.utilcode.NetworkUtils.isConnected(), which lazily invokesUtils.init()→android.util.Log.e(). The plain JVM test runner has noLogstub, so the call throws before any assertion runs.mockkStatic(NetworkUtils::class)and stubisConnected()to returntrue. Matches the semantic intent of these tests (they exercise the clone-attempt path, which presumes connectivity) and avoids depending on blankj-utilcode internals — unlike themockkStatic(Log::class)approach suggested in the ticket, which only patches the transitive symptom and would still leaveNetworkUtils.getActiveNetworkInfo()reaching for an Application context.@After unmockkAll()already covers cleanup; no other test changes.Heads-up filed on the ticket:
GitBottomSheetViewModel.ktlines 180 and 250 also callNetworkUtils.isConnected(). No JVM test exercises those paths today, so analyze.yml is not failing on them — but any future test will need the same treatment.Test plan
:app:testV8DebugUnitTest --tests "com.itsaky.androidide.viewmodel.CloneRepositoryViewModelTest"— 9 tests pass, 0 failures, 0 errors (the 4 previously-failing cases now pass).:testing:tooling:assemble :testing:common:assemble sonarqube --info --no-build-cache -x lint --continue).CloneRepositoryViewModelTestreportstests=9 failures=0 errors=0. Other unrelated failures in that run (CompilerTest,IndexingServiceManagerTest, and the SonarCloud upload itself failing for lack of a localSONAR_TOKEN) are pre-existing and outside the scope of this ticket.stageafter merge no longer reports the fourCloneRepositoryViewModelTestfailures.