Skip to content

Add unit tests for findUniqueFileName#6623

Open
Kota-Jagadeesh wants to merge 12 commits intocommons-app:mainfrom
Kota-Jagadeesh:fix-5923-tests
Open

Add unit tests for findUniqueFileName#6623
Kota-Jagadeesh wants to merge 12 commits intocommons-app:mainfrom
Kota-Jagadeesh:fix-5923-tests

Conversation

@Kota-Jagadeesh
Copy link
Collaborator

Description (required)

Fixes #5923

What changes did you make and why?

  • the logic update: Modified the findUniqueFileName in UploadWorker.kt to replace the old 5-digit random hash format (12345) with the requested 3-digit hash format #XXX.
  • test implementation: Created UploadWorkerTest.kt to ensure the filename generation logic is robust.
  • visibility vhange: updated findUniqueFileName visibility to internal to allow unit test access while maintaining module-level encapsulation.

Why?
The previous 5-digit format did not meeet the updated project requirements. these changes align the naming convention with the #XXX standard and provide automated testing to ensure filenames are generated correctly and remain unique.


Tests performed (required)

Tested ProdDebug build variant on Local Unit Tests (JUnit 4).

@Kota-Jagadeesh Kota-Jagadeesh self-assigned this Jan 22, 2026
@Kota-Jagadeesh Kota-Jagadeesh changed the title Fix 5923 tests Add unit tests for findUniqueFileName Jan 22, 2026
@whym
Copy link
Collaborator

whym commented Jan 31, 2026

Do we really want to go with the hash ("#") format? The information in #5923 might have been outdated in some part. I think "#" in file names would not be great as @nicolas-raoul said: #5877 (review)

@Kota-Jagadeesh
Copy link
Collaborator Author

Do we really want to go with the hash ("#") format?

@whym I uunderstand that the # character causes thhee issues with the web URLs (if i am not wrong). Would you prefer i use a dash (e.g., image -123.jpg) or a space instead? I will makee sure to update the logic and the tests once you confirm the preferred symbol.

@whym
Copy link
Collaborator

whym commented Feb 3, 2026

I would leave it as it is (using parentheses), if the point here is to add unit tests.

If there is a good reason to change it again, to the dash mark or something else, we can consider it later.

The change from "#" to "()" was done in #6086 .

@Kota-Jagadeesh
Copy link
Collaborator Author

@whym I have reverted the naming logic to the original 5-digit parentheses format and updated the unit tests to match.

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
uploadWorker = mock<UploadWorker>()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think testing against a mocked instance should be avoided where possible.

It seems like findUniqueFileName can be easier to test if it's extracted from UploadWorker, and placed in one of the util-like classes or a new one, if there is no suitable one. (MediaDataExtractor.kt?) What do you think?

@github-actions
Copy link

github-actions bot commented Feb 5, 2026

✅ Generated APK variants!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write tests for findUniqueFilename() in UploadWorker.kt

2 participants

Comments