mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 05:13:53 +01:00
Add AccountUtil Unit Tests (#4814)
This commit is contained in:
parent
dcf3aa8670
commit
fd0dbf4cfd
3 changed files with 120 additions and 0 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package fr.free.nrw.commons.auth
|
||||
|
||||
import fr.free.nrw.commons.FakeContextWrapper
|
||||
import fr.free.nrw.commons.FakeContextWrapperWithException
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@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(RuntimeEnvironment.application.applicationContext)
|
||||
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")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetUserNameWithException() {
|
||||
val context =
|
||||
FakeContextWrapperWithException(RuntimeEnvironment.application.applicationContext)
|
||||
Assert.assertEquals(AccountUtil.getUserName(context), null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAccount() {
|
||||
Assert.assertEquals(AccountUtil.account(context)?.name, "test@example.com")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAccountWithException() {
|
||||
val context =
|
||||
FakeContextWrapperWithException(RuntimeEnvironment.application.applicationContext)
|
||||
Assert.assertEquals(AccountUtil.account(context), null)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue