Fix/6404 app crashes theme change multi upload (#6429)

* Prevent IndexOutOfBoundsException in setUploadMediaDetails by validating index and list size (#6404)

* fixed UninitializedPropertyAccessException by safely initializing and accessing imageAdapter (#6404)

* fixed indexOutOfBoundsException by safely handling saved state and index in onViewCreated (#6404)

* resolve Unresolved reference by replacing setImageToBeUploaded with direct field assignments (#6404)

* Fix test compilation by removing obsolete testSetImageToBeUploaded and adding tha testInitializeFragmentWithUploadItem (#6404)

* Fix test compilation by removing testInitializeFragmentWithUploadItem with unresolved onImageProcessed (#6404)

* fix: test failures in UploadMediaDetailFragmentUnitTest by removing obsolete tests and initializing defaultKvStore (#6404)

* Fixed all the typos

---------

Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
VoidRaven 2025-10-11 18:08:07 +05:30 committed by GitHub
parent 2a9d5db51e
commit 4c621364c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 154 additions and 115 deletions

View file

@ -145,6 +145,8 @@ class UploadMediaDetailFragmentUnitTest {
ibExpandCollapse = view.findViewById(R.id.ib_expand_collapse)
Whitebox.setInternalState(fragment, "uploadMediaDetailAdapter", uploadMediaDetailAdapter)
Whitebox.setInternalState(fragment, "defaultKvStore", defaultKvStore)
`when`(defaultKvStore.getString("description_language", "")).thenReturn("en")
}
@Test
@ -160,16 +162,10 @@ class UploadMediaDetailFragmentUnitTest {
fragment.onCreate(Bundle())
}
@Test
@Throws(Exception::class)
fun testSetImageToBeUploaded() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.setImageToBeUploaded(null, null, location)
}
@Test
@Throws(Exception::class)
fun testOnCreateView() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
fragment.onCreateView(layoutInflater, null, savedInstanceState)
}
@ -181,34 +177,6 @@ class UploadMediaDetailFragmentUnitTest {
fragment.onViewCreated(view, savedInstanceState)
}
@Test
@Throws(Exception::class)
fun testInit() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
Whitebox.setInternalState(fragment, "presenter", presenter)
val method: Method =
UploadMediaDetailFragment::class.java.getDeclaredMethod(
"initializeFragment",
)
method.isAccessible = true
method.invoke(fragment)
}
@Test
@Throws(Exception::class)
fun testInitCaseGetIndexInViewFlipperNonZero() {
Shadows.shadowOf(Looper.getMainLooper()).idle()
Whitebox.setInternalState(fragment, "presenter", presenter)
`when`(callback.getIndexInViewFlipper(fragment)).thenReturn(1)
`when`(callback.totalNumberOfSteps).thenReturn(5)
val method: Method =
UploadMediaDetailFragment::class.java.getDeclaredMethod(
"initializeFragment",
)
method.isAccessible = true
method.invoke(fragment)
}
@Test
@Throws(Exception::class)
fun testShowInfoAlert() {
@ -317,7 +285,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testShowExternalMap() {
shadowOf(Looper.getMainLooper()).idle()
Shadows.shadowOf(Looper.getMainLooper()).idle()
`when`(uploadItem.gpsCoords).thenReturn(imageCoordinates)
`when`(imageCoordinates.decLatitude).thenReturn(0.0)
`when`(imageCoordinates.decLongitude).thenReturn(0.0)
@ -328,7 +296,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testOnCameraPositionCallbackOnMapIconClicked() {
shadowOf(Looper.getMainLooper()).idle()
Shadows.shadowOf(Looper.getMainLooper()).idle()
Mockito.mock(LocationPicker::class.java)
val intent = Mockito.mock(Intent::class.java)
val cameraPosition = Mockito.mock(CameraPosition::class.java)
@ -357,7 +325,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testOnCameraPositionCallbackAddLocationDialog() {
shadowOf(Looper.getMainLooper()).idle()
Shadows.shadowOf(Looper.getMainLooper()).idle()
Mockito.mock(LocationPicker::class.java)
val intent = Mockito.mock(Intent::class.java)
val cameraPosition = Mockito.mock(CameraPosition::class.java)
@ -427,7 +395,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testRememberedZoomLevelOnNull() {
shadowOf(Looper.getMainLooper()).idle()
Shadows.shadowOf(Looper.getMainLooper()).idle()
Whitebox.setInternalState(fragment, "defaultKvStore", defaultKvStore)
`when`(uploadItem.gpsCoords).thenReturn(null)
`when`(defaultKvStore.getString(LAST_ZOOM)).thenReturn("13.0")
@ -443,7 +411,7 @@ class UploadMediaDetailFragmentUnitTest {
@Test
@Throws(Exception::class)
fun testRememberedZoomLevelOnNotNull() {
shadowOf(Looper.getMainLooper()).idle()
Shadows.shadowOf(Looper.getMainLooper()).idle()
`when`(uploadItem.gpsCoords).thenReturn(imageCoordinates)
`when`(imageCoordinates.decLatitude).thenReturn(8.0)
`when`(imageCoordinates.decLongitude).thenReturn(-8.0)
@ -456,4 +424,4 @@ class UploadMediaDetailFragmentUnitTest {
val shadowIntent: ShadowIntent = shadowOf(startedIntent)
Assert.assertEquals(shadowIntent.intentClass, LocationPickerActivity::class.java)
}
}
}