From b3d2fe4f0811fe326c1523a5b28332d11e05cb59 Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Sat, 1 Feb 2025 21:52:05 +0530 Subject: [PATCH] fix tests Signed-off-by: parneet-guraya --- .../commons/upload/ImageProcessingServiceTest.kt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/test/kotlin/fr/free/nrw/commons/upload/ImageProcessingServiceTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/upload/ImageProcessingServiceTest.kt index 90d2f20e6..9a5e20b25 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/upload/ImageProcessingServiceTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/upload/ImageProcessingServiceTest.kt @@ -1,5 +1,7 @@ package fr.free.nrw.commons.upload +import android.content.ContentResolver +import android.content.Context import android.net.Uri import fr.free.nrw.commons.location.LatLng import fr.free.nrw.commons.media.MediaClient @@ -18,6 +20,7 @@ import org.mockito.Mockito.mock import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations import java.io.FileInputStream +import java.io.InputStream class ImageProcessingServiceTest { @Mock @@ -38,6 +41,9 @@ class ImageProcessingServiceTest { @Mock internal var location: LatLng? = null + @Mock + internal lateinit var appContext: Context + @InjectMocks var imageProcessingService: ImageProcessingService? = null @@ -49,8 +55,10 @@ class ImageProcessingServiceTest { fun setUp() { MockitoAnnotations.openMocks(this) val mediaUri = mock(Uri::class.java) + val contentUri = mock(Uri::class.java) val mockPlace = mock(Place::class.java) val mockTitle = mock(List::class.java) + val contentResolver = mock(ContentResolver::class.java) `when`(mockPlace.wikiDataEntityId).thenReturn("Q1") `when`(mockPlace.getLocation()).thenReturn(mock(LatLng::class.java)) @@ -59,6 +67,8 @@ class ImageProcessingServiceTest { `when`(mockTitle.isSet).thenReturn(true)*/ `when`(uploadItem.mediaUri).thenReturn(mediaUri) + `when`(uploadItem.contentUri).thenReturn(contentUri) + `when`(appContext.contentResolver).thenReturn(contentResolver) `when`(uploadItem.imageQuality).thenReturn(ImageUtils.IMAGE_WAIT) `when`(uploadItem.uploadMediaDetails).thenReturn(mockTitle as MutableList?) @@ -68,7 +78,9 @@ class ImageProcessingServiceTest { `when`(fileUtilsWrapper!!.getFileInputStream(ArgumentMatchers.anyString())) .thenReturn(mock(FileInputStream::class.java)) - `when`(fileUtilsWrapper!!.getSHA1(any(FileInputStream::class.java))) + `when`(appContext.contentResolver.openInputStream(ArgumentMatchers.any())) + .thenReturn(mock(InputStream::class.java)) + `when`(fileUtilsWrapper!!.getSHA1(any(InputStream::class.java))) .thenReturn("fileSha") `when`(fileUtilsWrapper!!.getGeolocationOfFile(ArgumentMatchers.anyString(), any(LatLng::class.java)))