mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Convert auth package to kotlin (#5966)
* Convert SessionManager to kotlin along with other small fixes * Convert WikiAccountAuthenticator to kotlin * Migrate WikiAccountAuthenticatorService to kotlin * Converted AccountUtil to kotlin * Convert SignupActivity to kotlin * Convert LoginActivity to kotlin * Merge from main
This commit is contained in:
parent
238023056f
commit
0c969c365b
25 changed files with 752 additions and 964 deletions
|
|
@ -6,7 +6,6 @@ import android.content.Context
|
|||
import androidx.collection.LruCache
|
||||
import com.google.gson.Gson
|
||||
import com.nhaarman.mockitokotlin2.mock
|
||||
import fr.free.nrw.commons.auth.AccountUtil
|
||||
import fr.free.nrw.commons.data.DBOpenHelper
|
||||
import fr.free.nrw.commons.di.CommonsApplicationComponent
|
||||
import fr.free.nrw.commons.di.CommonsApplicationModule
|
||||
|
|
@ -41,7 +40,6 @@ class TestCommonsApplication : Application() {
|
|||
class MockCommonsApplicationModule(
|
||||
appContext: Context,
|
||||
) : CommonsApplicationModule(appContext) {
|
||||
val accountUtil: AccountUtil = mock()
|
||||
val defaultSharedPreferences: JsonKvStore = mock()
|
||||
val locationServiceManager: LocationServiceManager = mock()
|
||||
val mockDbOpenHelper: DBOpenHelper = mock()
|
||||
|
|
@ -58,8 +56,6 @@ class MockCommonsApplicationModule(
|
|||
|
||||
override fun provideModificationContentProviderClient(context: Context?): ContentProviderClient = modificationClient
|
||||
|
||||
override fun providesAccountUtil(context: Context): AccountUtil = accountUtil
|
||||
|
||||
override fun providesDefaultKvStore(
|
||||
context: Context,
|
||||
gson: Gson,
|
||||
|
|
|
|||
|
|
@ -15,25 +15,17 @@ import org.robolectric.annotation.Config
|
|||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class AccountUtilUnitTest {
|
||||
private lateinit var context: FakeContextWrapper
|
||||
private lateinit var accountUtil: AccountUtil
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
context = FakeContextWrapper(ApplicationProvider.getApplicationContext())
|
||||
accountUtil = AccountUtil()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkNotNull() {
|
||||
Assert.assertNotNull(accountUtil)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetUserName() {
|
||||
Assert.assertEquals(AccountUtil.getUserName(context), "test@example.com")
|
||||
Assert.assertEquals(getUserName(context), "test@example.com")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -41,13 +33,13 @@ class AccountUtilUnitTest {
|
|||
fun testGetUserNameWithException() {
|
||||
val context =
|
||||
FakeContextWrapperWithException(ApplicationProvider.getApplicationContext())
|
||||
Assert.assertEquals(AccountUtil.getUserName(context), null)
|
||||
Assert.assertEquals(getUserName(context), null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAccount() {
|
||||
Assert.assertEquals(AccountUtil.account(context)?.name, "test@example.com")
|
||||
Assert.assertEquals(account(context)?.name, "test@example.com")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -55,6 +47,6 @@ class AccountUtilUnitTest {
|
|||
fun testAccountWithException() {
|
||||
val context =
|
||||
FakeContextWrapperWithException(ApplicationProvider.getApplicationContext())
|
||||
Assert.assertEquals(AccountUtil.account(context), null)
|
||||
Assert.assertEquals(account(context), null)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,17 +218,6 @@ class LoginActivityUnitTests {
|
|||
method.invoke(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHideProgress() {
|
||||
val method: Method =
|
||||
LoginActivity::class.java.getDeclaredMethod(
|
||||
"hideProgress",
|
||||
)
|
||||
method.isAccessible = true
|
||||
method.invoke(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnResume() {
|
||||
|
|
|
|||
|
|
@ -3,18 +3,13 @@ package fr.free.nrw.commons.auth
|
|||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import java.lang.reflect.Field
|
||||
|
||||
class WikiAccountAuthenticatorServiceUnitTest {
|
||||
private lateinit var service: WikiAccountAuthenticatorService
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.openMocks(this)
|
||||
service = WikiAccountAuthenticatorService()
|
||||
service.onBind(null)
|
||||
}
|
||||
private val service = WikiAccountAuthenticatorService()
|
||||
|
||||
@Test
|
||||
fun checkNotNull() {
|
||||
|
|
@ -23,10 +18,9 @@ class WikiAccountAuthenticatorServiceUnitTest {
|
|||
|
||||
@Test
|
||||
fun testOnBindCaseNull() {
|
||||
val field: Field =
|
||||
WikiAccountAuthenticatorService::class.java.getDeclaredField("authenticator")
|
||||
val field: Field = WikiAccountAuthenticatorService::class.java.getDeclaredField("authenticator")
|
||||
field.isAccessible = true
|
||||
field.set(service, null)
|
||||
Assert.assertEquals(service.onBind(null), null)
|
||||
Assert.assertEquals(service.onBind(mock()), null)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,10 +86,7 @@ class WikiAccountAuthenticatorUnitTest {
|
|||
|
||||
@Test
|
||||
fun testGetAuthTokenLabelCaseNonNull() {
|
||||
Assert.assertEquals(
|
||||
authenticator.getAuthTokenLabel(BuildConfig.ACCOUNT_TYPE),
|
||||
AccountUtil.AUTH_TOKEN_TYPE,
|
||||
)
|
||||
Assert.assertEquals(authenticator.getAuthTokenLabel(BuildConfig.ACCOUNT_TYPE), AUTH_TOKEN_TYPE)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue