Refactor Unit Test: Replace Unsafe Casting with Type-Safe Mocking for findViewById

>PR refactors the unit test for NearbyParentFragment by replacing unsafe casting in the findViewById mocking statements with type-safe

>Ensured all findViewById mocks now use a consistent, type-safe format (findViewById<View>(...)) to reduce verbosity and potential casting errors.

>Verified the functionality of prepareViewsForSheetPosition remains unchanged, ensuring no regression in test behavior.
This commit is contained in:
Akshay Komar 2025-01-12 00:26:53 +05:30
parent 83bef3a6b3
commit abef27a7af

View file

@ -333,8 +333,8 @@ class NearbyParentFragmentUnitTest {
fun testPrepareViewsForSheetPositionCaseCollapsed() {
Whitebox.setInternalState(fragment, "isFABsExpanded", true)
Whitebox.setInternalState(fragment, "mView", view)
whenever(view.findViewById(R.id.empty_view) as View?).thenReturn(view)
whenever(view.findViewById(R.id.empty_view1) as View?).thenReturn(view)
whenever(view.findViewById<View>(R.id.empty_view)).thenReturn(view)
whenever(view.findViewById<View>(R.id.empty_view1)).thenReturn(view)
whenever(view.id).thenReturn(0)
fragment.prepareViewsForSheetPosition(BottomSheetBehavior.STATE_COLLAPSED)
verify(fab).isShown
@ -345,8 +345,8 @@ class NearbyParentFragmentUnitTest {
fun testPrepareViewsForSheetPositionCaseHidden() {
Whitebox.setInternalState(fragment, "isFABsExpanded", true)
Whitebox.setInternalState(fragment, "mView", view)
whenever(view.findViewById(R.id.empty_view) as View?).thenReturn(view)
whenever(view.findViewById(R.id.empty_view1) as View?).thenReturn(view)
whenever(view.findViewById<View>(R.id.empty_view)).thenReturn(view)
whenever(view.findViewById<View>(R.id.empty_view1)).thenReturn(view)
whenever(view.id).thenReturn(0)
whenever(fab.layoutParams).thenReturn(mock(CoordinatorLayout.LayoutParams::class.java))
fragment.prepareViewsForSheetPosition(BottomSheetBehavior.STATE_HIDDEN)