From 0d5fa048a57168213f885d03fead2f64ad8b15aa Mon Sep 17 00:00:00 2001 From: Madhur Gupta <30932899+madhurgupta10@users.noreply.github.com> Date: Sat, 24 Oct 2020 11:02:23 +0530 Subject: [PATCH] Added Unit Test for About Activity Class (#3978) --- .../nrw/commons/AboutActivityUnitTests.kt | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 app/src/test/kotlin/fr/free/nrw/commons/AboutActivityUnitTests.kt diff --git a/app/src/test/kotlin/fr/free/nrw/commons/AboutActivityUnitTests.kt b/app/src/test/kotlin/fr/free/nrw/commons/AboutActivityUnitTests.kt new file mode 100644 index 000000000..6f77ebc26 --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/AboutActivityUnitTests.kt @@ -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) + } + +} \ No newline at end of file