From 44fb1534bb245401e32ca730c747bc9595a05d82 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Fri, 2 Oct 2020 05:21:33 +0300 Subject: [PATCH] Add bookmark location controller test (#3947) --- .../BookmarkLocationControllerTest.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 app/src/test/kotlin/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationControllerTest.kt diff --git a/app/src/test/kotlin/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationControllerTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationControllerTest.kt new file mode 100644 index 000000000..d459f3e94 --- /dev/null +++ b/app/src/test/kotlin/fr/free/nrw/commons/bookmarks/locations/BookmarkLocationControllerTest.kt @@ -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 + private get() { + val list = ArrayList() + 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()) + } +} \ No newline at end of file