From abef27a7afb2d7e172853608f6f7487819eda1f9 Mon Sep 17 00:00:00 2001 From: Akshay Komar Date: Sun, 12 Jan 2025 00:26:53 +0530 Subject: [PATCH] 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(...)) to reduce verbosity and potential casting errors. >Verified the functionality of prepareViewsForSheetPosition remains unchanged, ensuring no regression in test behavior. --- .../nrw/commons/nearby/NearbyParentFragmentUnitTest.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentUnitTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentUnitTest.kt index 7fb3ba8bd..65c4da282 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentUnitTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentUnitTest.kt @@ -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(R.id.empty_view)).thenReturn(view) + whenever(view.findViewById(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(R.id.empty_view)).thenReturn(view) + whenever(view.findViewById(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)