mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Migrated Profile Package from Butterknife to View Binding (#5591)
* Butterknife to ViewBinding * code fix to pass all tests * code cleanup and tests migrated to binding * fix LoD
This commit is contained in:
parent
dbe739e755
commit
6ed5deac65
7 changed files with 78 additions and 100 deletions
|
|
@ -17,6 +17,7 @@ import fr.free.nrw.commons.location.LocationServiceManager
|
|||
class TestCommonsApplication : Application() {
|
||||
private var mockApplicationComponent: CommonsApplicationComponent? = null
|
||||
|
||||
|
||||
override fun onCreate() {
|
||||
if (mockApplicationComponent == null) {
|
||||
mockApplicationComponent = DaggerCommonsApplicationComponent.builder()
|
||||
|
|
@ -64,4 +65,4 @@ class MockCommonsApplicationModule(appContext: Context) : CommonsApplicationModu
|
|||
override fun provideDBOpenHelper(context: Context): DBOpenHelper = mockDbOpenHelper
|
||||
|
||||
override fun provideLruCache(): LruCache<String, String> = lruCache
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import fr.free.nrw.commons.R
|
|||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.createTestClient
|
||||
import fr.free.nrw.commons.auth.SessionManager
|
||||
import fr.free.nrw.commons.databinding.FragmentLeaderboardBinding
|
||||
import fr.free.nrw.commons.profile.ProfileActivity
|
||||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardFragment
|
||||
import fr.free.nrw.commons.profile.leaderboard.LeaderboardListAdapter
|
||||
|
|
@ -47,21 +48,12 @@ class LeaderboardFragmentUnitTests {
|
|||
private lateinit var fragment: LeaderboardFragment
|
||||
private lateinit var fragmentManager: FragmentManager
|
||||
private lateinit var context: Context
|
||||
private lateinit var view: View
|
||||
private lateinit var layoutInflater: LayoutInflater
|
||||
|
||||
@Mock
|
||||
private lateinit var progressBar: ProgressBar
|
||||
|
||||
@Mock
|
||||
private lateinit var spinner: Spinner
|
||||
|
||||
@Mock
|
||||
private lateinit var viewModel: LeaderboardListViewModel
|
||||
|
||||
@Mock
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
|
||||
@Mock
|
||||
private lateinit var adapter: LeaderboardListAdapter
|
||||
|
||||
|
|
@ -71,12 +63,11 @@ class LeaderboardFragmentUnitTests {
|
|||
@Mock
|
||||
private lateinit var account: Account
|
||||
|
||||
@Mock
|
||||
private lateinit var button: Button
|
||||
|
||||
@Mock
|
||||
private lateinit var parentView: ViewGroup
|
||||
|
||||
private lateinit var binding: FragmentLeaderboardBinding
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
|
@ -92,15 +83,9 @@ class LeaderboardFragmentUnitTests {
|
|||
fragmentTransaction.commitNowAllowingStateLoss()
|
||||
|
||||
layoutInflater = LayoutInflater.from(activity)
|
||||
view = LayoutInflater.from(activity)
|
||||
.inflate(R.layout.fragment_leaderboard, null) as View
|
||||
binding = FragmentLeaderboardBinding.inflate(layoutInflater)
|
||||
|
||||
Whitebox.setInternalState(fragment, "progressBar", progressBar)
|
||||
Whitebox.setInternalState(fragment, "categorySpinner", spinner)
|
||||
Whitebox.setInternalState(fragment, "durationSpinner", spinner)
|
||||
Whitebox.setInternalState(fragment, "viewModel", viewModel)
|
||||
Whitebox.setInternalState(fragment, "scrollButton", button)
|
||||
Whitebox.setInternalState(fragment, "leaderboardListRecyclerView", recyclerView)
|
||||
Whitebox.setInternalState(fragment, "mView", parentView)
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +125,6 @@ class LeaderboardFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testScrollToUserRankCaseNonZeroTrue() {
|
||||
Whitebox.setInternalState(fragment, "userRank", 1)
|
||||
`when`(recyclerView.adapter).thenReturn(adapter)
|
||||
`when`(adapter.itemCount).thenReturn(3)
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank"
|
||||
|
|
@ -153,7 +137,6 @@ class LeaderboardFragmentUnitTests {
|
|||
@Throws(Exception::class)
|
||||
fun testScrollToUserRankCaseNonZeroFalse() {
|
||||
Whitebox.setInternalState(fragment, "userRank", 1)
|
||||
`when`(recyclerView.adapter).thenReturn(adapter)
|
||||
`when`(adapter.itemCount).thenReturn(1)
|
||||
val method: Method = LeaderboardFragment::class.java.getDeclaredMethod(
|
||||
"scrollToUserRank"
|
||||
|
|
@ -245,4 +228,4 @@ class LeaderboardFragmentUnitTests {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ class ProfileActivityTest {
|
|||
}
|
||||
@Test
|
||||
fun testToolbarNotNull() {
|
||||
val toolbar = activity.findViewById<Toolbar>(R.id.toolbar)
|
||||
val toolbar = activity.binding.toolbarBinding.toolbar
|
||||
Assert.assertNotNull(toolbar)
|
||||
}
|
||||
|
||||
|
|
@ -120,4 +120,4 @@ class ProfileActivityTest {
|
|||
Assert.assertEquals(1, menu.size())
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue