mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-30 22:34:02 +01:00 
			
		
		
		
	Migrated OkHttpJsonApiClient#getMedia and getPictureOfTheDay to MediaClient (#3056)
* With media client APIs migrated to retrofit (#2998) * With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests * Categories related client API's migrated to retrofit (#3053) * Commit 1 * searchCategories migrated to retrofit * SearchCategoriesFragment migrated to new API * Removed unused code * Created tests * implemented searching by prefix fixed SearchCategoryFragment behaviour where the same categories would be added to the list instead of new ones. * added tests * Migrated searchTitles to searchCategories, function behaviour seems identical * With media client APIs migrated to retrofit (#2998) * With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests * Categories related client API's migrated to retrofit (#3053) * Commit 1 * searchCategories migrated to retrofit * SearchCategoriesFragment migrated to new API * Removed unused code * Created tests * implemented searching by prefix fixed SearchCategoryFragment behaviour where the same categories would be added to the list instead of new ones. * added tests * Migrated searchTitles to searchCategories, function behaviour seems identical * OkHttpJsonApi#getMediaList migrated to retrofit (#3054) * Migrated OkHttpJsonApi#getMediaList partially to MediaClient#getCategoryImages * Migrated rest of OkHttpJsonApi#getMediaList functionality to MediaClient#getCategoryImages * Removed unused code and tests * Fixed small bug * Added tests * Removed unused CategoryImageController * getSubCategoryList and getParentCategoryList migrated to retrofit (#3055) * Migrated getSubCategoryList to retrofit * Migrated getParentCategoryList to retrofit * Removed obsolete functions * Added tests * Fixed small bugs * Migrated OkHttpJsonApiClient#getMedia and getPictureOfTheDay to MediaClient * Removed obsolete functions and added tests * Fixed merge errors * With media client APIs migrated to retrofit (#2998) * With media client APIs migrated to retrofit * Add test cases and java docs * Fix test * Fix build * Fix build and other minor issues * Fix tests * Categories related client API's migrated to retrofit (#3053) * Commit 1 * searchCategories migrated to retrofit * SearchCategoriesFragment migrated to new API * Removed unused code * Created tests * implemented searching by prefix fixed SearchCategoryFragment behaviour where the same categories would be added to the list instead of new ones. * added tests * Migrated searchTitles to searchCategories, function behaviour seems identical * OkHttpJsonApi#getMediaList migrated to retrofit (#3054) * Migrated OkHttpJsonApi#getMediaList partially to MediaClient#getCategoryImages * Migrated rest of OkHttpJsonApi#getMediaList functionality to MediaClient#getCategoryImages * Removed unused code and tests * Fixed small bug * Added tests * Removed unused CategoryImageController * getSubCategoryList and getParentCategoryList migrated to retrofit (#3055) * Migrated getSubCategoryList to retrofit * Migrated getParentCategoryList to retrofit * Removed obsolete functions * Added tests * Fixed small bugs * Consume login client from data client library (#2894) Fix actions for review client Use data client library for notifications With delete helper migrated to data client With wikidata edits With notifications and modifications migrated to data client With upload migrated to retrofit Delete unused code Reuse thank interface from the library
This commit is contained in:
		
							parent
							
								
									d24ca9d4fe
								
							
						
					
					
						commit
						8b36ee52d1
					
				
					 15 changed files with 181 additions and 159 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| package fr.free.nrw.commons.media | ||||
| 
 | ||||
| import fr.free.nrw.commons.Media | ||||
| import fr.free.nrw.commons.utils.CommonsDateUtil | ||||
| import io.reactivex.Observable | ||||
| import junit.framework.Assert.* | ||||
| import org.junit.Before | ||||
|  | @ -102,6 +103,68 @@ class MediaClientTest { | |||
|         assertFalse(checkFileExistsUsingSha) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun getMedia() { | ||||
|         val imageInfo = ImageInfo() | ||||
| 
 | ||||
|         val mwQueryPage = mock(MwQueryPage::class.java) | ||||
|         `when`(mwQueryPage.title()).thenReturn("Test") | ||||
|         `when`(mwQueryPage.imageInfo()).thenReturn(imageInfo) | ||||
| 
 | ||||
|         val mwQueryResult = mock(MwQueryResult::class.java) | ||||
|         `when`(mwQueryResult.firstPage()).thenReturn(mwQueryPage) | ||||
|         val mockResponse = mock(MwQueryResponse::class.java) | ||||
|         `when`(mockResponse.query()).thenReturn(mwQueryResult) | ||||
| 
 | ||||
|         `when`(mediaInterface!!.getMedia(ArgumentMatchers.anyString())) | ||||
|                 .thenReturn(Observable.just(mockResponse)) | ||||
| 
 | ||||
|         assertEquals("Test", mediaClient!!.getMedia("abcde").blockingGet().filename) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun getMediaNull() { | ||||
|         val imageInfo = ImageInfo() | ||||
| 
 | ||||
|         val mwQueryPage = mock(MwQueryPage::class.java) | ||||
|         `when`(mwQueryPage.title()).thenReturn("Test") | ||||
|         `when`(mwQueryPage.imageInfo()).thenReturn(imageInfo) | ||||
| 
 | ||||
|         val mwQueryResult = mock(MwQueryResult::class.java) | ||||
|         `when`(mwQueryResult.firstPage()).thenReturn(null) | ||||
|         val mockResponse = mock(MwQueryResponse::class.java) | ||||
|         `when`(mockResponse.query()).thenReturn(mwQueryResult) | ||||
| 
 | ||||
|         `when`(mediaInterface!!.getMedia(ArgumentMatchers.anyString())) | ||||
|                 .thenReturn(Observable.just(mockResponse)) | ||||
| 
 | ||||
|         assertEquals(Media.EMPTY, mediaClient!!.getMedia("abcde").blockingGet()) | ||||
|     } | ||||
|     @Captor | ||||
|     private val filenameCaptor: ArgumentCaptor<String>? = null | ||||
| 
 | ||||
|     @Test | ||||
|     fun getPictureOfTheDay() { | ||||
|         val template = "Template:Potd/" + CommonsDateUtil.getIso8601DateFormatShort().format(Date()) | ||||
| 
 | ||||
|         val imageInfo = ImageInfo() | ||||
| 
 | ||||
|         val mwQueryPage = mock(MwQueryPage::class.java) | ||||
|         `when`(mwQueryPage.title()).thenReturn("Test") | ||||
|         `when`(mwQueryPage.imageInfo()).thenReturn(imageInfo) | ||||
| 
 | ||||
|         val mwQueryResult = mock(MwQueryResult::class.java) | ||||
|         `when`(mwQueryResult.firstPage()).thenReturn(mwQueryPage) | ||||
|         val mockResponse = mock(MwQueryResponse::class.java) | ||||
|         `when`(mockResponse.query()).thenReturn(mwQueryResult) | ||||
| 
 | ||||
|         `when`(mediaInterface!!.getMediaWithGenerator(filenameCaptor!!.capture())) | ||||
|                 .thenReturn(Observable.just(mockResponse)) | ||||
| 
 | ||||
|         assertEquals("Test", mediaClient!!.getPictureOfTheDay().blockingGet().filename) | ||||
|         assertEquals(template, filenameCaptor.value); | ||||
|     } | ||||
|    | ||||
|     @Captor | ||||
|     private val continuationCaptor: ArgumentCaptor<Map<String, String>>? = null | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Ilgaz Er
						Ilgaz Er