mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-30 22:34:02 +01:00
Add MediaDetailFragment Unit Tests (#4632)
* Add MediaDetailFragment Unit Tests * Add ZoomableActivity Unit Tests
This commit is contained in:
parent
fb634934b9
commit
07d170a79c
5 changed files with 538 additions and 20 deletions
|
|
@ -37,7 +37,7 @@ fun <T> createMockDataSourceFactory(itemList: List<T>): DataSource.Factory<Int,
|
|||
/**
|
||||
* Provides a mocked Room SQL query
|
||||
*/
|
||||
private fun mockQuery(): RoomSQLiteQuery? {
|
||||
private fun mockQuery(): RoomSQLiteQuery {
|
||||
val query = mock(RoomSQLiteQuery::class.java);
|
||||
whenever(query.sql).thenReturn("");
|
||||
return query;
|
||||
|
|
@ -46,7 +46,7 @@ private fun mockQuery(): RoomSQLiteQuery? {
|
|||
/**
|
||||
* Provides a mocked Room DB
|
||||
*/
|
||||
private fun mockDb(): RoomDatabase? {
|
||||
private fun mockDb(): RoomDatabase {
|
||||
val roomDatabase = mock(RoomDatabase::class.java);
|
||||
val invalidationTracker = mock(InvalidationTracker::class.java)
|
||||
whenever(roomDatabase.invalidationTracker).thenReturn(invalidationTracker);
|
||||
|
|
@ -57,8 +57,10 @@ private fun mockDb(): RoomDatabase? {
|
|||
* Class that defines the mocked data source
|
||||
*/
|
||||
class MockLimitDataSource<T>(private val itemList: List<T>) :
|
||||
LimitOffsetDataSource<T>(mockDb(), mockQuery(), false, null) {
|
||||
override fun convertRows(cursor: Cursor?): MutableList<T> = itemList.toMutableList()
|
||||
LimitOffsetDataSource<T>(mockDb(), mockQuery(), false, "") {
|
||||
override fun convertRows(cursor: Cursor): MutableList<T> {
|
||||
return itemList.toMutableList()
|
||||
}
|
||||
override fun countItems(): Int = itemList.count()
|
||||
override fun isInvalid(): Boolean = false
|
||||
override fun loadRange(params: LoadRangeParams, callback: LoadRangeCallback<T>) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue