mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Add Login Activity Test (#4160)
This commit is contained in:
parent
c4bd23f7a1
commit
67a9bd56fb
1 changed files with 96 additions and 0 deletions
|
|
@ -0,0 +1,96 @@
|
|||
package fr.free.nrw.commons.login
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.content.Context
|
||||
import android.view.MenuItem
|
||||
import fr.free.nrw.commons.R
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.auth.LoginActivity
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.Robolectric
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.fakes.RoboMenuItem
|
||||
import java.lang.reflect.Field
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class LoginActivityUnitTests {
|
||||
|
||||
@Mock
|
||||
private lateinit var activity: LoginActivity
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
@Mock
|
||||
private lateinit var progressDialog: ProgressDialog
|
||||
|
||||
private lateinit var menuItem: MenuItem
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
activity = Robolectric.buildActivity(LoginActivity::class.java).create().get()
|
||||
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
|
||||
val fieldProgressDialog: Field =
|
||||
LoginActivity::class.java.getDeclaredField("progressDialog")
|
||||
fieldProgressDialog.isAccessible = true
|
||||
fieldProgressDialog.set(activity, progressDialog)
|
||||
|
||||
menuItem = RoboMenuItem(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkActivityNotNull() {
|
||||
Assert.assertNotNull(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowMessageAndCancelDialog() {
|
||||
activity.showMessageAndCancelDialog("")
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testStartMainActivity() {
|
||||
activity.startMainActivity()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowMessageAndCancelDialogRes() {
|
||||
activity.showMessageAndCancelDialog(R.color.secondaryDarkColor)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testAskUserForTwoFactorAuth() {
|
||||
activity.askUserForTwoFactorAuth()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testShowSuccessAndDismissDialog() {
|
||||
activity.showSuccessAndDismissDialog()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnOptionsItemSelected() {
|
||||
activity.onOptionsItemSelected(menuItem)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue