diff --git a/app/build.gradle b/app/build.gradle index 355748b73..8b8ec607e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -92,6 +92,7 @@ dependencies { testImplementation "androidx.arch.core:core-testing:2.1.0" testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.1" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.1" + testImplementation 'com.facebook.soloader:soloader:0.9.0' // Mockito and PowerMock androidTestCompile ('org.powermock:powermock-mockito-release-full:1.6.0') { diff --git a/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewActivityTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewActivityTest.kt new file mode 100644 index 000000000..b5d943d89 --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewActivityTest.kt @@ -0,0 +1,104 @@ +package fr.free.nrw.commons.review + +import android.content.Context +import android.view.Menu +import android.view.MenuItem +import com.facebook.drawee.backends.pipeline.Fresco +import com.facebook.soloader.SoLoader +import fr.free.nrw.commons.TestAppAdapter +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.mockito.MockitoAnnotations +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config +import org.robolectric.fakes.RoboMenu +import org.robolectric.fakes.RoboMenuItem +import org.wikipedia.AppAdapter + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [21], application = TestCommonsApplication::class) +class ReviewActivityTest { + + private lateinit var activity: ReviewActivity + + private lateinit var menuItem: MenuItem + + private lateinit var menu: Menu + + private lateinit var context: Context + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + + context = RuntimeEnvironment.application.applicationContext + + AppAdapter.set(TestAppAdapter()) + + SoLoader.setInTestMode() + + Fresco.initialize(context) + + activity = Robolectric.buildActivity(ReviewActivity::class.java).create().get() + + menuItem = RoboMenuItem(null) + + menu = RoboMenu(context) + + + } + + @Test + @Throws(Exception::class) + fun checkActivityNotNull() { + Assert.assertNotNull(activity) + } + + @Test + @Throws(Exception::class) + fun testOnSupportNavigateUp() { + activity.onSupportNavigateUp() + } + + @Test + @Throws(Exception::class) + fun testSwipeToNext() { + activity.swipeToNext() + } + + @Test + @Throws(Exception::class) + fun testOnDestroy() { + activity.onDestroy() + } + + @Test + @Throws(Exception::class) + fun testShowSkipImageInfo() { + activity.showSkipImageInfo() + } + + @Test + @Throws(Exception::class) + fun testShowReviewImageInfo() { + activity.showReviewImageInfo() + } + + @Test + @Throws(Exception::class) + fun testOnCreateOptionsMenu() { + activity.onCreateOptionsMenu(menu) + } + + @Test + @Throws(Exception::class) + fun testOnOptionsItemSelected() { + activity.onOptionsItemSelected(menuItem) + } + +} \ No newline at end of file