mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Added unit-tests for CacheController (#3275)
This commit is contained in:
parent
6e485d687c
commit
bb0a21929e
3 changed files with 62 additions and 2 deletions
48
app/src/test/kotlin/fr/free/nrw/commons/cache/CacheControllerTest.kt
vendored
Normal file
48
app/src/test/kotlin/fr/free/nrw/commons/cache/CacheControllerTest.kt
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package fr.free.nrw.commons.cache
|
||||
|
||||
import com.github.varunpant.quadtree.Point
|
||||
import com.github.varunpant.quadtree.QuadTree
|
||||
import com.nhaarman.mockito_kotlin.verify
|
||||
import fr.free.nrw.commons.caching.CacheController
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class CacheControllerTest {
|
||||
/**
|
||||
* initial setup, test environment
|
||||
*/
|
||||
private lateinit var cacheController: CacheController
|
||||
|
||||
@Mock
|
||||
private lateinit var quadTree: QuadTree<List<String>>
|
||||
|
||||
private lateinit var points: Array<Point<List<String>>>
|
||||
|
||||
var value = ArrayList<String>()
|
||||
|
||||
|
||||
@Before
|
||||
@Throws(Exception::class)
|
||||
fun setUp() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
val point = Point<List<String>>(1.0, 1.0, value)
|
||||
points = arrayOf(point)
|
||||
value.add("1")
|
||||
cacheController = CacheController(quadTree)
|
||||
Mockito.`when`(quadTree.searchWithin(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble())).thenReturn(points)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test find category
|
||||
*/
|
||||
@Test
|
||||
fun testFindCategory() {
|
||||
val findCategory = cacheController.findCategory()
|
||||
verify(quadTree).searchWithin(ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble(), ArgumentMatchers.anyDouble())
|
||||
assert(findCategory.size == 1)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue