mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add Category Details Activity Unit Tests (#4169)
This commit is contained in:
parent
a62c2f5cf0
commit
cd3ba67cfb
1 changed files with 114 additions and 0 deletions
|
|
@ -0,0 +1,114 @@
|
|||
package fr.free.nrw.commons.category
|
||||
|
||||
import android.content.Context
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import fr.free.nrw.commons.TestAppAdapter
|
||||
import fr.free.nrw.commons.TestCommonsApplication
|
||||
import fr.free.nrw.commons.explore.categories.media.CategoriesMediaFragment
|
||||
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.RoboMenu
|
||||
import org.robolectric.fakes.RoboMenuItem
|
||||
import org.wikipedia.AppAdapter
|
||||
import java.lang.reflect.Field
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
class CategoryDetailsActivityUnitTests {
|
||||
|
||||
private lateinit var activity: CategoryDetailsActivity
|
||||
|
||||
private lateinit var context: Context
|
||||
|
||||
private lateinit var menuItem: MenuItem
|
||||
|
||||
private lateinit var menu: Menu
|
||||
|
||||
@Mock
|
||||
private lateinit var categoriesMediaFragment: CategoriesMediaFragment
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
||||
MockitoAnnotations.initMocks(this)
|
||||
|
||||
AppAdapter.set(TestAppAdapter())
|
||||
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
|
||||
activity = Robolectric.buildActivity(CategoryDetailsActivity::class.java).create().get()
|
||||
|
||||
val fieldCategoriesMediaFragment: Field =
|
||||
CategoryDetailsActivity::class.java.getDeclaredField("categoriesMediaFragment")
|
||||
fieldCategoriesMediaFragment.isAccessible = true
|
||||
fieldCategoriesMediaFragment.set(activity, categoriesMediaFragment)
|
||||
|
||||
menuItem = RoboMenuItem(null)
|
||||
|
||||
menu = RoboMenu(context)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkActivityNotNull() {
|
||||
Assert.assertNotNull(activity)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnMediaClicked() {
|
||||
activity.onMediaClicked(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetMediaAtPosition() {
|
||||
activity.getMediaAtPosition(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetTotalMediaCount() {
|
||||
activity.totalMediaCount
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetContributionStateAt() {
|
||||
activity.getContributionStateAt(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnCreateOptionsMenu() {
|
||||
activity.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnOptionsItemSelected() {
|
||||
activity.onOptionsItemSelected(menuItem)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnBackPressed() {
|
||||
activity.onBackPressed()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testViewPagerNotifyDataSetChanged() {
|
||||
activity.viewPagerNotifyDataSetChanged()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue