#3780 Create media using a combination of Entities & MwQueryResult (#3786)

* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchDepictionsRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadCategoryDepictionsRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - update BaseAdapter to be easier to use

* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchImagesRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace SearchCategoriesRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace NotificationRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace UploadDepictsRenderer

* #3468 Switch from RvRenderer to AdapterDelegates - replace PlaceRenderer

* #3756 Convert SearchDepictionsFragment to use Pagination - convert SearchDepictionsFragment

* #3756 Convert SearchDepictionsFragment to use Pagination - fix presenter unit tests now that view is not nullable - fix Category prefix imports

* #3756 Convert SearchDepictionsFragment to use Pagination - test DataSource related classes

* #3756 Convert SearchDepictionsFragment to use Pagination - reset rx scheduler - ignore failing test

* #3760 Convert SearchCategoriesFragment to use Pagination - extract functionality of pagination to base classes - add category pagination

* #3772 Convert SearchImagesFragment to use Pagination  - convert SearchImagesFragment - tidy up showing the empty view - make search fragments show snackbar with appropriate text

* #3772 Convert SearchImagesFragment to use Pagination  - allow viewpager to load more data

* #3760 remove test that got re-added by merge

* #3760 remove duplicate dependency

* #3772 fix compilation

* #3780 Create media using a combination of Entities & MwQueryResult - construct media with an entity - move fields from media down to contribution - move dynamic fields outside of media - remove unused constructors - remove all unnecessary fetching of captions/descriptions - bump database version

* #3808 Construct media objects that depict an item id correctly - use generator to construct media for DepictedImages

* #3780 Create media using a combination of Entities & MwQueryResult - update wikicode to align with expected behaviour

* #3780 Create media using a combination of Entities & MwQueryResult - replace old site of thumbnail title with most relevant caption
This commit is contained in:
Seán Mac Gillicuddy 2020-06-25 08:20:01 +01:00 committed by GitHub
parent bf4b7e2efc
commit 4b22583b60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 803 additions and 1532 deletions

View file

@ -1,108 +0,0 @@
package fr.free.nrw.commons.bookmarks.pictures;
import android.net.Uri;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.List;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.bookmarks.Bookmark;
import fr.free.nrw.commons.media.MediaClient;
import io.reactivex.Single;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
/**
* Tests for bookmark pictures controller
*/
public class BookmarkPicturesControllerTest {
@Mock
MediaClient mediaClient;
@Mock
BookmarkPicturesDao bookmarkDao;
@InjectMocks
BookmarkPicturesController bookmarkPicturesController;
/**
* Init mocks
*/
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
Media mockMedia = getMockMedia();
when(bookmarkDao.getAllBookmarks())
.thenReturn(getMockBookmarkList());
when(mediaClient.getMedia(anyString()))
.thenReturn(Single.just(mockMedia));
}
/**
* Get mock bookmark list
* @return
*/
private List<Bookmark> getMockBookmarkList() {
ArrayList<Bookmark> list = new ArrayList<>();
list.add(new Bookmark("File:Test1.jpg", "Maskaravivek", Uri.EMPTY));
list.add(new Bookmark("File:Test2.jpg", "Maskaravivek", Uri.EMPTY));
return list;
}
/**
* Test case where all bookmark pictures are fetched and media is found against it
*/
@Test
public void loadBookmarkedPictures() {
List<Media> bookmarkedPictures = bookmarkPicturesController.loadBookmarkedPictures().blockingGet();
assertEquals(2, bookmarkedPictures.size());
}
/**
* Test case where all bookmark pictures are fetched and only one media is found
*/
@Test
public void loadBookmarkedPicturesForNullMedia() {
when(mediaClient.getMedia("File:Test1.jpg"))
.thenReturn(Single.error(new NullPointerException("Error occurred")));
when(mediaClient.getMedia("File:Test2.jpg"))
.thenReturn(Single.just(getMockMedia()));
List<Media> bookmarkedPictures = bookmarkPicturesController.loadBookmarkedPictures().blockingGet();
assertEquals(1, bookmarkedPictures.size());
}
private Media getMockMedia() {
return new Media("File:Test.jpg");
}
/**
* Test case where current bookmarks don't match the bookmarks in DB
*/
@Test
public void needRefreshBookmarkedPictures() {
boolean needRefreshBookmarkedPictures = bookmarkPicturesController.needRefreshBookmarkedPictures();
assertTrue(needRefreshBookmarkedPictures);
}
/**
* Test case where the DB is up to date with the bookmarks loaded in the list
*/
@Test
public void doNotNeedRefreshBookmarkedPictures() {
List<Media> bookmarkedPictures = bookmarkPicturesController.loadBookmarkedPictures().blockingGet();
assertEquals(2, bookmarkedPictures.size());
boolean needRefreshBookmarkedPictures = bookmarkPicturesController.needRefreshBookmarkedPictures();
assertFalse(needRefreshBookmarkedPictures);
}
}

