Add bookmark location controller test (#3947)

This commit is contained in:
neslihanturan 2020-10-02 05:21:33 +03:00 committed by GitHub
parent 257e8c57dd
commit 44fb1534bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,50 @@
package fr.free.nrw.commons.bookmarks.locations
import android.net.Uri
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.bookmarks.Bookmark
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao
import fr.free.nrw.commons.nearby.Place
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import java.util.ArrayList
class BookmarkLocationControllerTest {
@Mock
var bookmarkDao: BookmarkLocationsDao? = null
@InjectMocks
lateinit var bookmarkLocationsController: BookmarkLocationsController
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
whenever(bookmarkDao!!.allBookmarksLocations)
.thenReturn(mockBookmarkList)
}
/**
* Get mock bookmark list
* @return
*/
private val mockBookmarkList: List<Place>
private get() {
val list = ArrayList<Place>()
list.add(Place("a place",null,"a description",null,"a cat",null,null,null))
list.add(Place("another place",null,"another description",null,"another cat",null,null,null))
return list
}
/**
* Test case where all bookmark locations are fetched and media is found against it
*/
@Test
fun loadBookmarkedLocations() {
val bookmarkedLocations =
bookmarkLocationsController!!.loadFavoritesLocations()
Assert.assertEquals(2, bookmarkedLocations.size.toLong())
}
}