mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Migrated Bookmarks Package From Butterknife to ViewBinding (#5594)
* Butterknife to ViewBinding * code fix to pass all tests * code cleanup & binding added to tests
This commit is contained in:
parent
3e5424e18d
commit
161e2edc31
9 changed files with 130 additions and 139 deletions
|
|
@ -21,6 +21,8 @@ import fr.free.nrw.commons.TestCommonsApplication
|
|||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesFragment
|
||||
import fr.free.nrw.commons.contributions.MainActivity
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksBinding
|
||||
import fr.free.nrw.commons.databinding.FragmentFeaturedRootBinding
|
||||
import fr.free.nrw.commons.explore.ParentViewPager
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment
|
||||
import org.junit.Assert
|
||||
|
|
@ -81,6 +83,8 @@ class BookmarkListRootFragmentUnitTest {
|
|||
@Mock
|
||||
private lateinit var adapter: BookmarksPagerAdapter
|
||||
|
||||
private lateinit var binding: FragmentFeaturedRootBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
|
|
@ -95,14 +99,17 @@ class BookmarkListRootFragmentUnitTest {
|
|||
fragmentTransaction.commitNowAllowingStateLoss()
|
||||
|
||||
bookmarkFragment = BookmarkFragment()
|
||||
bookmarkFragment.binding = FragmentBookmarksBinding.inflate(LayoutInflater.from(activity))
|
||||
|
||||
binding = FragmentFeaturedRootBinding.inflate(LayoutInflater.from(activity))
|
||||
|
||||
Whitebox.setInternalState(fragment, "mChildFragmentManager", childFragmentManager)
|
||||
Whitebox.setInternalState(fragment, "mParentFragment", bookmarkFragment)
|
||||
Whitebox.setInternalState(fragment, "listFragment", listFragment)
|
||||
Whitebox.setInternalState(fragment, "mediaDetails", mediaDetails)
|
||||
Whitebox.setInternalState(fragment, "bookmarksPagerAdapter", bookmarksPagerAdapter)
|
||||
Whitebox.setInternalState(bookmarkFragment, "tabLayout", tabLayout)
|
||||
Whitebox.setInternalState(bookmarkFragment, "viewPager", viewPager)
|
||||
Whitebox.setInternalState(bookmarkFragment.binding, "tabLayout", tabLayout)
|
||||
Whitebox.setInternalState(bookmarkFragment.binding, "viewPagerBookmarks", viewPager)
|
||||
Whitebox.setInternalState(bookmarkFragment, "adapter", adapter)
|
||||
|
||||
whenever(childFragmentManager.beginTransaction()).thenReturn(childFragmentTransaction)
|
||||
|
|
@ -322,4 +329,4 @@ class BookmarkListRootFragmentUnitTest {
|
|||
Assert.assertEquals(fragment.backPressed(), false)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import fr.free.nrw.commons.R
|
|||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.category.CategoryItem
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksItemsBinding
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import fr.free.nrw.commons.upload.structure.depictions.DepictedItem
|
||||
import org.junit.Assert
|
||||
|
|
@ -25,6 +26,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
|
@ -45,8 +47,7 @@ class BookmarkItemsFragmentUnitTest {
|
|||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
|
||||
@Mock
|
||||
private lateinit var parentLayout: RelativeLayout
|
||||
private lateinit var binding: FragmentBookmarksItemsBinding
|
||||
|
||||
@Mock
|
||||
private lateinit var savedInstanceState: Bundle
|
||||
|
|
@ -89,17 +90,16 @@ class BookmarkItemsFragmentUnitTest {
|
|||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = layoutInflater
|
||||
.inflate(R.layout.fragment_bookmarks_items, null) as View
|
||||
binding = FragmentBookmarksItemsBinding.inflate(layoutInflater)
|
||||
|
||||
statusTextView = view.findViewById(R.id.status_message)
|
||||
progressBar = view.findViewById(R.id.loading_images_progress_bar)
|
||||
recyclerView = view.findViewById(R.id.list_view)
|
||||
|
||||
fragment.statusTextView = statusTextView
|
||||
fragment.progressBar = progressBar
|
||||
fragment.recyclerView = recyclerView
|
||||
fragment.parentLayout = parentLayout
|
||||
fragment.controller = controller
|
||||
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -132,4 +132,4 @@ class BookmarkItemsFragmentUnitTest {
|
|||
fun checkFragmentNotNull() {
|
||||
Assert.assertNotNull(fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import fr.free.nrw.commons.R
|
|||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.contributions.ContributionController
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksLocationsBinding
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||
import fr.free.nrw.commons.nearby.Place
|
||||
import fr.free.nrw.commons.nearby.fragments.CommonPlaceClickActions
|
||||
|
|
@ -52,9 +53,6 @@ class BookmarkLocationFragmentUnitTests {
|
|||
@Mock
|
||||
lateinit var store: JsonKvStore
|
||||
|
||||
@Mock
|
||||
private lateinit var parentLayout: RelativeLayout
|
||||
|
||||
@Mock
|
||||
private lateinit var savedInstanceState: Bundle
|
||||
|
||||
|
|
@ -70,6 +68,8 @@ class BookmarkLocationFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var adapter: PlaceAdapter
|
||||
|
||||
private lateinit var binding: FragmentBookmarksLocationsBinding
|
||||
|
||||
/**
|
||||
* Get Mock bookmark list.
|
||||
*/
|
||||
|
|
@ -109,20 +109,18 @@ class BookmarkLocationFragmentUnitTests {
|
|||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = layoutInflater
|
||||
.inflate(R.layout.fragment_bookmarks_locations, null) as View
|
||||
binding = FragmentBookmarksLocationsBinding.bind(view)
|
||||
|
||||
statusTextView = view.findViewById(R.id.statusMessage)
|
||||
progressBar = view.findViewById(R.id.loadingImagesProgressBar)
|
||||
recyclerView = view.findViewById(R.id.listView)
|
||||
commonPlaceClickActions = CommonPlaceClickActions(store,activity,contributionController)
|
||||
|
||||
fragment.statusTextView = statusTextView
|
||||
fragment.progressBar = progressBar
|
||||
fragment.recyclerView = recyclerView
|
||||
fragment.parentLayout = parentLayout
|
||||
fragment.bookmarkLocationDao = bookmarkLocationDao
|
||||
fragment.controller = controller
|
||||
fragment.commonPlaceClickActions = commonPlaceClickActions
|
||||
Whitebox.setInternalState(fragment, "adapter", adapter)
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -173,4 +171,4 @@ class BookmarkLocationFragmentUnitTests {
|
|||
fun testOnResume() {
|
||||
fragment.onResume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ import androidx.test.core.app.ApplicationProvider
|
|||
import com.nhaarman.mockitokotlin2.any
|
||||
import com.nhaarman.mockitokotlin2.times
|
||||
import com.nhaarman.mockitokotlin2.verify
|
||||
import com.nhaarman.mockitokotlin2.whenever
|
||||
import fr.free.nrw.commons.Media
|
||||
import fr.free.nrw.commons.OkHttpConnectionFactory
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.category.GridViewAdapter
|
||||
import fr.free.nrw.commons.databinding.FragmentBookmarksPicturesBinding
|
||||
import fr.free.nrw.commons.media.MediaClient
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import media
|
||||
|
|
@ -49,9 +51,9 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
|
||||
private lateinit var fragment: BookmarkPicturesFragment
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var binding: FragmentBookmarksPicturesBinding
|
||||
|
||||
private lateinit var view: View
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
lateinit var statusTextView: TextView
|
||||
|
|
@ -97,13 +99,7 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
fragmentTransaction.add(fragment, null)
|
||||
fragmentTransaction.commit()
|
||||
|
||||
view = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.fragment_bookmarks_pictures, null) as View
|
||||
|
||||
fragment.statusTextView = statusTextView
|
||||
fragment.progressBar = progressBar
|
||||
fragment.gridView = gridView
|
||||
fragment.parentLayout = parentLayout
|
||||
binding = FragmentBookmarksPicturesBinding.inflate(LayoutInflater.from(activity))
|
||||
|
||||
val bookmarkDao = BookmarkPicturesDao { client }
|
||||
|
||||
|
|
@ -116,6 +112,12 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
0,
|
||||
listOf(media())
|
||||
))
|
||||
Whitebox.setInternalState(fragment, "binding", binding)
|
||||
|
||||
Whitebox.setInternalState(binding, "statusMessage", statusTextView)
|
||||
Whitebox.setInternalState(binding, "loadingImagesProgressBar", progressBar)
|
||||
Whitebox.setInternalState(binding, "bookmarkedPicturesList", gridView)
|
||||
Whitebox.setInternalState(binding, "parentLayout", parentLayout)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -127,7 +129,7 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnViewCreated() {
|
||||
fragment.onViewCreated(view, savedInstanceState)
|
||||
fragment.onViewCreated(binding.root, savedInstanceState)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -216,4 +218,4 @@ class BookmarkPicturesFragmentUnitTests {
|
|||
method.isAccessible = true
|
||||
method.invoke(fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue