From d34d3b419ab34689c2695c4798cb50fd8f003099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey?= Date: Mon, 2 May 2022 13:38:05 +0200 Subject: [PATCH] Fix mocking in FileMenuFilterIT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not sure why this wasn't a compilation error Signed-off-by: Álvaro Brey --- ...lperTest.kt => ContentResolverHelperIT.kt} | 2 +- .../android/files/FileMenuFilterIT.kt | 49 +++++++++++-------- 2 files changed, 30 insertions(+), 21 deletions(-) rename app/src/androidTest/java/com/owncloud/android/datamodel/{ContentResolverHelperTest.kt => ContentResolverHelperIT.kt} (98%) diff --git a/app/src/androidTest/java/com/owncloud/android/datamodel/ContentResolverHelperTest.kt b/app/src/androidTest/java/com/owncloud/android/datamodel/ContentResolverHelperIT.kt similarity index 98% rename from app/src/androidTest/java/com/owncloud/android/datamodel/ContentResolverHelperTest.kt rename to app/src/androidTest/java/com/owncloud/android/datamodel/ContentResolverHelperIT.kt index 6bde0f35c2..da50a25ee9 100644 --- a/app/src/androidTest/java/com/owncloud/android/datamodel/ContentResolverHelperTest.kt +++ b/app/src/androidTest/java/com/owncloud/android/datamodel/ContentResolverHelperIT.kt @@ -36,7 +36,7 @@ import org.mockito.kotlin.eq import org.mockito.kotlin.verify @RunWith(AndroidJUnit4::class) -class ContentResolverHelperTest { +class ContentResolverHelperIT { companion object { private val URI = Uri.parse("http://foo.bar") diff --git a/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt b/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt index f3b5317f47..3b59a37c2c 100644 --- a/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt @@ -30,39 +30,48 @@ import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile +import com.owncloud.android.files.services.FileDownloader +import com.owncloud.android.files.services.FileUploader import com.owncloud.android.lib.resources.files.model.FileLockType import com.owncloud.android.lib.resources.status.CapabilityBooleanType import com.owncloud.android.lib.resources.status.OCCapability +import com.owncloud.android.services.OperationsService import com.owncloud.android.ui.activity.ComponentsGetter -import org.junit.After +import io.mockk.MockKAnnotations +import io.mockk.every +import io.mockk.impl.annotations.MockK import org.junit.Assert import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.MockitoAnnotations -import org.mockito.kotlin.any -import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) class FileMenuFilterIT : AbstractIT() { - @Mock - private lateinit var componentsGetter: ComponentsGetter + @MockK + private lateinit var mockComponentsGetter: ComponentsGetter - @Mock - private lateinit var fileDataStorageManager: FileDataStorageManager + @MockK + private lateinit var mockStorageManager: FileDataStorageManager - private lateinit var mocks: AutoCloseable + @MockK + private lateinit var mockFileUploaderBinder: FileUploader.FileUploaderBinder + + @MockK + private lateinit var mockFileDownloaderBinder: FileDownloader.FileDownloaderBinder + + @MockK + private lateinit var mockOperationsServiceBinder: OperationsService.OperationsServiceBinder @Before fun setup() { - mocks = MockitoAnnotations.openMocks(this) - } - - @After - fun tearDown() { - mocks.close() + MockKAnnotations.init(this) + every { mockFileUploaderBinder.isUploading(any(), any()) } returns false + every { mockComponentsGetter.fileUploaderBinder } returns mockFileUploaderBinder + every { mockFileDownloaderBinder.isDownloading(any(), any()) } returns false + every { mockComponentsGetter.fileDownloaderBinder } returns mockFileDownloaderBinder + every { mockOperationsServiceBinder.isSynchronizing(any(), any()) } returns false + every { mockComponentsGetter.operationsServiceBinder } returns mockOperationsServiceBinder } @Test @@ -149,9 +158,9 @@ class FileMenuFilterIT : AbstractIT() { ) private fun configureCapability(capability: OCCapability) { - whenever(fileDataStorageManager.getCapability(any())).thenReturn(capability) - whenever(fileDataStorageManager.getCapability(any())).thenReturn(capability) - whenever(componentsGetter.storageManager).thenReturn(fileDataStorageManager) + every { mockStorageManager.getCapability(any()) } returns capability + every { mockStorageManager.getCapability(any()) } returns capability + every { mockComponentsGetter.storageManager } returns mockStorageManager } private fun getMenu(activity: TestActivity): Menu { @@ -172,7 +181,7 @@ class FileMenuFilterIT : AbstractIT() { it.onActivity { activity -> val menu = getMenu(activity) - val sut = FileMenuFilter(file, componentsGetter, activity, true, user) + val sut = FileMenuFilter(file, mockComponentsGetter, activity, true, user) sut.filter(menu, false)