View file

@ -0,0 +1,110 @@
package fr.free.nrw.commons.bookmarks.pictures
import android.net.Uri
import com.nhaarman.mockitokotlin2.whenever
import fr.free.nrw.commons.Media
import fr.free.nrw.commons.bookmarks.Bookmark
import fr.free.nrw.commons.media.MediaClient
import io.reactivex.Single
import media
import org.junit.Assert
import org.junit.Before
import org.junit.Test
import org.mockito.ArgumentMatchers
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import java.util.*
/**
* Tests for bookmark pictures controller
*/
class BookmarkPicturesControllerTest {
@Mock
var mediaClient: MediaClient? = null
@Mock
var bookmarkDao: BookmarkPicturesDao? = null
@InjectMocks
var bookmarkPicturesController: BookmarkPicturesController? = null
/**
* Init mocks
*/
@Before
fun setup() {
MockitoAnnotations.initMocks(this)
val mockMedia = mockMedia
whenever(bookmarkDao!!.allBookmarks)
.thenReturn(mockBookmarkList)
whenever(
mediaClient!!.getMedia(
ArgumentMatchers.anyString()
)
)
.thenReturn(Single.just(mockMedia))
}
/**
* Get mock bookmark list
* @return
*/
private val mockBookmarkList: List<Bookmark>
private get() {
val list = ArrayList<Bookmark>()
list.add(Bookmark("File:Test1.jpg", "Maskaravivek", Uri.EMPTY))
list.add(Bookmark("File:Test2.jpg", "Maskaravivek", Uri.EMPTY))
return list
}
/**
* Test case where all bookmark pictures are fetched and media is found against it
*/
@Test
fun loadBookmarkedPictures() {
val bookmarkedPictures =
bookmarkPicturesController!!.loadBookmarkedPictures().blockingGet()
Assert.assertEquals(2, bookmarkedPictures.size.toLong())
}
/**
* Test case where all bookmark pictures are fetched and only one media is found
*/
@Test
fun loadBookmarkedPicturesForNullMedia() {
whenever(mediaClient!!.getMedia("File:Test1.jpg"))
.thenReturn(Single.error(NullPointerException("Error occurred")))
whenever(mediaClient!!.getMedia("File:Test2.jpg"))
.thenReturn(Single.just(mockMedia))
val bookmarkedPictures =
bookmarkPicturesController!!.loadBookmarkedPictures().blockingGet()
Assert.assertEquals(1, bookmarkedPictures.size.toLong())
}
private val mockMedia: Media
private get() = media(filename="File:Test.jpg")
/**
* Test case where current bookmarks don't match the bookmarks in DB
*/
@Test
fun needRefreshBookmarkedPictures() {
val needRefreshBookmarkedPictures =
bookmarkPicturesController!!.needRefreshBookmarkedPictures()
Assert.assertTrue(needRefreshBookmarkedPictures)
}
/**
* Test case where the DB is up to date with the bookmarks loaded in the list
*/
@Test
fun doNotNeedRefreshBookmarkedPictures() {
val bookmarkedPictures =
bookmarkPicturesController!!.loadBookmarkedPictures().blockingGet()
Assert.assertEquals(2, bookmarkedPictures.size.toLong())
val needRefreshBookmarkedPictures =
bookmarkPicturesController!!.needRefreshBookmarkedPictures()
Assert.assertFalse(needRefreshBookmarkedPictures)
}
}