mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Added Unit Test for About Activity Class (#3978)
This commit is contained in:
parent
f36561f0c7
commit
0d5fa048a5
1 changed files with 110 additions and 0 deletions
|
|
@ -0,0 +1,110 @@
|
|||
package fr.free.nrw.commons
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
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.Shadows
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.fakes.RoboMenu
|
||||
import org.robolectric.fakes.RoboMenuItem
|
||||
import org.robolectric.shadows.ShadowActivity
|
||||
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class AboutActivityUnitTests {
|
||||
|
||||
private lateinit var activity:AboutActivity
|
||||
|
||||
@Mock
|
||||
private lateinit var context: Context
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
activity = Robolectric.buildActivity(AboutActivity::class.java).get()
|
||||
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkActivityNotNull() {
|
||||
Assert.assertNotNull(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchFacebook() {
|
||||
activity.launchFacebook(null)
|
||||
val shadowActivity: ShadowActivity = Shadows.shadowOf(activity)
|
||||
val startedIntent = shadowActivity.nextStartedActivity
|
||||
Assert.assertEquals(startedIntent.action, "android.intent.action.VIEW")
|
||||
Assert.assertEquals(startedIntent.`package`, "com.facebook.katana")
|
||||
Assert.assertEquals(startedIntent.`data`, Uri.parse("fb://page/1921335171459985"))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchGithub() {
|
||||
activity.launchGithub(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchWebsite() {
|
||||
activity.launchWebsite(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchRatings() {
|
||||
activity.launchRatings(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchCredits() {
|
||||
activity.launchCredits(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchPrivacyPolicy() {
|
||||
activity.launchPrivacyPolicy(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testLaunchFrequentlyAskedQuestions() {
|
||||
activity.launchFrequentlyAskedQuesions(null)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreateOptionsMenu() {
|
||||
val menu: Menu = RoboMenu(context)
|
||||
activity.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnOptionsItemSelected() {
|
||||
val menuItem: MenuItem = RoboMenuItem(R.menu.menu_about)
|
||||
activity.onOptionsItemSelected(menuItem)
|
||||
val shadowActivity = Shadows.shadowOf(activity)
|
||||
shadowActivity.clickMenuItem(R.id.share_app_icon)
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue