mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add some more Nearby Unit Tests (#4633)
This commit is contained in:
parent
07d170a79c
commit
121119a358
2 changed files with 197 additions and 0 deletions
|
|
@ -0,0 +1,92 @@
|
|||
package fr.free.nrw.commons.nearby
|
||||
|
||||
import android.os.Parcel
|
||||
import com.mapbox.mapboxsdk.annotations.Icon
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.powermock.reflect.Whitebox
|
||||
|
||||
class NearbyBaseMarkerUnitTests {
|
||||
|
||||
private lateinit var marker: NearbyBaseMarker
|
||||
|
||||
@Mock
|
||||
private lateinit var place: Place
|
||||
|
||||
@Mock
|
||||
private lateinit var parcel: Parcel
|
||||
|
||||
@Mock
|
||||
private lateinit var icon: Icon
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
marker = NearbyBaseMarker()
|
||||
Whitebox.setInternalState(marker, "icon", icon)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkNotNull() {
|
||||
Assert.assertNotNull(marker)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testPlace() {
|
||||
marker.place(place)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetThis() {
|
||||
marker.getThis()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetMarker() {
|
||||
marker.marker
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetPlace() {
|
||||
marker.place
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testDescribeContents() {
|
||||
marker.describeContents()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testWriteToParcel() {
|
||||
marker.writeToParcel(parcel, 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testEquals() {
|
||||
marker.equals(this)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testEqualsCaseNull() {
|
||||
Assert.assertFalse(marker.equals(this))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testHashCode() {
|
||||
marker.hashCode()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
package fr.free.nrw.commons.nearby
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
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.Mock
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import org.robolectric.annotation.LooperMode
|
||||
import java.util.*
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [21], application = TestCommonsApplication::class)
|
||||
@LooperMode(LooperMode.Mode.PAUSED)
|
||||
class NearbyFilterSearchRecyclerViewAdapterUnitTests {
|
||||
|
||||
private lateinit var context: Context
|
||||
private lateinit var adapter: NearbyFilterSearchRecyclerViewAdapter
|
||||
|
||||
@Mock
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
|
||||
@Mock
|
||||
private lateinit var callback: NearbyFilterSearchRecyclerViewAdapter.Callback
|
||||
|
||||
@Mock
|
||||
private lateinit var viewHolder: NearbyFilterSearchRecyclerViewAdapter.RecyclerViewHolder
|
||||
|
||||
@Mock
|
||||
private lateinit var imageView: ImageView
|
||||
|
||||
@Mock
|
||||
private lateinit var textView: TextView
|
||||
|
||||
@Mock
|
||||
private lateinit var linearLayout: LinearLayout
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
context = RuntimeEnvironment.application.applicationContext
|
||||
adapter = NearbyFilterSearchRecyclerViewAdapter(context, ArrayList<Label>(Label.valuesAsList()), recyclerView)
|
||||
viewHolder.placeTypeIcon = imageView
|
||||
viewHolder.placeTypeLabel = textView
|
||||
viewHolder.placeTypeLayout = linearLayout
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun checkAdapterNotNull() {
|
||||
Assert.assertNotNull(adapter)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetCallback() {
|
||||
adapter.setCallback(callback)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testOnBindViewHolder() {
|
||||
adapter.onBindViewHolder(viewHolder, 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetItemId() {
|
||||
adapter.getItemId(0)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetItemCount() {
|
||||
Assert.assertEquals(adapter.itemCount, 26)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetFilter() {
|
||||
adapter.filter
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetRecyclerViewAdapterItemsGreyedOut() {
|
||||
adapter.setRecyclerViewAdapterItemsGreyedOut()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testSetRecyclerViewAdapterAllSelected() {
|
||||
adapter.setRecyclerViewAdapterAllSelected()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue