Skip to content

Refactor: comprehensive unit tests for FileUtils (Deletion, Validation & Storage)#4721

Open
harshsomankar123-tech wants to merge 2 commits intokiwix:mainfrom
harshsomankar123-tech:part01file
Open

Refactor: comprehensive unit tests for FileUtils (Deletion, Validation & Storage)#4721
harshsomankar123-tech wants to merge 2 commits intokiwix:mainfrom
harshsomankar123-tech:part01file

Conversation

@harshsomankar123-tech
Copy link
Contributor

@harshsomankar123-tech harshsomankar123-tech commented Feb 24, 2026

fixes #4713
Summary
This PR significantly improves the code coverage of FileUtils.kt by adding comprehensive unit tests for critical file operations, ZIM validation, and storage path resolution. It achieves >90% coverage for the file.

Changes

  • Preserved Existing Tests: Kept the original tests for getAllZimParts to ensure no regression in split-archive detection.
  • Added Deletion Logic: Added tests for deleteZimFile to verify correct removal of .zim, .part, and split chunks (.zimaa, etc.).
  • Added Validation Logic: Added tests for isValidZimFile and isSplittedZimFile to validate file extensions and types.
  • Added Storage & URI Logic: Added tests for getStoragePath and getLocalFilePathByUri using MockK to mock Android static classes (Environment, Uri, Context).

Technical Details

  • Used mockkStatic to mock Kotlin extension functions and Android.os.Environment.
  • Covered edge cases for file collision (e.g., when both book.zim and book.zim.part exist).
  • Verified safety checks for file descriptors to prevent runtime crashes.

@atharvyadav22
Copy link
Contributor

@harshsomankar123-tech i have recently changed File Utils please view that and add tests accordingly as i have made new features

@harshsomankar123-tech harshsomankar123-tech marked this pull request as draft February 24, 2026 17:48
@harshsomankar123-tech
Copy link
Contributor Author

@atharvyadav22 Sure, I’ll update the tests accordingly

@harshsomankar123-tech harshsomankar123-tech changed the title Refactor: unit tests for FileUtils Part01 Refactor: comprehensive unit tests for FileUtils (Deletion, Validation & Storage) Feb 25, 2026
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.56%. Comparing base (0bf40b7) to head (9fe178a).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4721      +/-   ##
============================================
+ Coverage     60.48%   60.56%   +0.08%     
+ Complexity     1625     1619       -6     
============================================
  Files           327      330       +3     
  Lines         15615    15726     +111     
  Branches       2146     2162      +16     
============================================
+ Hits           9445     9525      +80     
- Misses         4731     4734       +3     
- Partials       1439     1467      +28     

☔ 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.

@harshsomankar123-tech harshsomankar123-tech marked this pull request as ready for review February 26, 2026 03:45
@harshsomankar123-tech
Copy link
Contributor Author

harshsomankar123-tech commented Feb 26, 2026

@MohitMaliFtechiz could you please review this when you get time? Thanks!

@MohitMaliFtechiz MohitMaliFtechiz self-requested a review February 26, 2026 12:36
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.

Improve code coverage for FileUtils: Deletion, Validation & Storage Logic

2 participants