mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	#3847 Convert Media and Contribution to Kotlin Data Classes - convert to data classes - compose a contribution with a media (#3848)
Co-authored-by: Vivek Maskara <maskaravivek@gmail.com>
This commit is contained in:
		
							parent
							
								
									3361155fad
								
							
						
					
					
						commit
						cc2f14dab8
					
				
					 34 changed files with 334 additions and 741 deletions
				
			
		|  | @ -4,12 +4,12 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule | |||
| import com.nhaarman.mockitokotlin2.verify | ||||
| import com.nhaarman.mockitokotlin2.verifyZeroInteractions | ||||
| import com.nhaarman.mockitokotlin2.whenever | ||||
| import fr.free.nrw.commons.Media | ||||
| import fr.free.nrw.commons.auth.SessionManager | ||||
| import fr.free.nrw.commons.media.MediaClient | ||||
| import io.reactivex.Scheduler | ||||
| import io.reactivex.Single | ||||
| import io.reactivex.schedulers.Schedulers | ||||
| import media | ||||
| import org.junit.Before | ||||
| import org.junit.Rule | ||||
| import org.junit.Test | ||||
|  | @ -57,9 +57,8 @@ class ContributionBoundaryCallbackTest { | |||
|         whenever(repository.save(anyList<Contribution>())) | ||||
|             .thenReturn(Single.just(listOf(1L, 2L))) | ||||
|         whenever(sessionManager.userName).thenReturn("Test") | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())).thenReturn( | ||||
|             Single.just(listOf(mock(Media::class.java))) | ||||
|         ) | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())) | ||||
|             .thenReturn(Single.just(listOf(media()))) | ||||
|         contributionBoundaryCallback.onZeroItemsLoaded() | ||||
|         verify(repository).save(anyList<Contribution>()); | ||||
|         verify(mediaClient).getMediaListForUser(anyString()); | ||||
|  | @ -70,9 +69,8 @@ class ContributionBoundaryCallbackTest { | |||
|         whenever(repository.save(anyList<Contribution>())) | ||||
|             .thenReturn(Single.just(listOf(1L, 2L))) | ||||
|         whenever(sessionManager.userName).thenReturn("Test") | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())).thenReturn( | ||||
|             Single.just(listOf(mock(Media::class.java))) | ||||
|         ) | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())) | ||||
|             .thenReturn(Single.just(listOf(media()))) | ||||
|         contributionBoundaryCallback.onItemAtEndLoaded(mock(Contribution::class.java)) | ||||
|         verify(repository).save(anyList()); | ||||
|         verify(mediaClient).getMediaListForUser(anyString()); | ||||
|  | @ -83,9 +81,8 @@ class ContributionBoundaryCallbackTest { | |||
|         whenever(repository.save(anyList<Contribution>())) | ||||
|             .thenReturn(Single.just(listOf(1L, 2L))) | ||||
|         whenever(sessionManager.userName).thenReturn("Test") | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())).thenReturn( | ||||
|             Single.just(listOf(mock(Media::class.java))) | ||||
|         ) | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())) | ||||
|             .thenReturn(Single.just(listOf(media()))) | ||||
|         contributionBoundaryCallback.onItemAtFrontLoaded(mock(Contribution::class.java)) | ||||
|         verify(repository).save(anyList()); | ||||
|         verify(mediaClient).getMediaListForUser(anyString()); | ||||
|  | @ -97,7 +94,7 @@ class ContributionBoundaryCallbackTest { | |||
|             .thenReturn(Single.just(listOf(1L, 2L))) | ||||
|         whenever(sessionManager.userName).thenReturn("Test") | ||||
|         whenever(mediaClient.getMediaListForUser(anyString())).thenReturn( | ||||
|             Single.just(listOf(mock(Media::class.java))) | ||||
|             Single.just(listOf(media())) | ||||
|         ) | ||||
|         contributionBoundaryCallback.fetchContributions() | ||||
|         verify(repository).save(anyList()); | ||||
|  |  | |||
|  | @ -123,7 +123,7 @@ class DeleteHelperTest { | |||
|             .thenReturn(Observable.just(true)) | ||||
| 
 | ||||
|         whenever(media.displayTitle).thenReturn("Test file") | ||||
|         media.filename ="Test file.jpg" | ||||
|         whenever(media.filename).thenReturn("Test file.jpg") | ||||
| 
 | ||||
|         whenever(media.creator).thenReturn(null) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| package fr.free.nrw.commons.review | ||||
| 
 | ||||
| import com.nhaarman.mockitokotlin2.whenever | ||||
| import fr.free.nrw.commons.Media | ||||
| import fr.free.nrw.commons.media.MediaClient | ||||
| import io.reactivex.Observable | ||||
| import io.reactivex.Single | ||||
| import junit.framework.Assert.assertNotNull | ||||
| import junit.framework.Assert.assertNull | ||||
| import org.junit.Assert.assertTrue | ||||
| import org.junit.Before | ||||
|  | @ -61,7 +61,7 @@ class ReviewHelperTest { | |||
|                 .thenReturn(Observable.just(mockResponse)) | ||||
| 
 | ||||
|         val media = mock(Media::class.java) | ||||
|         media.filename="File:Test.jpg" | ||||
|         whenever(media.filename).thenReturn("Test file.jpg") | ||||
|         `when`(mediaClient?.getMedia(ArgumentMatchers.anyString())) | ||||
|                 .thenReturn(Single.just(media)) | ||||
|     } | ||||
|  | @ -126,4 +126,4 @@ class ReviewHelperTest { | |||
| 
 | ||||
|         assertTrue(firstRevisionOfFile is MwQueryPage.Revision) | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
|  | @ -2,6 +2,9 @@ package fr.free.nrw.commons.upload | |||
| 
 | ||||
| import android.content.ComponentName | ||||
| import android.content.Context | ||||
| import com.nhaarman.mockitokotlin2.mock | ||||
| import com.nhaarman.mockitokotlin2.whenever | ||||
| import fr.free.nrw.commons.Media | ||||
| import fr.free.nrw.commons.auth.SessionManager | ||||
| import fr.free.nrw.commons.contributions.Contribution | ||||
| import fr.free.nrw.commons.kvstore.JsonKvStore | ||||
|  | @ -47,7 +50,9 @@ class UploadControllerTest { | |||
|     @Test | ||||
|     fun startUpload() { | ||||
|         val contribution = mock(Contribution::class.java) | ||||
|         `when`(contribution.getCreator()).thenReturn("Creator") | ||||
|         val media = mock<Media>() | ||||
|         whenever(contribution.media).thenReturn(media) | ||||
|         whenever(media.creator).thenReturn("Creator") | ||||
|         uploadController!!.startUpload(contribution) | ||||
|     } | ||||
| } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Seán Mac Gillicuddy
						Seán Mac Gillicuddy