From ba78a675f1a32cab38abd0d7ac4d2a399b3ca010 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Tue, 29 Aug 2023 11:05:12 +0100 Subject: [PATCH 01/20] Done OCFolderBackupLocalDataSourceTest --- .../OCFolderBackupLocalDataSourceTest.kt | 184 ++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt diff --git a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt new file mode 100644 index 00000000000..1eb8918c553 --- /dev/null +++ b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt @@ -0,0 +1,184 @@ +package com.owncloud.android.data.folderbackup.datasources.implementation + +import com.owncloud.android.data.OwncloudDatabase +import com.owncloud.android.data.folderbackup.db.FolderBackUpEntity +import com.owncloud.android.data.folderbackup.db.FolderBackupDao +import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration +import com.owncloud.android.domain.camerauploads.model.UploadBehavior +import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import io.mockk.every +import io.mockk.mockkClass +import io.mockk.verify +import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertNull +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.junit.Test + +class OCFolderBackupLocalDataSourceTest { + + private lateinit var ocFolderBackupLocalDataSource: OCFolderBackupLocalDataSource + private val folderBackupDao = mockkClass(FolderBackupDao::class) + private val db = mockkClass(OwncloudDatabase::class) + + private val ocFolderBackUpEntity = FolderBackUpEntity( + accountName = OC_ACCOUNT_NAME, + behavior = UploadBehavior.COPY.name, + sourcePath = "/Photos", + uploadPath = "/Photos", + wifiOnly = true, + chargingOnly = true, + lastSyncTimestamp = 1542628397, + name = "" + ) + private val ocFolderBackUpConfiguration = FolderBackUpConfiguration( + accountName = OC_ACCOUNT_NAME, + behavior = UploadBehavior.COPY, + sourcePath = "/Photos", + uploadPath = "/Photos", + wifiOnly = true, + chargingOnly = true, + lastSyncTimestamp = 1542628397, + name = "" + ) + + @Before + fun init() { + + every { db.folderBackUpDao() } returns folderBackupDao + + ocFolderBackupLocalDataSource = OCFolderBackupLocalDataSource(folderBackupDao) + } + + @Test + fun `OCFolderBackupLocalDataSource with valid configurations returns a CameraUploadsConfiguration object`() { + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns ocFolderBackUpEntity + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns ocFolderBackUpEntity + + val resultCurrent = ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() + + assertEquals(ocFolderBackUpEntity.toModel(), resultCurrent?.pictureUploadsConfiguration) + assertEquals(ocFolderBackUpEntity.toModel(), resultCurrent?.videoUploadsConfiguration) + + verify(exactly = 1) { + folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) + folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) + } + } + + @Test + fun `OCFolderBackupLocalDataSource with no configurations returns null`() { + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns null + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns null + + val resultCurrent = ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() + + assertNull(resultCurrent) + + verify(exactly = 1) { + folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) + folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) + } + } + + @Test(expected = Exception::class) + fun `OCFolderBackupLocalDataSource when dao receive an exception returns an exception `() { + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } throws Exception() + + ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() + + verify(exactly = 1) { + folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) + folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) + } + } + + @Test + fun `getFolderBackupConfigurationByNameAsFlow with valid configurations returns a flow of CameraUploadsConfiguration`() = runBlocking { + every { folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) } returns flowOf( + ocFolderBackUpEntity + ) + + val resultCurrent = ocFolderBackupLocalDataSource.getFolderBackupConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) + + resultCurrent.collect { result -> + assertEquals(ocFolderBackUpEntity.toModel(), result) + } + verify(exactly = 1) { + folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) + } + } + + @Test(expected = Exception::class) + fun `getFolderBackupConfigurationByNameAsFlow when dao receive an exception returns an exception`() = runBlocking { + every { folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() + + val resultCurrent = ocFolderBackupLocalDataSource.getFolderBackupConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) + + resultCurrent.collect { result -> + assertEquals(ocFolderBackUpEntity.toModel(), result) + } + verify(exactly = 1) { + folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) + } + } + + @Test + fun `saveFolderBackupConfiguration with valid configurations returns unit and save the information`() { + every { folderBackupDao.update(ocFolderBackUpEntity) } returns 1 + + ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(ocFolderBackUpConfiguration) + + verify(exactly = 1) { + folderBackupDao.update(ocFolderBackUpEntity) + } + } + + @Test(expected = Exception::class) + fun `saveFolderBackupConfiguration when dao receive an exception returns an exception`() { + every { folderBackupDao.update(ocFolderBackUpEntity) } throws Exception() + + ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(ocFolderBackUpConfiguration) + + verify(exactly = 1) { + folderBackupDao.update(ocFolderBackUpEntity) + } + } + + @Test + fun `resetFolderBackupConfigurationByName when folder backup configuration is reset by name returns unit `() { + every { folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) } returns 1 + + ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) + + verify(exactly = 1) { + folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) + } + } + + @Test(expected = Exception::class) + fun `resetFolderBackupConfigurationByName when dao receive an exception returns an exception `() { + every { folderBackupDao.delete(any()) } throws Exception() + + ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) + + verify(exactly = 1) { + folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) + } + } + + private fun FolderBackUpEntity.toModel() = + FolderBackUpConfiguration( + accountName = accountName, + behavior = UploadBehavior.fromString(behavior), + sourcePath = sourcePath, + uploadPath = uploadPath, + wifiOnly = wifiOnly, + chargingOnly = chargingOnly, + lastSyncTimestamp = lastSyncTimestamp, + name = name + ) + +} \ No newline at end of file From 5a9ba7d816be9e200033a31ae6c4bbb6eece81ef Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Tue, 29 Aug 2023 11:31:35 +0100 Subject: [PATCH 02/20] Added verify to RemoteOAuthDataSourceTest --- .../datasources/RemoteOAuthDataSourceTest.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt index d774a814873..fd76c86e187 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt @@ -41,6 +41,7 @@ import com.owncloud.android.testutil.oauth.OC_TOKEN_RESPONSE import com.owncloud.android.utils.createRemoteOperationResultMock import io.mockk.every import io.mockk.mockk +import io.mockk.verify import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Before @@ -77,6 +78,11 @@ class RemoteOAuthDataSourceTest { assertNotNull(oidcDiscovery) assertEquals(OC_OIDC_SERVER_CONFIGURATION, oidcDiscovery) + + verify(exactly = 1) { + clientManager.getClientForAnonymousCredentials(OC_SECURE_BASE_URL, false) + oidcService.getOIDCServerDiscovery(ocClientMocked) + } } @Test(expected = Exception::class) @@ -101,6 +107,11 @@ class RemoteOAuthDataSourceTest { assertNotNull(tokenResponse) assertEquals(OC_TOKEN_RESPONSE, tokenResponse) + + verify(exactly = 1) { + clientManager.getClientForAnonymousCredentials(OC_SECURE_BASE_URL, false) + oidcService.performTokenRequest(ocClientMocked, any()) + } } @Test(expected = Exception::class) @@ -125,6 +136,11 @@ class RemoteOAuthDataSourceTest { assertNotNull(clientRegistrationInfo) assertEquals(OC_CLIENT_REGISTRATION, clientRegistrationInfo) + + verify(exactly = 1) { + clientManager.getClientForAnonymousCredentials(any(), false) + oidcService.registerClientWithRegistrationEndpoint(ocClientMocked, any()) + } } @Test(expected = Exception::class) From 24a34f1afd2f3396477bf5c6352c018a57716f60 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Tue, 29 Aug 2023 11:51:28 +0100 Subject: [PATCH 03/20] Added verify to OCRemoteShareesDataSourceTest --- .../OCRemoteShareesDataSourceTest.kt | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt index 399f05b6ae1..dad698524b5 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt @@ -33,6 +33,7 @@ import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.utils.createRemoteOperationResultMock import io.mockk.every import io.mockk.mockk +import io.mockk.verify import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNotNull @@ -74,6 +75,10 @@ class OCRemoteShareesDataSourceTest { fun `OCSharees List - ok - contains sharees entered as remote sharees`() { assertNotNull(sharees) assertEquals(5, sharees.size) + + verify(exactly = 1) { + ocShareeService.getSharees("user", 1, 30,) + } } @Test @@ -84,6 +89,10 @@ class OCRemoteShareesDataSourceTest { assertEquals(sharee.shareWith, "user") assertEquals(sharee.additionalInfo, "user@exact.com") assertTrue(sharee.isExactMatch) + + verify(exactly = 1) { + ocShareeService.getSharees("user", 1, 30,) + } } @Test @@ -94,6 +103,10 @@ class OCRemoteShareesDataSourceTest { assertEquals("user1", sharee.shareWith) assertEquals("user1@mail.com", sharee.additionalInfo) assertFalse(sharee.isExactMatch) + + verify(exactly = 1) { + ocShareeService.getSharees("user", 1, 30,) + } } @Test @@ -104,6 +117,10 @@ class OCRemoteShareesDataSourceTest { assertEquals("user2", sharee.shareWith) assertEquals("", sharee.additionalInfo) assertFalse(sharee.isExactMatch) + + verify(exactly = 1) { + ocShareeService.getSharees("user", 1, 30,) + } } @Test @@ -114,6 +131,10 @@ class OCRemoteShareesDataSourceTest { assertEquals("remoteuser1", sharee.shareWith) assertEquals("user1@remote.com", sharee.additionalInfo) assertFalse(sharee.isExactMatch) + + verify(exactly = 1) { + ocShareeService.getSharees("user", 1, 30,) + } } @Test @@ -124,6 +145,10 @@ class OCRemoteShareesDataSourceTest { assertEquals("group1", sharee.shareWith) assertEquals("group@group.com", sharee.additionalInfo) assertFalse(sharee.isExactMatch) + + verify(exactly = 1) { + ocShareeService.getSharees("user", 1, 30,) + } } @Test @@ -146,6 +171,10 @@ class OCRemoteShareesDataSourceTest { ) assertTrue(emptySharees.isEmpty()) + + verify(exactly = 2) { + ocShareeService.getSharees("user", 1, 30,) + } } companion object { From c7c907b096b99673e297754dcec9203c1c4f3a56 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Tue, 29 Aug 2023 12:34:42 +0100 Subject: [PATCH 04/20] Done OCLocalShareDataSourceTest --- .../datasources/OCLocalShareDataSourceTest.kt | 76 ++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index e213e6d812a..8ce4f8337dc 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -83,7 +83,7 @@ class OCLocalShareDataSourceTest { private val privateShareTypes = listOf(ShareType.USER, ShareType.GROUP, ShareType.FEDERATED) @Test - fun readLocalPrivateShares() { + fun `getSharesAsLiveData read local private shares returns a list of LiveData OCShare`() { val privateSharesAsLiveData: MutableLiveData> = MutableLiveData() privateSharesAsLiveData.value = privateShares @@ -110,10 +110,17 @@ class OCLocalShareDataSourceTest { assertEquals(false, shares[1].isFolder) assertEquals("user.name", shares[1].shareWith) assertEquals("Nicole", shares[1].sharedWithDisplayName) + + verify(exactly = 1) { + ocSharesDao.getSharesAsLiveData( + "/Docs/doc1.doc", + "admin@server", + privateShareTypes.map { it.value }) + } } @Test - fun readLocalPrivateShare() { + fun `getSharesAsLiveData read local private share returns a OCShare`() { val privateShareAsLiveData: MutableLiveData = MutableLiveData() privateShareAsLiveData.value = privateShares.first() @@ -125,10 +132,12 @@ class OCLocalShareDataSourceTest { assertEquals(false, share.isFolder) assertEquals("username", share.shareWith) assertEquals("Sophie", share.sharedWithDisplayName) + + verify(exactly = 1) { ocSharesDao.getShareAsLiveData(OC_SHARE.remoteId) } } @Test - fun insertPrivateShares() { + fun `insert private OCShare into repository returns a long`() { every { ocSharesDao.insertOrReplace(privateShares[0]) } returns 10 val insertedShareId = ocLocalSharesDataSource.insert( @@ -139,10 +148,27 @@ class OCLocalShareDataSourceTest { ) ) assertEquals(10, insertedShareId) + + verify(exactly = 1) { ocSharesDao.insertOrReplace(privateShares[0]) } + } + + @Test + fun `insert list of private OCShares into repository returns a list of long`() { + + val expectedValues = listOf(1, 2) + every { ocSharesDao.insertOrReplace(privateShares) } returns expectedValues + + val insertedSharesid = ocLocalSharesDataSource.insert( + privateShares.map { it.toModel() } + ) + + assertEquals(expectedValues, insertedSharesid) + + verify(exactly = 1) { ocSharesDao.insertOrReplace(privateShares) } } @Test - fun updatePrivateShare() { + fun `update private OCShare and returns a long`() { every { ocSharesDao.update(privateShares[1]) } returns 3 val updatedShareId = ocLocalSharesDataSource.update( @@ -153,6 +179,8 @@ class OCLocalShareDataSourceTest { ) ) assertEquals(3, updatedShareId) + + verify(exactly = 1) { ocSharesDao.update(privateShares[1]) } } /****************************************************************************************************** @@ -175,7 +203,7 @@ class OCLocalShareDataSourceTest { ) @Test - fun readLocalPublicShares() { + fun `getSharesAsLiveData read local public shares returns a list of LiveData OCShare`() { val publicSharesAsLiveData: MutableLiveData> = MutableLiveData() publicSharesAsLiveData.value = publicShares @@ -204,10 +232,17 @@ class OCLocalShareDataSourceTest { assertEquals(true, shares[1].isFolder) assertEquals("Photos link 2", shares[1].name) assertEquals("http://server:port/s/2", shares[1].shareLink) + + verify(exactly = 1) { + ocSharesDao.getSharesAsLiveData( + "/Photos/", + "admin@server", + listOf(ShareType.PUBLIC_LINK.value)) + } } @Test - fun insertPublicShare() { + fun `insert public OCShare into repository returns a long`() { every { ocSharesDao.insertOrReplace(publicShares[0]) } returns 7 val insertedShareId = ocLocalSharesDataSource.insert( @@ -219,10 +254,12 @@ class OCLocalShareDataSourceTest { ) ) assertEquals(7, insertedShareId) + + verify(exactly = 1) { ocSharesDao.insertOrReplace(publicShares[0]) } } @Test - fun insertPublicShares() { + fun `insert list of public OCShares into repository returns a list of long`() { val expectedValues = listOf(1, 2) every { ocSharesDao.insertOrReplace(publicShares) } returns expectedValues @@ -231,10 +268,12 @@ class OCLocalShareDataSourceTest { ) assertEquals(expectedValues, retrievedValues) + + verify(exactly = 1) { ocSharesDao.insertOrReplace(publicShares) } } @Test - fun updatePublicShares() { + fun `update public OCShare and returns a long`() { every { ocSharesDao.update(publicShares[1]) } returns 8 val updatedShareId = ocLocalSharesDataSource.update( @@ -246,6 +285,8 @@ class OCLocalShareDataSourceTest { ) ) assertEquals(8, updatedShareId) + + verify(exactly = 1) { ocSharesDao.update(publicShares[1]) } } /************************************************************************************************************** @@ -253,7 +294,7 @@ class OCLocalShareDataSourceTest { **************************************************************************************************************/ @Test - fun replaceShares() { + fun `replaceShares OCShares and returns a list of long`() { val expectedValues = listOf(1, 2) every { ocSharesDao.replaceShares(publicShares) } returns expectedValues @@ -262,6 +303,8 @@ class OCLocalShareDataSourceTest { ) assertEquals(expectedValues, retrievedValues) + + verify(exactly = 1) { ocSharesDao.replaceShares(publicShares) } } @Test @@ -269,15 +312,26 @@ class OCLocalShareDataSourceTest { every { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } returns Unit ocLocalSharesDataSource.deleteSharesForFile("file", OC_ACCOUNT_NAME) - verify { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } + verify(exactly = 1) { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } } @Test - fun deleteShare() { + fun `deleteShare OCShare by remoteId and returns a Int`() { every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } returns 1 val deletedRows = ocLocalSharesDataSource.deleteShare(OC_SHARE.remoteId) assertEquals(1, deletedRows) + + verify(exactly = 1) { ocSharesDao.deleteShare(OC_SHARE.remoteId) } + } + + @Test + fun `deleteSharesForAccount by account returns unit`() { + every { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } returns Unit + + ocLocalSharesDataSource.deleteSharesForAccount(OC_SHARE.accountOwner) + + verify(exactly = 1) { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } } } From 39a668bd7324b82ca8484495887bc5d52dad3eb5 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 31 Aug 2023 09:06:16 +0100 Subject: [PATCH 05/20] Done OCRemoteShareDataSourceTest --- .../OCRemoteShareDataSourceTest.kt | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt index 613efe8cc5c..b3f19a8ca2e 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt @@ -33,6 +33,7 @@ import com.owncloud.android.testutil.OC_SHARE import com.owncloud.android.utils.createRemoteOperationResultMock import io.mockk.every import io.mockk.mockk +import io.mockk.verify import org.hamcrest.CoreMatchers.notNullValue import org.hamcrest.MatcherAssert.assertThat import org.junit.Assert.assertEquals @@ -58,7 +59,7 @@ class OCRemoteShareDataSourceTest { ******************************************************************************************************/ @Test - fun insertPrivateShare() { + fun `insert private share returns OCShare`() { val createRemoteShareOperationResult = createRemoteOperationResultMock( ShareResponse( listOf( @@ -96,10 +97,14 @@ class OCRemoteShareDataSourceTest { assertEquals("user", privateShareAdded.shareWith) assertEquals("User", privateShareAdded.sharedWithDisplayName) assertEquals(1, privateShareAdded.permissions) + + verify(exactly = 1) { + ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + } } @Test - fun updatePrivateShare() { + fun `updateShare update a private share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( ShareResponse( listOf( @@ -136,6 +141,10 @@ class OCRemoteShareDataSourceTest { assertEquals("User", privateShareUpdated.sharedWithDisplayName) assertEquals(17, privateShareUpdated.permissions) assertEquals(false, privateShareUpdated.isFolder) + + verify(exactly = 1) { + ocShareService.updateShare(any(), any(), any(), any(), any()) + } } /****************************************************************************************************** @@ -143,7 +152,7 @@ class OCRemoteShareDataSourceTest { ******************************************************************************************************/ @Test - fun insertPublicShare() { + fun `insert public share returns OCShare`() { val createRemoteShareOperationResult = createRemoteOperationResultMock( ShareResponse( listOf( @@ -181,10 +190,14 @@ class OCRemoteShareDataSourceTest { assertEquals("Photos/img1.png", publicShareAdded.path) assertEquals(false, publicShareAdded.isFolder) assertEquals("http://server:port/s/112ejbhdasyd1", publicShareAdded.shareLink) + + verify(exactly = 1) { + ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + } } @Test - fun updatePublicShare() { + fun `updateShare update a public share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( ShareResponse( listOf( @@ -222,6 +235,10 @@ class OCRemoteShareDataSourceTest { assertEquals(2000, publicShareUpdated.expirationDate) assertEquals(1, publicShareUpdated.permissions) assertEquals("http://server:port/s/1275farv", publicShareUpdated.shareLink) + + verify(exactly = 1) { + ocShareService.updateShare(any(), any(), any(), any(), any()) + } } /****************************************************************************************************** @@ -229,7 +246,7 @@ class OCRemoteShareDataSourceTest { ******************************************************************************************************/ @Test - fun readRemoteShares() { + fun `getShares returns a list of OCShare`() { val remoteShares = listOf( remoteShareMapper.toRemote( OC_SHARE.copy( @@ -311,15 +328,23 @@ class OCRemoteShareDataSourceTest { assertEquals(false, groupShare.isFolder) assertEquals("family", groupShare.shareWith) assertEquals("My family", groupShare.sharedWithDisplayName) + + verify(exactly = 1) { + ocShareService.getShares( + remoteFilePath = "/Documents/doc", + reshares = true, + subfiles = true, + ) + } } @Test(expected = ShareNotFoundException::class) - fun insertShareFileNotFound() { + fun `insert share file not found`() { createShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) } @Test(expected = ShareForbiddenException::class) - fun insertShareForbidden() { + fun `insert share forbidden`() { createShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN) } @@ -345,12 +370,12 @@ class OCRemoteShareDataSourceTest { } @Test(expected = ShareNotFoundException::class) - fun updateShareFileNotFound() { + fun `update share file not found`() { updateShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) } @Test(expected = ShareForbiddenException::class) - fun updateShareForbidden() { + fun `update share forbidden`() { updateShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN) } @@ -374,7 +399,7 @@ class OCRemoteShareDataSourceTest { } @Test - fun deleteShare() { + fun `deleteShare delete a share returns unit`() { val removeRemoteShareOperationResult = createRemoteOperationResultMock( Unit, isSuccess = true @@ -386,16 +411,18 @@ class OCRemoteShareDataSourceTest { ocRemoteShareDataSource.deleteShare(remoteId = "3", accountName = "user@server") - // We check there's no exception here + verify(exactly = 1) { + ocShareService.deleteShare(any()) + } } @Test(expected = ShareNotFoundException::class) - fun removeShareFileNotFound() { + fun `remove share file not found`() { deleteShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) } @Test(expected = ShareForbiddenException::class) - fun removeShareForbidden() { + fun `remove share forbidden`() { deleteShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_FORBIDDEN) } From 6bcbb01b9873b21764acd5d2b48939cbf36a6f5b Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 31 Aug 2023 10:08:41 +0100 Subject: [PATCH 06/20] Working on OCLocalSpacesDataSourceTest --- .../OCLocalSpacesDataSourceTest.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt new file mode 100644 index 00000000000..a929b019704 --- /dev/null +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt @@ -0,0 +1,31 @@ +package com.owncloud.android.data.spaces.datasource.implementation + + +import com.owncloud.android.data.OwncloudDatabase +import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource +import com.owncloud.android.data.spaces.db.SpacesDao +import com.owncloud.android.testutil.OC_SPACE_PERSONAL +import com.owncloud.android.testutil.OC_SPACE_PROJECT_WITH_IMAGE +import com.owncloud.android.testutil.OC_SPACE_SPECIAL_IMAGE +import com.owncloud.android.testutil.OC_SPACE_SPECIAL_README +import io.mockk.every +import io.mockk.mockkClass +import org.junit.Before + +class OCLocalSpacesDataSourceTest { + + private lateinit var ocLocalSpacesDataSource: OCLocalSpacesDataSource + private val spacesDao = mockkClass(SpacesDao::class) + + val listSpace = listOf(OC_SPACE_PERSONAL, OC_SPACE_PROJECT_WITH_IMAGE) + val listSpaceSpecial = listOf(OC_SPACE_SPECIAL_IMAGE, OC_SPACE_SPECIAL_README) + + @Before + fun init() { + val db = mockkClass(OwncloudDatabase::class) + + every { db.spacesDao() } returns spacesDao + + ocLocalSpacesDataSource = OCLocalSpacesDataSource(spacesDao) + } +} \ No newline at end of file From 9fa48070736808543f70d615c35feadf67eedb56 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Fri, 1 Sep 2023 14:08:01 +0100 Subject: [PATCH 07/20] Done remote and local SpacesDataSource --- .../OCRemoteSpacesDataSource.kt | 8 +- .../OCLocalSpacesDataSourceTest.kt | 294 +++++++++++++++++- .../OCRemoteSpacesDataSourceTest.kt | 78 +++++ 3 files changed, 374 insertions(+), 6 deletions(-) create mode 100644 owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt diff --git a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt index bb9872f4450..5fa0441fb20 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt @@ -18,6 +18,7 @@ */ package com.owncloud.android.data.spaces.datasources.implementation +import androidx.annotation.VisibleForTesting import com.owncloud.android.data.ClientManager import com.owncloud.android.data.executeRemoteOperation import com.owncloud.android.data.spaces.datasources.RemoteSpacesDataSource @@ -43,7 +44,11 @@ class OCRemoteSpacesDataSource( return spacesResponse.map { it.toModel(accountName) } } - private fun SpaceResponse.toModel(accountName: String): OCSpace = + companion object { + + + @VisibleForTesting + fun SpaceResponse.toModel(accountName: String): OCSpace = OCSpace( accountName = accountName, driveAlias = driveAlias, @@ -87,4 +92,5 @@ class OCRemoteSpacesDataSource( ) } ) + } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt index a929b019704..1031f122da8 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt @@ -1,24 +1,113 @@ package com.owncloud.android.data.spaces.datasource.implementation - import com.owncloud.android.data.OwncloudDatabase import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource +import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource.Companion.toEntity +import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource.Companion.toModel +import com.owncloud.android.data.spaces.db.SpaceRootEntity +import com.owncloud.android.data.spaces.db.SpaceSpecialEntity import com.owncloud.android.data.spaces.db.SpacesDao +import com.owncloud.android.data.spaces.db.SpacesEntity +import com.owncloud.android.data.spaces.db.SpacesWithSpecials +import com.owncloud.android.domain.spaces.model.OCSpace +import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARES +import com.owncloud.android.domain.spaces.model.SpaceDeleted +import com.owncloud.android.domain.spaces.model.SpaceOwner +import com.owncloud.android.domain.spaces.model.SpaceQuota +import com.owncloud.android.domain.spaces.model.SpaceRoot +import com.owncloud.android.domain.spaces.model.SpaceUser +import com.owncloud.android.testutil.OC_ACCOUNT_ID +import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import com.owncloud.android.testutil.OC_CLIENT_ID import com.owncloud.android.testutil.OC_SPACE_PERSONAL -import com.owncloud.android.testutil.OC_SPACE_PROJECT_WITH_IMAGE import com.owncloud.android.testutil.OC_SPACE_SPECIAL_IMAGE import com.owncloud.android.testutil.OC_SPACE_SPECIAL_README +import io.mockk.Runs import io.mockk.every +import io.mockk.just import io.mockk.mockkClass +import io.mockk.verify +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.runBlocking +import org.junit.Assert.assertEquals import org.junit.Before +import org.junit.Test class OCLocalSpacesDataSourceTest { private lateinit var ocLocalSpacesDataSource: OCLocalSpacesDataSource private val spacesDao = mockkClass(SpacesDao::class) - val listSpace = listOf(OC_SPACE_PERSONAL, OC_SPACE_PROJECT_WITH_IMAGE) - val listSpaceSpecial = listOf(OC_SPACE_SPECIAL_IMAGE, OC_SPACE_SPECIAL_README) + private val WEB_DAV_URL = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9" + + private val spaceWithSpecials = SpacesWithSpecials( + SpacesEntity( + accountName = OC_ACCOUNT_NAME, + driveAlias = "driveAlias", + driveType = "driveType", + id = OC_ACCOUNT_ID, + ownerId = OC_CLIENT_ID, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + quota = null, + root = SpaceRootEntity( + eTag = "eTag", + id = "id", + webDavUrl = WEB_DAV_URL, + deleteState = "state" + ), + webUrl = "webUrl", + description = "description" + ), + listOf( + SpaceSpecialEntity( + accountName = OC_ACCOUNT_NAME, + eTag = "eTag", + fileMimeType = "fileMimeType", + id = OC_ACCOUNT_ID, + spaceId = OC_SPACE_PERSONAL.id, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + webDavUrl = WEB_DAV_URL, + size = 100, + specialFolderName = OC_SPACE_SPECIAL_IMAGE.name + ) + ) + ) + + private val listSpaceSpecial = listOf( + OCSpace( + accountName = OC_ACCOUNT_NAME, + driveAlias = "driveAlias", + driveType = "driveType", + id = OC_ACCOUNT_ID, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + owner = SpaceOwner( + user = SpaceUser( + id = "id" + ) + ), + quota = SpaceQuota( + remaining = 100, + state = "quotaResponse.state", + total = 100, + used = 100, + ), + root = SpaceRoot( + eTag = "eTag", + id = "id", + webDavUrl = WEB_DAV_URL, + deleted = SpaceDeleted(state = "state") + ), + webUrl = "webUrl", + description = "description", + special = listOf( + OC_SPACE_SPECIAL_IMAGE, + OC_SPACE_SPECIAL_README + ) + ) + ) @Before fun init() { @@ -26,6 +115,201 @@ class OCLocalSpacesDataSourceTest { every { db.spacesDao() } returns spacesDao - ocLocalSpacesDataSource = OCLocalSpacesDataSource(spacesDao) + ocLocalSpacesDataSource = OCLocalSpacesDataSource(spacesDao) + } + + @Test + fun `saveSpacesForAccount inserts spaces and special spaces returns unit`() { + val spaceEntities = mutableListOf() + val spaceSpecialEntities = mutableListOf() + + listSpaceSpecial.forEach { spaceModel -> + spaceEntities.add(spaceModel.toEntity()) + spaceModel.special?.let { listOfSpacesSpecials -> + spaceSpecialEntities.addAll(listOfSpacesSpecials.map { it.toEntity(spaceModel.accountName, spaceModel.id) }) + } + } + + every { + spacesDao.insertOrDeleteSpaces(any(), any()) + } just Runs + + ocLocalSpacesDataSource.saveSpacesForAccount(listSpaceSpecial) + + verify(exactly = 1) { + spacesDao.insertOrDeleteSpaces(spaceEntities, spaceSpecialEntities) + } + } + + @Test + fun `getPersonalSpaceForAccount by drive type returns a OCSpace`() { + every { + spacesDao.getSpacesByDriveTypeForAccount(any(), any()) + } returns listOf(OC_SPACE_PERSONAL.toEntity()) + + val resultActual = ocLocalSpacesDataSource.getPersonalSpaceForAccount(OC_ACCOUNT_NAME) + + assertEquals(OC_SPACE_PERSONAL, resultActual) + + verify(exactly = 1) { + spacesDao.getSpacesByDriveTypeForAccount(OC_ACCOUNT_NAME, setOf(OCSpace.DRIVE_TYPE_PERSONAL)) + } + } + + @Test + fun `getSharesSpaceForAccount returns a OCSpace`() { + every { + spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) + } returns OC_SPACE_PERSONAL.toEntity() + + val resultActual = ocLocalSpacesDataSource.getSharesSpaceForAccount(OC_ACCOUNT_NAME) + + assertEquals(OC_SPACE_PERSONAL, resultActual) + + verify(exactly = 1) { + spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) + } + } + + @Test + fun `getSpacesFromEveryAccountAsStream returns a flow of OCSpace`() = runBlocking { + + every { + spacesDao.getSpacesByDriveTypeFromEveryAccountAsStream( + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } returns flowOf(listOf(OC_SPACE_PERSONAL.toEntity())) + + val resultActual = ocLocalSpacesDataSource.getSpacesFromEveryAccountAsStream() + + resultActual.collect { result -> + assertEquals(listOf(OC_SPACE_PERSONAL), result) + } + + verify(exactly = 1) { + spacesDao.getSpacesByDriveTypeFromEveryAccountAsStream( + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } + } + + @Test + fun `getSpacesByDriveTypeWithSpecialsForAccountAsFlow returns a flow of OCSpace list`() = runBlocking { + + every { + spacesDao.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( + OC_ACCOUNT_NAME, + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } returns flowOf(listOf(spaceWithSpecials)) + + val resultActual = ocLocalSpacesDataSource.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( + OC_ACCOUNT_NAME, setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + + resultActual.collect { result -> + assertEquals(listOf(spaceWithSpecials.toModel()), result) + } + + verify(exactly = 1) { + spacesDao.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( + OC_ACCOUNT_NAME, + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } + } + + @Test + fun `getPersonalAndProjectSpacesForAccount returns a list of OCSpace`() { + + every { + spacesDao.getSpacesByDriveTypeForAccount( + OC_ACCOUNT_NAME, + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } returns listOf(OC_SPACE_PERSONAL.toEntity()) + + val resultActual = ocLocalSpacesDataSource.getPersonalAndProjectSpacesForAccount(OC_ACCOUNT_NAME) + + assertEquals(listOf(OC_SPACE_PERSONAL), resultActual) + + + verify(exactly = 1) { + spacesDao.getSpacesByDriveTypeForAccount( + OC_ACCOUNT_NAME, + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } + } + + @Test + fun `getSpaceWithSpecialsByIdForAccount returns a OCSpace`() { + + every { + spacesDao.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + } returns spaceWithSpecials + + val resultActual = ocLocalSpacesDataSource.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + + assertEquals(spaceWithSpecials.toModel(), resultActual) + + verify(exactly = 1) { + spacesDao.getSpaceWithSpecialsByIdForAccount( + OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME + ) + } + } + + @Test + fun `getWebDavUrlForSpace returns a string of webDavUrl`() { + + every { + spacesDao.getWebDavUrlForSpace(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + } returns WEB_DAV_URL + + val resultActual = ocLocalSpacesDataSource.getWebDavUrlForSpace(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + + assertEquals(WEB_DAV_URL, resultActual) + + verify(exactly = 1) { + spacesDao.getWebDavUrlForSpace( + OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME + ) + } + } + + @Test + fun `deleteSpacesForAccount delete the space by account returns Unit`() { + + every { + spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) + } returns Unit + + ocLocalSpacesDataSource.deleteSpacesForAccount(OC_ACCOUNT_NAME) + + verify(exactly = 1) { + spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) + } } } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt new file mode 100644 index 00000000000..46e991a98f7 --- /dev/null +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt @@ -0,0 +1,78 @@ +package com.owncloud.android.data.spaces.datasource.implementation + +import com.owncloud.android.data.ClientManager +import com.owncloud.android.data.spaces.datasources.implementation.OCRemoteSpacesDataSource +import com.owncloud.android.data.spaces.datasources.implementation.OCRemoteSpacesDataSource.Companion.toModel +import com.owncloud.android.lib.resources.spaces.responses.QuotaResponse +import com.owncloud.android.lib.resources.spaces.responses.RootResponse +import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse +import com.owncloud.android.lib.resources.spaces.services.OCSpacesService +import com.owncloud.android.testutil.OC_ACCOUNT_ID +import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import com.owncloud.android.utils.createRemoteOperationResultMock +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test + +class OCRemoteSpacesDataSourceTest { + + private lateinit var ocRemoteSpacesDataSource: OCRemoteSpacesDataSource + + private val ocSpaceService: OCSpacesService = mockk() + private val clientManager: ClientManager = mockk(relaxed = true) + + private val spaceResponse = + SpaceResponse( + driveAlias = "driveAlias", + driveType = "driveType", + id = OC_ACCOUNT_ID, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + webUrl = "webUrl", + description = "description", + owner = null, + root = RootResponse( + eTag = "eTag", + id = OC_ACCOUNT_ID, + webDavUrl = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9", + deleted = null + ), + quota = QuotaResponse( + remaining = 1, + state = "state", + total = 10, + used = 1 + ), + special = null, + + ) + + @Before + fun init() { + ocRemoteSpacesDataSource = OCRemoteSpacesDataSource(clientManager) + every { clientManager.getSpacesService(any()) } returns ocSpaceService + } + + @Test + fun `refreshSpacesForAccount returns a list of OCSpace`() { + val removeRemoteSpaceOperationResult = createRemoteOperationResultMock( + listOf(spaceResponse), isSuccess = true + ) + + every { ocSpaceService.getSpaces() } returns removeRemoteSpaceOperationResult + + val resultActual = ocRemoteSpacesDataSource.refreshSpacesForAccount(OC_ACCOUNT_NAME) + + assertEquals( + listOf(spaceResponse.toModel(OC_ACCOUNT_NAME)), resultActual + ) + + verify(exactly = 1) { + ocSpaceService.getSpaces() + } + } + +} \ No newline at end of file From 3e5c86dcf537423555e63f9a5a26eee4ae9db1bf Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 6 Sep 2023 14:17:27 +0100 Subject: [PATCH 08/20] Added the rest of the unit test --- .../OCFolderBackupLocalDataSource.kt | 28 +- .../OCLocalTransferDataSource.kt | 66 +-- .../OCFolderBackupLocalDataSourceTest.kt | 41 +- .../datasources/RemoteOAuthDataSourceTest.kt | 12 +- .../OCRemoteShareesDataSourceTest.kt | 31 +- .../datasources/OCLocalShareDataSourceTest.kt | 149 +++++- .../OCRemoteShareDataSourceTest.kt | 77 +++ .../OCLocalSpacesDataSourceTest.kt | 120 +++++ .../OCRemoteSpacesDataSourceTest.kt | 8 + .../OCLocalTransferDataSourceTest.kt | 505 ++++++++++++++++++ .../datasources/OCLocalUserDataSourceTest.kt | 56 +- .../datasources/OCRemoteUserDataSourceTest.kt | 19 +- .../OCRemoteWebFingerDatasourceTest.kt | 150 ++++++ 13 files changed, 1167 insertions(+), 95 deletions(-) create mode 100644 owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt create mode 100644 owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt diff --git a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt index 1ffd5d5bd10..a28bbf8b143 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt @@ -18,6 +18,7 @@ */ package com.owncloud.android.data.folderbackup.datasources.implementation +import androidx.annotation.VisibleForTesting import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource import com.owncloud.android.data.folderbackup.db.FolderBackUpEntity import com.owncloud.android.data.folderbackup.db.FolderBackupDao @@ -59,17 +60,22 @@ class OCFolderBackupLocalDataSource( /************************************************************************************************************** ************************************************* Mappers **************************************************** **************************************************************************************************************/ - private fun FolderBackUpEntity.toModel() = - FolderBackUpConfiguration( - accountName = accountName, - behavior = UploadBehavior.fromString(behavior), - sourcePath = sourcePath, - uploadPath = uploadPath, - wifiOnly = wifiOnly, - chargingOnly = chargingOnly, - lastSyncTimestamp = lastSyncTimestamp, - name = name - ) + + companion object { + @VisibleForTesting + fun FolderBackUpEntity.toModel() = + FolderBackUpConfiguration( + accountName = accountName, + behavior = UploadBehavior.fromString(behavior), + sourcePath = sourcePath, + uploadPath = uploadPath, + wifiOnly = wifiOnly, + chargingOnly = chargingOnly, + lastSyncTimestamp = lastSyncTimestamp, + name = name + ) + } + private fun FolderBackUpConfiguration.toEntity(): FolderBackUpEntity = FolderBackUpEntity( diff --git a/owncloudData/src/main/java/com/owncloud/android/data/transfers/datasources/implementation/OCLocalTransferDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/transfers/datasources/implementation/OCLocalTransferDataSource.kt index 05104379ae8..dfde793f7db 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/transfers/datasources/implementation/OCLocalTransferDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/transfers/datasources/implementation/OCLocalTransferDataSource.kt @@ -20,6 +20,7 @@ package com.owncloud.android.data.transfers.datasources.implementation +import androidx.annotation.VisibleForTesting import com.owncloud.android.data.transfers.datasources.LocalTransferDataSource import com.owncloud.android.data.transfers.db.OCTransferEntity import com.owncloud.android.data.transfers.db.TransferDao @@ -143,35 +144,40 @@ class OCLocalTransferDataSource( transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) } - private fun OCTransferEntity.toModel() = OCTransfer( - id = id, - localPath = localPath, - remotePath = remotePath, - accountName = accountName, - fileSize = fileSize, - status = TransferStatus.fromValue(status), - localBehaviour = if (localBehaviour > 1) UploadBehavior.MOVE else UploadBehavior.values()[localBehaviour], - forceOverwrite = forceOverwrite, - transferEndTimestamp = transferEndTimestamp, - lastResult = lastResult?.let { TransferResult.fromValue(it) }, - createdBy = UploadEnqueuedBy.values()[createdBy], - transferId = transferId, - spaceId = spaceId, - ) - - private fun OCTransfer.toEntity() = OCTransferEntity( - localPath = localPath, - remotePath = remotePath, - accountName = accountName, - fileSize = fileSize, - status = status.value, - localBehaviour = localBehaviour.ordinal, - forceOverwrite = forceOverwrite, - transferEndTimestamp = transferEndTimestamp, - lastResult = lastResult?.value, - createdBy = createdBy.ordinal, - transferId = transferId, - spaceId = spaceId, - ).apply { this@toEntity.id?.let { this.id = it } } + + companion object { + + @VisibleForTesting + fun OCTransferEntity.toModel() = OCTransfer( + id = id, + localPath = localPath, + remotePath = remotePath, + accountName = accountName, + fileSize = fileSize, + status = TransferStatus.fromValue(status), + localBehaviour = if (localBehaviour > 1) UploadBehavior.MOVE else UploadBehavior.values()[localBehaviour], + forceOverwrite = forceOverwrite, + transferEndTimestamp = transferEndTimestamp, + lastResult = lastResult?.let { TransferResult.fromValue(it) }, + createdBy = UploadEnqueuedBy.values()[createdBy], + transferId = transferId, + spaceId = spaceId, + ) + @VisibleForTesting + fun OCTransfer.toEntity() = OCTransferEntity( + localPath = localPath, + remotePath = remotePath, + accountName = accountName, + fileSize = fileSize, + status = status.value, + localBehaviour = localBehaviour.ordinal, + forceOverwrite = forceOverwrite, + transferEndTimestamp = transferEndTimestamp, + lastResult = lastResult?.value, + createdBy = createdBy.ordinal, + transferId = transferId, + spaceId = spaceId, + ).apply { this@toEntity.id?.let { this.id = it } } + } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt index 1eb8918c553..c18d73b7920 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt @@ -1,6 +1,7 @@ package com.owncloud.android.data.folderbackup.datasources.implementation import com.owncloud.android.data.OwncloudDatabase +import com.owncloud.android.data.folderbackup.datasources.implementation.OCFolderBackupLocalDataSource.Companion.toModel import com.owncloud.android.data.folderbackup.db.FolderBackUpEntity import com.owncloud.android.data.folderbackup.db.FolderBackupDao import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration @@ -52,7 +53,7 @@ class OCFolderBackupLocalDataSourceTest { } @Test - fun `OCFolderBackupLocalDataSource with valid configurations returns a CameraUploadsConfiguration object`() { + fun `getCameraUploadsConfiguration with valid configurations returns a CameraUploadsConfiguration object`() { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns ocFolderBackUpEntity every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns ocFolderBackUpEntity @@ -67,8 +68,17 @@ class OCFolderBackupLocalDataSourceTest { } } + @Test(expected = Exception::class) + fun `getCameraUploadsConfiguration with valid configurations returns an exception when service receive an exception`() { + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } throws Exception() + + ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() + + } + @Test - fun `OCFolderBackupLocalDataSource with no configurations returns null`() { + fun `getCameraUploadsConfiguration with no configurations returns null`() { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns null every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns null @@ -83,16 +93,12 @@ class OCFolderBackupLocalDataSourceTest { } @Test(expected = Exception::class) - fun `OCFolderBackupLocalDataSource when dao receive an exception returns an exception `() { + fun `getCameraUploadsConfiguration with no configurations returns an exception when service receive an exception`() { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } throws Exception() ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() - verify(exactly = 1) { - folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) - folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) - } } @Test @@ -120,9 +126,6 @@ class OCFolderBackupLocalDataSourceTest { resultCurrent.collect { result -> assertEquals(ocFolderBackUpEntity.toModel(), result) } - verify(exactly = 1) { - folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) - } } @Test @@ -142,9 +145,6 @@ class OCFolderBackupLocalDataSourceTest { ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(ocFolderBackUpConfiguration) - verify(exactly = 1) { - folderBackupDao.update(ocFolderBackUpEntity) - } } @Test @@ -164,21 +164,6 @@ class OCFolderBackupLocalDataSourceTest { ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) - verify(exactly = 1) { - folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) - } } - private fun FolderBackUpEntity.toModel() = - FolderBackUpConfiguration( - accountName = accountName, - behavior = UploadBehavior.fromString(behavior), - sourcePath = sourcePath, - uploadPath = uploadPath, - wifiOnly = wifiOnly, - chargingOnly = chargingOnly, - lastSyncTimestamp = lastSyncTimestamp, - name = name - ) - } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt index fd76c86e187..b8582022f8b 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt @@ -66,7 +66,7 @@ class RemoteOAuthDataSourceTest { } @Test - fun `perform oidc discovery - ok`() { + fun `performOIDCDiscovery returns a object of OIDCServerConfiguration`() { val oidcDiscoveryResult: RemoteOperationResult = createRemoteOperationResultMock(data = OC_REMOTE_OIDC_DISCOVERY_RESPONSE, isSuccess = true) @@ -86,7 +86,7 @@ class RemoteOAuthDataSourceTest { } @Test(expected = Exception::class) - fun `perform oidc discovery - ko`() { + fun `performOIDCDiscovery returns an exception when service receive an exception`() { every { oidcService.getOIDCServerDiscovery(ocClientMocked) } throws Exception() @@ -95,7 +95,7 @@ class RemoteOAuthDataSourceTest { } @Test - fun `perform token request - ok`() { + fun `performTokenRequest returns a TokenResponse`() { val tokenResponseResult: RemoteOperationResult = createRemoteOperationResultMock(data = OC_REMOTE_TOKEN_RESPONSE, isSuccess = true) @@ -115,7 +115,7 @@ class RemoteOAuthDataSourceTest { } @Test(expected = Exception::class) - fun `perform token request - ko`() { + fun `performTokenRequest returns an exception when service receive an exception`() { every { oidcService.performTokenRequest(ocClientMocked, OC_REMOTE_TOKEN_REQUEST_PARAMS_ACCESS) } throws Exception() @@ -124,7 +124,7 @@ class RemoteOAuthDataSourceTest { } @Test - fun `register client - ok`() { + fun `registerClient returns a ClientRegistrationInfo object`() { val clientRegistrationResponse: RemoteOperationResult = createRemoteOperationResultMock(data = OC_REMOTE_CLIENT_REGISTRATION_RESPONSE, isSuccess = true) @@ -144,7 +144,7 @@ class RemoteOAuthDataSourceTest { } @Test(expected = Exception::class) - fun `register client - ko`() { + fun `registerClient returns an exception when service receive an exception`() { every { oidcService.registerClientWithRegistrationEndpoint(ocClientMocked, OC_REMOTE_CLIENT_REGISTRATION_PARAMS) } throws Exception() diff --git a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt index dad698524b5..e11a63376fa 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt @@ -72,7 +72,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCSharees List - ok - contains sharees entered as remote sharees`() { + fun `getSharees contains sharees entered as remote sharees returns a list of OCSharee`() { assertNotNull(sharees) assertEquals(5, sharees.size) @@ -82,7 +82,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCSharees List - ok - contains exact user match`() { + fun `getSharees contains exact user match returns a list of OCSharee`() { val sharee = sharees[0] assertEquals(sharee.label, "User") assertEquals(sharee.shareType, ShareType.USER) @@ -96,7 +96,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCSharees List - ok - contains one user not exactly matched`() { + fun `getSharees contains one user not exactly matched returns a list of OCSharee`() { val sharee = sharees[1] assertEquals("User 1", sharee.label) assertEquals(ShareType.USER, sharee.shareType) @@ -110,7 +110,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCShares List - ok - contains one user without additional info`() { + fun `getSharees contains one user without additional info returns a list of OCSharee`() { val sharee = sharees[2] assertEquals("User 2", sharee.label) assertEquals(ShareType.USER, sharee.shareType) @@ -124,7 +124,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCShares List - ok - contains one remote user`() { + fun `getSharees contains one remote user returns a list of OCSharee`() { val sharee = sharees[3] assertEquals("Remoteuser 1", sharee.label) assertEquals(ShareType.FEDERATED, sharee.shareType) @@ -138,7 +138,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCShares List - ok - contains one group`() { + fun `getSharees contains one group returns a list of OCSharee`() { val sharee = sharees[4] assertEquals("Group 1", sharee.label) assertEquals(ShareType.GROUP, sharee.shareType) @@ -152,7 +152,7 @@ class OCRemoteShareesDataSourceTest { } @Test - fun `OCShares List - ok - handle empty response`() { + fun `getSharees handle empty response returns a list of OCSharee`() { val getRemoteShareesOperationResult = createRemoteOperationResultMock( EMPTY_REMOTE_SHAREES, true @@ -177,6 +177,23 @@ class OCRemoteShareesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSharees returns an exception when service receive an exception`() { + every { + ocShareeService.getSharees("user", 1, 30) + } throws Exception() + + ocRemoteShareesDataSource.getSharees( + "user", + 1, + 30, + OC_ACCOUNT_NAME, + ) + verify(exactly = 2) { + ocShareeService.getSharees("user", 1, 30,) + } + } + companion object { val REMOTE_SHAREES = ShareeOcsResponse( ExactSharees( diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index 8ce4f8337dc..59d6652255d 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -119,6 +119,21 @@ class OCLocalShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSharesAsLiveData read local private shares returns an exception when dao receive an exception`() { + every { + ocSharesDao.getSharesAsLiveData( + "/Docs/doc1.doc", + "admin@server", + privateShareTypes.map { it.value }) + } throws Exception() + + ocLocalSharesDataSource.getSharesAsLiveData( + "/Docs/doc1.doc", "admin@server", privateShareTypes + ).getLastEmittedValue()!! + + } + @Test fun `getSharesAsLiveData read local private share returns a OCShare`() { val privateShareAsLiveData: MutableLiveData = MutableLiveData() @@ -136,6 +151,15 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.getShareAsLiveData(OC_SHARE.remoteId) } } + @Test(expected = Exception::class) + fun `getSharesAsLiveData read local private share returns an exception when dao receive an exception`() { + + every { ocSharesDao.getShareAsLiveData(OC_SHARE.remoteId) } throws Exception() + + ocLocalSharesDataSource.getShareAsLiveData(OC_SHARE.remoteId).getLastEmittedValue()!! + + } + @Test fun `insert private OCShare into repository returns a long`() { every { ocSharesDao.insertOrReplace(privateShares[0]) } returns 10 @@ -152,6 +176,20 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(privateShares[0]) } } + @Test(expected = Exception::class) + fun `insert private OCShare into repository returns an exception when dao receive an exception`() { + every { ocSharesDao.insertOrReplace(privateShares[0]) } throws Exception() + + ocLocalSharesDataSource.insert( + OC_PRIVATE_SHARE.copy( + path = "/Docs/doc1.doc", + shareWith = "username", + sharedWithDisplayName = "Sophie" + ) + ) + } + + @Test fun `insert list of private OCShares into repository returns a list of long`() { @@ -167,6 +205,16 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(privateShares) } } + @Test(expected = Exception::class) + fun `insert list of private OCShares into repository returns an exception when dao receive an exception`() { + + every { ocSharesDao.insertOrReplace(privateShares) } throws Exception() + + ocLocalSharesDataSource.insert( + privateShares.map { it.toModel() } + ) + } + @Test fun `update private OCShare and returns a long`() { every { ocSharesDao.update(privateShares[1]) } returns 3 @@ -183,6 +231,19 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.update(privateShares[1]) } } + @Test(expected = Exception::class) + fun `update private OCShare and returns returns an exception when dao receive an exception`() { + every { ocSharesDao.update(privateShares[1]) } throws Exception() + + ocLocalSharesDataSource.update( + OC_PRIVATE_SHARE.copy( + path = "/Docs/doc1.doc", + shareWith = "user.name", + sharedWithDisplayName = "Nicole" + ) + ) + } + /****************************************************************************************************** ******************************************* PUBLIC SHARES ******************************************** ******************************************************************************************************/ @@ -241,6 +302,23 @@ class OCLocalShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSharesAsLiveData read local public shares returns an exception when dao receive an exception`() { + every { + ocSharesDao.getSharesAsLiveData( + "/Photos/", + "admin@server", + listOf(ShareType.PUBLIC_LINK.value) + ) + } throws Exception() + + ocLocalSharesDataSource.getSharesAsLiveData( + "/Photos/", + "admin@server", + listOf(ShareType.PUBLIC_LINK) + ).getLastEmittedValue()!! + } + @Test fun `insert public OCShare into repository returns a long`() { every { ocSharesDao.insertOrReplace(publicShares[0]) } returns 7 @@ -258,6 +336,20 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(publicShares[0]) } } + @Test(expected = Exception::class) + fun `insert public OCShare into repository returns an exception when dao receive an exception`() { + every { ocSharesDao.insertOrReplace(publicShares[0]) } throws Exception() + + ocLocalSharesDataSource.insert( + OC_PUBLIC_SHARE.copy( + path = "/Photos/", + isFolder = true, + name = "Photos link", + shareLink = "http://server:port/s/1" + ) + ) + } + @Test fun `insert list of public OCShares into repository returns a list of long`() { val expectedValues = listOf(1, 2) @@ -272,6 +364,16 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(publicShares) } } + @Test(expected = Exception::class) + fun `insert list of public OCShares into repository returns an exception when dao receive an exception`() { + + every { ocSharesDao.insertOrReplace(publicShares) } throws Exception() + + ocLocalSharesDataSource.insert( + publicShares.map { it.toModel() } + ) + } + @Test fun `update public OCShare and returns a long`() { every { ocSharesDao.update(publicShares[1]) } returns 8 @@ -289,6 +391,20 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.update(publicShares[1]) } } + @Test(expected = Exception::class) + fun `update public OCShare and returns an exception when dao receive an exception`() { + every { ocSharesDao.update(publicShares[1]) } throws Exception() + + ocLocalSharesDataSource.update( + OC_PUBLIC_SHARE.copy( + path = "/Photos/", + isFolder = true, + name = "Photos link 2", + shareLink = "http://server:port/s/2" + ) + ) + } + /************************************************************************************************************** *************************************************** COMMON *************************************************** **************************************************************************************************************/ @@ -307,14 +423,31 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.replaceShares(publicShares) } } + @Test(expected = Exception::class) + fun `replaceShares returns returns an exception when dao receive an exception`() { + + every { ocSharesDao.replaceShares(publicShares) } throws Exception() + + ocLocalSharesDataSource.replaceShares( + publicShares.map { it.toModel() } + ) + } + @Test - fun deleteSharesForFile() { + fun `deleteSharesForFile returns Unit`() { every { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } returns Unit ocLocalSharesDataSource.deleteSharesForFile("file", OC_ACCOUNT_NAME) verify(exactly = 1) { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } } + @Test(expected = Exception::class) + fun `deleteSharesForFile returns an exception when dao receive an exception`() { + every { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } throws Exception() + ocLocalSharesDataSource.deleteSharesForFile("file", OC_ACCOUNT_NAME) + } + + @Test fun `deleteShare OCShare by remoteId and returns a Int`() { every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } returns 1 @@ -326,6 +459,13 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.deleteShare(OC_SHARE.remoteId) } } + @Test(expected = Exception::class) + fun `deleteShare OCShare by remoteId returns an exception when dao receive an exception`() { + every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } throws Exception() + + ocLocalSharesDataSource.deleteShare(OC_SHARE.remoteId) + } + @Test fun `deleteSharesForAccount by account returns unit`() { every { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } returns Unit @@ -334,4 +474,11 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } } + + @Test(expected = Exception::class) + fun `deleteSharesForAccount by account returns an exception when dao receive an exception`() { + every { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } throws Exception() + + ocLocalSharesDataSource.deleteSharesForAccount(OC_SHARE.accountOwner) + } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt index b3f19a8ca2e..d393d4e4bd0 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt @@ -103,6 +103,22 @@ class OCRemoteShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `insert private share returns an exception when service receive an exception`() { + + every { + ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + } throws Exception() + + ocRemoteShareDataSource.insert( + remoteFilePath = "Photos/", + shareType = ShareType.USER, + shareWith = "user", + permissions = 1, + accountName = "user@server" + ) + } + @Test fun `updateShare update a private share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( @@ -147,6 +163,20 @@ class OCRemoteShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `updateShare update a private share returns an exception when service receive an exception`() { + + every { + ocShareService.updateShare(any(), any(), any(), any(), any()) + } throws Exception() + + ocRemoteShareDataSource.updateShare( + remoteId = "3", + permissions = 17, + accountName = "user@server" + ) + } + /****************************************************************************************************** ******************************************* PUBLIC SHARES ******************************************** ******************************************************************************************************/ @@ -196,6 +226,21 @@ class OCRemoteShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `insert public share returns an exception when service receive an exception`() { + every { + ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + } throws Exception() + + ocRemoteShareDataSource.insert( + "Photos/img1.png", + ShareType.PUBLIC_LINK, + "", + 1, + accountName = "user@server" + ) + } + @Test fun `updateShare update a public share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( @@ -241,6 +286,21 @@ class OCRemoteShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `updateShare update a public share returns an exception when service receive an exception`() { + + every { + ocShareService.updateShare(any(), any(), any(), any(), any()) + } throws Exception() + + ocRemoteShareDataSource.updateShare( + remoteId = "3", + permissions = 17, + accountName = "user@server" + ) + + } + /****************************************************************************************************** *********************************************** COMMON *********************************************** ******************************************************************************************************/ @@ -338,6 +398,23 @@ class OCRemoteShareDataSourceTest { } } + @Test(expected = Exception::class) + fun `getShares returns an exception when service receive an exception`() { + + every { + ocShareService.getShares(any(), any(), any()) + } throws Exception() + + // Get shares from remote datasource + ocRemoteShareDataSource.getShares( + remoteFilePath = "/Documents/doc", + reshares = true, + subfiles = true, + accountName = "user@server" + ) + + } + @Test(expected = ShareNotFoundException::class) fun `insert share file not found`() { createShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt index 1031f122da8..249390fe280 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt @@ -141,6 +141,25 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `saveSpacesForAccount inserts spaces and special spaces returns an exception when dao receive an exception`() { + val spaceEntities = mutableListOf() + val spaceSpecialEntities = mutableListOf() + + listSpaceSpecial.forEach { spaceModel -> + spaceEntities.add(spaceModel.toEntity()) + spaceModel.special?.let { listOfSpacesSpecials -> + spaceSpecialEntities.addAll(listOfSpacesSpecials.map { it.toEntity(spaceModel.accountName, spaceModel.id) }) + } + } + + every { + spacesDao.insertOrDeleteSpaces(any(), any()) + } throws Exception() + + ocLocalSpacesDataSource.saveSpacesForAccount(listSpaceSpecial) + } + @Test fun `getPersonalSpaceForAccount by drive type returns a OCSpace`() { every { @@ -156,6 +175,16 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getPersonalSpaceForAccount by drive type returns an exception when dao receive an exception`() { + every { + spacesDao.getSpacesByDriveTypeForAccount(any(), any()) + } throws Exception() + + ocLocalSpacesDataSource.getPersonalSpaceForAccount(OC_ACCOUNT_NAME) + } + + @Test fun `getSharesSpaceForAccount returns a OCSpace`() { every { @@ -171,6 +200,15 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSharesSpaceForAccount returns an exception when dao receive an exception`() { + every { + spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) + } throws Exception() + + ocLocalSpacesDataSource.getSharesSpaceForAccount(OC_ACCOUNT_NAME) + } + @Test fun `getSpacesFromEveryAccountAsStream returns a flow of OCSpace`() = runBlocking { @@ -199,6 +237,21 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSpacesFromEveryAccountAsStream returns an exception when dao receive an exception`() { + + every { + spacesDao.getSpacesByDriveTypeFromEveryAccountAsStream( + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } throws Exception() + + ocLocalSpacesDataSource.getSpacesFromEveryAccountAsStream() + } + @Test fun `getSpacesByDriveTypeWithSpecialsForAccountAsFlow returns a flow of OCSpace list`() = runBlocking { @@ -234,6 +287,26 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSpacesByDriveTypeWithSpecialsForAccountAsFlow returns an exception when dao receive an exception`() { + + every { + spacesDao.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( + OC_ACCOUNT_NAME, + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } throws Exception() + + ocLocalSpacesDataSource.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( + OC_ACCOUNT_NAME, setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } @Test fun `getPersonalAndProjectSpacesForAccount returns a list of OCSpace`() { @@ -263,6 +336,21 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getPersonalAndProjectSpacesForAccount returns an exception when dao receive an exception`() { + + every { + spacesDao.getSpacesByDriveTypeForAccount( + OC_ACCOUNT_NAME, + setOf( + OCSpace.DRIVE_TYPE_PERSONAL, + OCSpace.DRIVE_TYPE_PROJECT + ) + ) + } throws Exception() + + ocLocalSpacesDataSource.getPersonalAndProjectSpacesForAccount(OC_ACCOUNT_NAME) + } @Test fun `getSpaceWithSpecialsByIdForAccount returns a OCSpace`() { @@ -281,6 +369,16 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getSpaceWithSpecialsByIdForAccount returns an exception when dao receive an exception`() { + + every { + spacesDao.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + } throws Exception() + + ocLocalSpacesDataSource.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + } + @Test fun `getWebDavUrlForSpace returns a string of webDavUrl`() { @@ -299,6 +397,17 @@ class OCLocalSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `getWebDavUrlForSpace returns an exception when dao receive an exception`() { + + every { + spacesDao.getWebDavUrlForSpace(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + } throws Exception() + + ocLocalSpacesDataSource.getWebDavUrlForSpace(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) + + } + @Test fun `deleteSpacesForAccount delete the space by account returns Unit`() { @@ -312,4 +421,15 @@ class OCLocalSpacesDataSourceTest { spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) } } + + @Test(expected = Exception::class) + fun `deleteSpacesForAccount delete the space by account returns an exception when dao receive an exception`() { + + every { + spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) + } throws Exception() + + ocLocalSpacesDataSource.deleteSpacesForAccount(OC_ACCOUNT_NAME) + + } } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt index 46e991a98f7..37da22053ad 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt @@ -75,4 +75,12 @@ class OCRemoteSpacesDataSourceTest { } } + @Test(expected = Exception::class) + fun `refreshSpacesForAccount returns an exception when service receive an exception`() { + + every { ocSpaceService.getSpaces() } throws Exception() + + ocRemoteSpacesDataSource.refreshSpacesForAccount(OC_ACCOUNT_NAME) + } + } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt new file mode 100644 index 00000000000..b0906b27975 --- /dev/null +++ b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt @@ -0,0 +1,505 @@ +package com.owncloud.android.data.transfers.implementation + +import com.owncloud.android.data.OwncloudDatabase +import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource +import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource.Companion.toEntity +import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource.Companion.toModel +import com.owncloud.android.data.transfers.db.OCTransferEntity +import com.owncloud.android.data.transfers.db.TransferDao +import com.owncloud.android.domain.camerauploads.model.UploadBehavior +import com.owncloud.android.domain.transfers.model.OCTransfer +import com.owncloud.android.domain.transfers.model.TransferResult +import com.owncloud.android.domain.transfers.model.TransferStatus +import com.owncloud.android.domain.transfers.model.UploadEnqueuedBy +import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import io.mockk.every +import io.mockk.mockkClass +import io.mockk.verify +import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.runBlocking +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test + +class OCLocalTransferDataSourceTest { + private lateinit var ocLocalTransferDataSource: OCLocalTransferDataSource + private val transferDao = mockkClass(TransferDao::class) + private val id = -1L + private val ocTransfer = OCTransfer( + id = id, + localPath = "/local/path", + remotePath = "/remote/path", + accountName = OC_ACCOUNT_NAME, + fileSize = 1024L, + status = TransferStatus.TRANSFER_IN_PROGRESS, + localBehaviour = UploadBehavior.MOVE, + forceOverwrite = true, + createdBy = UploadEnqueuedBy.ENQUEUED_BY_USER + ) + private val transferEntity: OCTransferEntity = ocTransfer.toEntity() + + @Before + fun init() { + val db = mockkClass(OwncloudDatabase::class) + + every { db.transferDao() } returns transferDao + + ocLocalTransferDataSource = OCLocalTransferDataSource(transferDao) + } + + @Test + fun `saveTransfer returns a Long`() { + val resultExpected = 1L + every { + transferDao.insertOrReplace(any()) + } returns resultExpected + + val resultActual = ocLocalTransferDataSource.saveTransfer(ocTransfer) + + assertEquals(resultExpected, resultActual) + + verify(exactly = 1) { + transferDao.insertOrReplace(ocTransfer.toEntity()) + } + } + + @Test(expected = Exception::class) + fun `saveTransfer returns an exception when dao receive an exception`() { + + every { + transferDao.insertOrReplace(any()) + } throws Exception() + + ocLocalTransferDataSource.saveTransfer(ocTransfer) + } + @Test + fun `updateTransfer returns a Long`() { + val resultExpected = 1L + every { + transferDao.insertOrReplace(any()) + } returns resultExpected + + ocLocalTransferDataSource.updateTransfer(ocTransfer) + + verify(exactly = 1) { + transferDao.insertOrReplace(ocTransfer.toEntity()) + } + } + + @Test(expected = Exception::class) + fun `updateTransfer returns an exception when dao receive an exception`() { + every { + transferDao.insertOrReplace(any()) + } throws Exception() + + ocLocalTransferDataSource.updateTransfer(ocTransfer) + } + @Test + fun `updateTransferStatusToInProgressById returns a unit`() { + val resultExpected = 10L + every { + transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_IN_PROGRESS.value) + } returns Unit + + ocLocalTransferDataSource.updateTransferStatusToInProgressById(resultExpected) + + verify(exactly = 1) { + transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_IN_PROGRESS.value) + } + } + + @Test(expected = Exception::class) + fun `updateTransferStatusToInProgressById returns an exception when dao receive an exception`() { + val resultExpected = 10L + every { + transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_IN_PROGRESS.value) + } throws Exception() + + ocLocalTransferDataSource.updateTransferStatusToInProgressById(resultExpected) + + } + + @Test + fun `updateTransferStatusToEnqueuedById returns a unit`() { + val resultExpected = 10L + every { + transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_QUEUED.value) + } returns Unit + + ocLocalTransferDataSource.updateTransferStatusToEnqueuedById(resultExpected) + + verify(exactly = 1) { + transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_QUEUED.value) + } + } + + @Test(expected = Exception::class) + fun `updateTransferStatusToEnqueuedById returns an exception when dao receive an exception`() { + val resultExpected = 10L + every { + transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_QUEUED.value) + } throws Exception() + + ocLocalTransferDataSource.updateTransferStatusToEnqueuedById(resultExpected) + + } + @Test + fun `updateTransferWhenFinished returns a unit`() { + val timestamp = System.currentTimeMillis() + every { + transferDao.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED.value, timestamp, TransferResult.UPLOADED.value) + } returns Unit + + ocLocalTransferDataSource.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED, timestamp, TransferResult.UPLOADED) + + verify(exactly = 1) { + transferDao.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED.value, timestamp, TransferResult.UPLOADED.value) + } + } + + @Test(expected = Exception::class) + fun `updateTransferWhenFinished returns an exception when dao receive an exception`() { + val timestamp = System.currentTimeMillis() + every { + transferDao.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED.value, timestamp, TransferResult.UPLOADED.value) + } throws Exception() + + ocLocalTransferDataSource.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED, timestamp, TransferResult.UPLOADED) + + } + + @Test + fun `updateTransferLocalPath returns a unit`() { + every { + transferDao.updateTransferLocalPath(id, ocTransfer.localPath) + } returns Unit + + ocLocalTransferDataSource.updateTransferLocalPath(id, ocTransfer.localPath) + + verify(exactly = 1) { + transferDao.updateTransferLocalPath(id, ocTransfer.localPath) + } + } + + @Test(expected = Exception::class) + fun `updateTransferLocalPath returns an exception when dao receive an exception`() { + every { + transferDao.updateTransferLocalPath(id, ocTransfer.localPath) + } throws Exception() + + ocLocalTransferDataSource.updateTransferLocalPath(id, ocTransfer.localPath) + + } + + @Test + fun `updateTransferStorageDirectoryInLocalPath returns a unit`() { + val oldDirectory = "oldDirectory" + val newDirectory = "newDirectory" + + every { + transferDao.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) + } returns Unit + + ocLocalTransferDataSource.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) + + verify(exactly = 1) { + transferDao.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) + } + } + + @Test(expected = Exception::class) + fun `updateTransferStorageDirectoryInLocalPath returns an exception when dao receive an exception`() { + val oldDirectory = "oldDirectory" + val newDirectory = "newDirectory" + + every { + transferDao.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) + } throws Exception() + + ocLocalTransferDataSource.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) + + } + @Test + fun `deleteTransferById returns a unit`() { + every { + transferDao.deleteTransferWithId(id) + } returns Unit + + ocLocalTransferDataSource.deleteTransferById(id) + + verify(exactly = 1) { + transferDao.deleteTransferWithId(id) + } + } + + @Test(expected = Exception::class) + fun `deleteTransferById returns an exception when dao receive an exception`() { + every { + transferDao.deleteTransferWithId(id) + } throws Exception() + + ocLocalTransferDataSource.deleteTransferById(id) + + } + @Test + fun `deleteAllTransfersFromAccount returns a unit`() { + every { + transferDao.deleteTransfersWithAccountName(OC_ACCOUNT_NAME) + } returns Unit + + ocLocalTransferDataSource.deleteAllTransfersFromAccount(OC_ACCOUNT_NAME) + + verify(exactly = 1) { + transferDao.deleteTransfersWithAccountName(OC_ACCOUNT_NAME) + } + } + + @Test(expected = Exception::class) + fun `deleteAllTransfersFromAccount returns an exception when dao receive an exception`() { + every { + transferDao.deleteTransfersWithAccountName(OC_ACCOUNT_NAME) + } throws Exception() + + ocLocalTransferDataSource.deleteAllTransfersFromAccount(OC_ACCOUNT_NAME) + + } + @Test + fun `getTransferById returns a OCTransfer`() { + every { + transferDao.getTransferWithId(any()) + } returns ocTransfer.toEntity() + + val actualResult = ocLocalTransferDataSource.getTransferById(id) + + assertEquals(ocTransfer, actualResult) + + verify(exactly = 1) { + transferDao.getTransferWithId(id) + } + } + + @Test(expected = Exception::class) + fun `getTransferById returns an exception when dao receive an exception`() { + every { + transferDao.getTransferWithId(any()) + } throws Exception() + + ocLocalTransferDataSource.getTransferById(id) + + } + + @Test + fun `getAllTransfers returns a list of OCTransfer`() { + + every { + transferDao.getAllTransfers() + } returns listOf(transferEntity) + + val actualResult = ocLocalTransferDataSource.getAllTransfers() + + assertEquals(listOf(transferEntity.toModel()), actualResult) + + verify(exactly = 1) { + transferDao.getAllTransfers() + } + } + + @Test(expected = Exception::class) + fun `getAllTransfers returns an exception when dao receive an exception`() { + + every { + transferDao.getAllTransfers() + } throws Exception() + + ocLocalTransferDataSource.getAllTransfers() + + } + + @Test + fun `getAllTransfersAsStream returns a flow of list of OCTransfer`() = runBlocking { + + every { + transferDao.getAllTransfersAsStream() + } returns flowOf(listOf(transferEntity)) + + val actualResult = ocLocalTransferDataSource.getAllTransfersAsStream() + + actualResult.collect { result -> + assertEquals(listOf(transferEntity.toModel()), result) + } + + verify(exactly = 1) { + transferDao.getAllTransfersAsStream() + } + } + + @Test(expected = Exception::class) + fun `getAllTransfersAsStream returns an exception when dao receive an exception`() { + + every { + transferDao.getAllTransfersAsStream() + } throws Exception() + + ocLocalTransferDataSource.getAllTransfersAsStream() + + } + + @Test + fun `getLastTransferFor returns a OCTransfer`() { + + every { + transferDao.getLastTransferWithRemotePathAndAccountName(ocTransfer.remotePath, OC_ACCOUNT_NAME) + } returns transferEntity + + val actualResult = ocLocalTransferDataSource.getLastTransferFor(ocTransfer.remotePath, OC_ACCOUNT_NAME) + + assertEquals(transferEntity.toModel(), actualResult) + + verify(exactly = 1) { + transferDao.getLastTransferWithRemotePathAndAccountName(ocTransfer.remotePath, OC_ACCOUNT_NAME) + } + } + + @Test(expected = Exception::class) + fun `getLastTransferFor returns an exception`() { + + every { + transferDao.getLastTransferWithRemotePathAndAccountName(ocTransfer.remotePath, OC_ACCOUNT_NAME) + } throws Exception() + + ocLocalTransferDataSource.getLastTransferFor(ocTransfer.remotePath, OC_ACCOUNT_NAME) + + } + + + @Test + fun `getCurrentAndPendingTransfers returns a list of OCTransfer`() { + + every { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_IN_PROGRESS.value, TransferStatus.TRANSFER_QUEUED.value)) + } returns listOf(transferEntity) + + val actualResult = ocLocalTransferDataSource.getCurrentAndPendingTransfers() + + assertEquals(listOf(transferEntity.toModel()), actualResult) + + verify(exactly = 1) { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_IN_PROGRESS.value, TransferStatus.TRANSFER_QUEUED.value)) + } + } + + @Test(expected = Exception::class) + fun `getCurrentAndPendingTransfers returns an exception when dao receive an exception`() { + + every { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_IN_PROGRESS.value, TransferStatus.TRANSFER_QUEUED.value)) + } throws Exception() + + ocLocalTransferDataSource.getCurrentAndPendingTransfers() + + } + + @Test + fun `getFailedTransfers returns a list of OCTransfer`() { + + every { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_FAILED.value)) + } returns listOf(transferEntity) + + val actualResult = ocLocalTransferDataSource.getFailedTransfers() + + assertEquals(listOf(transferEntity.toModel()), actualResult) + + verify(exactly = 1) { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_FAILED.value)) + } + } + + @Test(expected = Exception::class) + fun `getFailedTransfers returns an Exception when dao receive an exception`() { + + every { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_FAILED.value)) + } throws Exception() + + ocLocalTransferDataSource.getFailedTransfers() + + } + + @Test + fun `getFinishedTransfers returns a list of OCTransfer`() { + + every { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_SUCCEEDED.value)) + } returns listOf(transferEntity) + + val actualResult = ocLocalTransferDataSource.getFinishedTransfers() + + assertEquals(listOf(transferEntity.toModel()), actualResult) + + verify(exactly = 1) { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_SUCCEEDED.value)) + } + } + + @Test(expected = Exception::class) + fun `getFinishedTransfers returns an exception when dao receive an exception`() { + + every { + transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_SUCCEEDED.value)) + } throws Exception() + + ocLocalTransferDataSource.getFinishedTransfers() + + } + + @Test + fun `clearFailedTransfers returns unit`() { + + every { + transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_FAILED.value) + } returns Unit + + ocLocalTransferDataSource.clearFailedTransfers() + + verify(exactly = 1) { + transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_FAILED.value) + } + } + + @Test(expected = Exception::class) + fun `clearFailedTransfers returns an exception when dao receive an exception`() { + + every { + transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_FAILED.value) + } throws Exception() + + ocLocalTransferDataSource.clearFailedTransfers() + + } + + @Test + fun `clearSuccessfulTransfers returns unit`() { + + every { + transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) + } returns Unit + + ocLocalTransferDataSource.clearSuccessfulTransfers() + + verify(exactly = 1) { + transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) + } + } + + @Test(expected = Exception::class) + fun `clearSuccessfulTransfers returns an exception when dao receive an exception`() { + + every { + transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) + } throws Exception() + + ocLocalTransferDataSource.clearSuccessfulTransfers() + + } +} \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt index 15b6db7b98d..340d5e777c9 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt @@ -51,29 +51,73 @@ class OCLocalUserDataSourceTest { } @Test - fun getQuotaForAccount() { + fun `saveQuotaForAccount return Unit`() { + every { ocUserQuotaDao.insertOrReplace(any()) } returns Unit + + ocLocalUserDataSource.saveQuotaForAccount(OC_ACCOUNT_NAME, OC_USER_QUOTA) + + verify(exactly = 1) { + ocUserQuotaDao.insertOrReplace(userQuotaEntity) + } + } + + @Test(expected = Exception::class) + fun `saveQuotaForAccount returns an exception when dao receive an exception`() { + every { ocUserQuotaDao.insertOrReplace(any()) } throws Exception() + ocLocalUserDataSource.saveQuotaForAccount(OC_ACCOUNT_NAME, OC_USER_QUOTA) + + } + + @Test + fun `getQuotaForAccount returns a UserQuota`() { every { ocUserQuotaDao.getQuotaForAccount(any()) } returns userQuotaEntity val userQuota = ocLocalUserDataSource.getQuotaForAccount(OC_ACCOUNT_NAME) assertEquals(OC_USER_QUOTA, userQuota) + + verify(exactly = 1) { + ocUserQuotaDao.getQuotaForAccount(OC_ACCOUNT_NAME) + } } @Test - fun getQuotaForAccountNull() { + fun `getQuotaForAccount return null when dao receive null`() { every { ocUserQuotaDao.getQuotaForAccount(any()) } returns null val quotaEntity = ocLocalUserDataSource.getQuotaForAccount(OC_ACCOUNT_NAME) assertNull(quotaEntity) + + verify(exactly = 1) { + ocUserQuotaDao.getQuotaForAccount(OC_ACCOUNT_NAME) + } + } + + @Test(expected = Exception::class) + fun `getQuotaForAccount returns an exception when dao receive an exception`() { + every { ocUserQuotaDao.getQuotaForAccount(any()) } throws Exception() + + ocLocalUserDataSource.getQuotaForAccount(OC_ACCOUNT_NAME) + } @Test - fun insertQuota() { - every { ocUserQuotaDao.insertOrReplace(any()) } returns Unit + fun `deleteQuotaForAccount returns unit`() { + every { ocUserQuotaDao.deleteQuotaForAccount(any()) } returns Unit - ocLocalUserDataSource.saveQuotaForAccount(OC_ACCOUNT_NAME, OC_USER_QUOTA) + ocLocalUserDataSource.deleteQuotaForAccount(OC_ACCOUNT_NAME) + + verify(exactly = 1) { + ocUserQuotaDao.deleteQuotaForAccount(OC_ACCOUNT_NAME) + } + } + + @Test(expected = Exception::class) + fun `deleteQuotaForAccount returns an exception when dao receive an exception`() { + every { ocUserQuotaDao.deleteQuotaForAccount(any()) } throws Exception() + + ocLocalUserDataSource.deleteQuotaForAccount(OC_ACCOUNT_NAME) - verify(exactly = 1) { ocUserQuotaDao.insertOrReplace(userQuotaEntity) } } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt index fb8fcf2dcec..a88634a94f8 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt @@ -33,6 +33,7 @@ import com.owncloud.android.testutil.OC_USER_QUOTA import com.owncloud.android.utils.createRemoteOperationResultMock import io.mockk.every import io.mockk.mockk +import io.mockk.verify import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Before @@ -74,7 +75,7 @@ class OCRemoteUserDataSourceTest { } @Test - fun getUserInfoOk() { + fun `getUserInfo returns UserInfo`() { val getUserInfoResult: RemoteOperationResult = createRemoteOperationResultMock(data = remoteUserInfo, isSuccess = true) @@ -86,10 +87,12 @@ class OCRemoteUserDataSourceTest { assertNotNull(userInfo) assertEquals(OC_USER_INFO, userInfo) + + verify(exactly = 1) { ocUserService.getUserInfo() } } @Test(expected = Exception::class) - fun getUserInfoException() { + fun `getUserInfo returns an exception when service receive a exception`() { every { ocUserService.getUserInfo() @@ -99,7 +102,7 @@ class OCRemoteUserDataSourceTest { } @Test - fun getUserQuotaOk() { + fun `getUserQuota returns UserQuota`() { val getUserQuotaResult: RemoteOperationResult = createRemoteOperationResultMock(data = remoteQuota, isSuccess = true) @@ -111,10 +114,12 @@ class OCRemoteUserDataSourceTest { assertNotNull(userQuota) assertEquals(OC_USER_QUOTA, userQuota) + + verify(exactly = 1) { ocUserService.getUserQuota() } } @Test(expected = Exception::class) - fun getUserQuotaException() { + fun `getUserQuota returns an exception when service receive an exception`() { every { ocUserService.getUserQuota() } throws Exception() @@ -123,7 +128,7 @@ class OCRemoteUserDataSourceTest { } @Test - fun getUserAvatarOk() { + fun `getUserAvatar returns UserAvatar`() { val getUserAvatarResult: RemoteOperationResult = createRemoteOperationResultMock(data = remoteAvatar, isSuccess = true) @@ -135,10 +140,12 @@ class OCRemoteUserDataSourceTest { assertNotNull(userAvatar) assertEquals(OC_USER_AVATAR, userAvatar) + + verify(exactly = 1) { ocUserService.getUserAvatar(avatarDimension) } } @Test(expected = Exception::class) - fun getUserAvatarException() { + fun `getUserAvatar returns an exception when service receive exception`() { every { ocUserService.getUserAvatar(avatarDimension) } throws Exception() diff --git a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt new file mode 100644 index 00000000000..4f57757ed9c --- /dev/null +++ b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt @@ -0,0 +1,150 @@ +package com.owncloud.android.data.webfinger.datasource.implementation + +import com.owncloud.android.data.ClientManager +import com.owncloud.android.data.webfinger.datasources.implementation.OCRemoteWebFingerDatasource +import com.owncloud.android.domain.webfinger.model.WebFingerRel +import com.owncloud.android.lib.common.OwnCloudClient +import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.resources.webfinger.services.implementation.OCWebFingerService +import com.owncloud.android.testutil.OC_ACCESS_TOKEN +import com.owncloud.android.testutil.OC_ACCOUNT_ID +import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH +import com.owncloud.android.utils.createRemoteOperationResultMock +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify +import org.junit.Assert.assertEquals +import org.junit.Before +import org.junit.Test + +class OCRemoteWebFingerDatasourceTest { + + private lateinit var ocRemoteWebFingerDatasource: OCRemoteWebFingerDatasource + + private val clientManager: ClientManager = mockk(relaxed = true) + private val ownCloudClient: OwnCloudClient = mockk(relaxed = true) + private val ocWebFingerService: OCWebFingerService = mockk() + private val listString: List = mockk(relaxed = true) + + @Before + fun init() { + ocRemoteWebFingerDatasource = OCRemoteWebFingerDatasource( + ocWebFingerService, + clientManager, + ) + + every { clientManager.getClientForAnonymousCredentials(OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, false) } returns ownCloudClient + + } + + @Test + fun `getInstancesFromWebFinger returns a list of web finger`() { + + val getInstancesFromWebFingerResult: RemoteOperationResult> = + createRemoteOperationResultMock(data = listString, isSuccess = true) + + every { + ocWebFingerService.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, + ownCloudClient, + ) + } returns getInstancesFromWebFingerResult + + val actualResult = ocRemoteWebFingerDatasource.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + ) + + assertEquals(getInstancesFromWebFingerResult.data, actualResult) + + verify(exactly = 1) { + clientManager.getClientForAnonymousCredentials(any(), false) + ocWebFingerService.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, + ownCloudClient, + ) + } + } + + @Test(expected = Exception::class) + fun `getInstancesFromWebFinger returns an exception when service receive an exception`() { + + every { + ocWebFingerService.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, + any(), + ) + } throws Exception() + + ocRemoteWebFingerDatasource.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + ) + } + + @Test + fun `getInstancesFromAuthenticatedWebFinger returns a list of web finger`() { + + val getInstancesFromAuthenticatedWebFingerResult: RemoteOperationResult> = + createRemoteOperationResultMock(data = listString, isSuccess = true) + + every { + ocWebFingerService.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, + ownCloudClient, + ) + } returns getInstancesFromAuthenticatedWebFingerResult + + val actualResult = ocRemoteWebFingerDatasource.getInstancesFromAuthenticatedWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + username = OC_ACCOUNT_ID, + accessToken = OC_ACCESS_TOKEN + ) + + assertEquals(getInstancesFromAuthenticatedWebFingerResult.data, actualResult) + + verify(exactly = 1) { + clientManager.getClientForAnonymousCredentials(any(), false) + ocWebFingerService.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, + any(), + ) + } + } + + @Test(expected = Exception::class) + fun `getInstancesFromAuthenticatedWebFinger returns an exception when service receive an exception`() { + + every { + ocWebFingerService.getInstancesFromWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, + ownCloudClient, + ) + } throws Exception() + + ocRemoteWebFingerDatasource.getInstancesFromAuthenticatedWebFinger( + lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + rel = WebFingerRel.OIDC_ISSUER_DISCOVERY, + resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, + username = OC_ACCOUNT_ID, + accessToken = OC_ACCESS_TOKEN + ) + + } +} \ No newline at end of file From d12dea17b19c481f6408d51eb7b8700e9866cbe1 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 6 Sep 2023 14:24:21 +0100 Subject: [PATCH 09/20] Added calens --- changelog/unreleased/4143 | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 changelog/unreleased/4143 diff --git a/changelog/unreleased/4143 b/changelog/unreleased/4143 new file mode 100644 index 00000000000..cf0e9e2ab24 --- /dev/null +++ b/changelog/unreleased/4143 @@ -0,0 +1,9 @@ +Enhancement: Unit tests for datasources classes - Part 3 + + +Unit tests of the OCFolderBackupLocalDataSource, OCRemoteOAuthDataSource, OCRemoteShareeDataSource, OCLocalShareDataSource, +OCRemoteShareDataSource, OCLocalSpacesDataSource, OCRemoteSpacesDataSource, OCLocalTransferDataSource, OCLocalUserDataSource, +OCRemoteUserDataSource, OCRemoteWebFingerDatasource classes have been done and completed. + +https://github.com/owncloud/android/issues/4072 +https://github.com/owncloud/android/pull/4143 \ No newline at end of file From f24d613406bf7e7c9b97d2c655e612bec9ded013 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 6 Sep 2023 13:25:03 +0000 Subject: [PATCH 10/20] Calens changelog updated --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d66114c67ea..a119f42f93d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -117,6 +117,7 @@ Summary * Enhancement - Force security if not protected: [#4061](https://github.com/owncloud/android/issues/4061) * Enhancement - Prevent http traffic with branding options: [#4066](https://github.com/owncloud/android/issues/4066) * Enhancement - Unit tests for datasources classes - Part 2: [#4071](https://github.com/owncloud/android/issues/4071) +* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) * Enhancement - Respect app_providers_appsUrl value from capabilities: [#4075](https://github.com/owncloud/android/issues/4075) * Enhancement - Apply (1) to uploads' name conflicts: [#4079](https://github.com/owncloud/android/issues/4079) * Enhancement - Support "per app" language change on Android 13+: [#4082](https://github.com/owncloud/android/issues/4082) @@ -297,6 +298,17 @@ Details https://github.com/owncloud/android/issues/4071 https://github.com/owncloud/android/pull/4123 +* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) + + Unit tests of the OCFolderBackupLocalDataSource, OCRemoteOAuthDataSource, + OCRemoteShareeDataSource, OCLocalShareDataSource, OCRemoteShareDataSource, + OCLocalSpacesDataSource, OCRemoteSpacesDataSource, OCLocalTransferDataSource, + OCLocalUserDataSource, OCRemoteUserDataSource, OCRemoteWebFingerDatasource classes + have been done and completed. + + https://github.com/owncloud/android/issues/4072 + https://github.com/owncloud/android/pull/4143 + * Enhancement - Respect app_providers_appsUrl value from capabilities: [#4075](https://github.com/owncloud/android/issues/4075) Now, the app receives the app_providers_appsUrl from the local database. Before of this From b9f9a74b15c2e7bb7f6a2fc1d1091784b2b0939c Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Thu, 5 Oct 2023 10:45:54 +0100 Subject: [PATCH 11/20] Fix from CR --- changelog/unreleased/4143 | 3 +- .../sharees/ui/SearchShareesFragmentTest.kt | 2 +- .../OCLocalAuthenticationDataSourceTest.kt | 2 +- .../OCRemoteSpacesDataSource.kt | 89 +++--- .../data/transfers/db/OCTransferEntity.kt | 2 +- .../OCLocalAppRegistryDataSourceTest.kt | 28 +- .../OCRemoteAppRegistryDataSourceTest.kt | 20 +- .../OCLocalCapabilitiesDataSourceTest.kt | 3 +- .../OCRemoteCapabilitiesDataSourceTest.kt | 3 +- .../datasources/OCLocalFileDataSourceTest.kt | 52 ++-- .../datasources/OCRemoteFileDataSourceTest.kt | 3 +- .../OCFolderBackupLocalDataSourceTest.kt | 138 +++------- .../datasources/RemoteOAuthDataSourceTest.kt | 39 +-- .../OCRemoteServerInfoDataSourceTest.kt | 2 +- .../OCRemoteShareesDataSourceTest.kt | 111 +++++--- .../datasources/OCLocalShareDataSourceTest.kt | 174 +----------- .../OCRemoteShareDataSourceTest.kt | 157 +++++------ .../OCLocalSpacesDataSourceTest.kt | 254 +++-------------- .../OCRemoteSpacesDataSourceTest.kt | 68 ++--- .../OCLocalTransferDataSourceTest.kt | 260 ++++-------------- .../datasources/OCLocalUserDataSourceTest.kt | 42 ++- .../datasources/OCRemoteUserDataSourceTest.kt | 2 +- .../OCRemoteWebFingerDatasourceTest.kt | 65 ++--- owncloudTestUtil/build.gradle | 2 +- .../testutil/OCFolderBackUpConfiguration.kt | 12 + .../com/owncloud/android/testutil/OCSpace.kt | 72 +++++ 26 files changed, 558 insertions(+), 1047 deletions(-) diff --git a/changelog/unreleased/4143 b/changelog/unreleased/4143 index cf0e9e2ab24..30b6577074e 100644 --- a/changelog/unreleased/4143 +++ b/changelog/unreleased/4143 @@ -1,9 +1,8 @@ Enhancement: Unit tests for datasources classes - Part 3 - Unit tests of the OCFolderBackupLocalDataSource, OCRemoteOAuthDataSource, OCRemoteShareeDataSource, OCLocalShareDataSource, OCRemoteShareDataSource, OCLocalSpacesDataSource, OCRemoteSpacesDataSource, OCLocalTransferDataSource, OCLocalUserDataSource, OCRemoteUserDataSource, OCRemoteWebFingerDatasource classes have been done and completed. https://github.com/owncloud/android/issues/4072 -https://github.com/owncloud/android/pull/4143 \ No newline at end of file +https://github.com/owncloud/android/pull/4143 diff --git a/owncloudApp/src/androidTest/java/com/owncloud/android/sharing/sharees/ui/SearchShareesFragmentTest.kt b/owncloudApp/src/androidTest/java/com/owncloud/android/sharing/sharees/ui/SearchShareesFragmentTest.kt index 59f3f46f890..c5384d97231 100644 --- a/owncloudApp/src/androidTest/java/com/owncloud/android/sharing/sharees/ui/SearchShareesFragmentTest.kt +++ b/owncloudApp/src/androidTest/java/com/owncloud/android/sharing/sharees/ui/SearchShareesFragmentTest.kt @@ -54,7 +54,7 @@ class SearchShareesFragmentTest { private val sharesLiveData = MutableLiveData>>>() @Before - fun init() { + fun setUp() { every { shareViewModel.shares } returns sharesLiveData stopKoin() diff --git a/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt b/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt index a401c1a0475..8b0a44b594a 100644 --- a/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt +++ b/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt @@ -77,7 +77,7 @@ class OCLocalAuthenticationDataSourceTest { private val preferencesProvider = spyk() @Before - fun init() { + fun setUp() { val context = InstrumentationRegistry.getInstrumentation().targetContext ocLocalAuthenticationDataSource = OCLocalAuthenticationDataSource( diff --git a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt index 5fa0441fb20..11f8a2b37d0 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/spaces/datasources/implementation/OCRemoteSpacesDataSource.kt @@ -46,51 +46,50 @@ class OCRemoteSpacesDataSource( companion object { - - @VisibleForTesting - fun SpaceResponse.toModel(accountName: String): OCSpace = - OCSpace( - accountName = accountName, - driveAlias = driveAlias, - driveType = driveType, - id = id, - lastModifiedDateTime = lastModifiedDateTime, - name = name, - owner = owner?.let { ownerResponse -> - SpaceOwner( - user = SpaceUser( - id = ownerResponse.user.id + @VisibleForTesting + fun SpaceResponse.toModel(accountName: String): OCSpace = + OCSpace( + accountName = accountName, + driveAlias = driveAlias, + driveType = driveType, + id = id, + lastModifiedDateTime = lastModifiedDateTime, + name = name, + owner = owner?.let { ownerResponse -> + SpaceOwner( + user = SpaceUser( + id = ownerResponse.user.id + ) + ) + }, + quota = quota?.let { quotaResponse -> + SpaceQuota( + remaining = quotaResponse.remaining, + state = quotaResponse.state, + total = quotaResponse.total, + used = quotaResponse.used, + ) + }, + root = SpaceRoot( + eTag = root.eTag, + id = root.id, + webDavUrl = root.webDavUrl, + deleted = root.deleted?.let { SpaceDeleted(state = it.state) } + ), + webUrl = webUrl, + description = description, + special = special?.map { specialResponse -> + SpaceSpecial( + eTag = specialResponse.eTag, + file = SpaceFile(mimeType = specialResponse.file.mimeType), + id = specialResponse.id, + lastModifiedDateTime = specialResponse.lastModifiedDateTime, + name = specialResponse.name, + size = specialResponse.size, + specialFolder = SpaceSpecialFolder(name = specialResponse.specialFolder.name), + webDavUrl = specialResponse.webDavUrl ) - ) - }, - quota = quota?.let { quotaResponse -> - SpaceQuota( - remaining = quotaResponse.remaining, - state = quotaResponse.state, - total = quotaResponse.total, - used = quotaResponse.used, - ) - }, - root = SpaceRoot( - eTag = root.eTag, - id = root.id, - webDavUrl = root.webDavUrl, - deleted = root.deleted?.let { SpaceDeleted(state = it.state) } - ), - webUrl = webUrl, - description = description, - special = special?.map { specialResponse -> - SpaceSpecial( - eTag = specialResponse.eTag, - file = SpaceFile(mimeType = specialResponse.file.mimeType), - id = specialResponse.id, - lastModifiedDateTime = specialResponse.lastModifiedDateTime, - name = specialResponse.name, - size = specialResponse.size, - specialFolder = SpaceSpecialFolder(name = specialResponse.specialFolder.name), - webDavUrl = specialResponse.webDavUrl - ) - } - ) + } + ) } } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt b/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt index 32d3da8f56e..c5dab107ca3 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt @@ -46,7 +46,7 @@ data class OCTransferEntity( val remotePath: String, val accountName: String, val fileSize: Long, - val status: Int, + var status: Int, val localBehaviour: Int, val forceOverwrite: Boolean, val transferEndTimestamp: Long? = null, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt index bc28f2cbbe1..8c381895875 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt @@ -1,3 +1,22 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.owncloud.android.data.appRegistry.datasources.implementation import androidx.arch.core.executor.testing.InstantTaskExecutorRule @@ -16,6 +35,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Assert +import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Rule import org.junit.Test @@ -42,7 +62,7 @@ class OCLocalAppRegistryDataSourceTest { val instantExecutorRule = InstantTaskExecutorRule() @Before - fun init() { + fun setUp() { val db = mockkClass(OwncloudDatabase::class) @@ -64,7 +84,7 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryForMimeTypeAsStream(OC_ACCOUNT_NAME, mimetype) appRegistry.collect { appRegistryEmitted -> - Assert.assertEquals(OC_APP_REGISTRY_MIMETYPE, appRegistryEmitted) + assertEquals(OC_APP_REGISTRY_MIMETYPE, appRegistryEmitted) } verify(exactly = 1) { appRegistryDao.getAppRegistryForMimeType(OC_ACCOUNT_NAME, mimetype) } @@ -104,7 +124,7 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) appRegistry.collect { appRegistryEmitted -> - Assert.assertEquals(listOf(OC_APP_REGISTRY_MIMETYPE), appRegistryEmitted) + assertEquals(listOf(OC_APP_REGISTRY_MIMETYPE), appRegistryEmitted) } verify(exactly = 1) { appRegistryDao.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) } @@ -118,7 +138,7 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) appRegistry.collect { listEmitted -> - Assert.assertEquals(emptyList(), listEmitted) + assertEquals(emptyList(), listEmitted) } verify(exactly = 1) { appRegistryDao.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt index c01ab18e280..1890d7a70d4 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt @@ -1,4 +1,22 @@ package com.owncloud.android.data.appRegistry.datasources.implementation +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ import com.owncloud.android.data.ClientManager import com.owncloud.android.data.appregistry.datasources.implementation.OCRemoteAppRegistryDataSource @@ -29,7 +47,7 @@ class OCRemoteAppRegistryDataSourceTest { private val appName = "TestApp" @Before - fun init() { + fun setUp() { every { clientManager.getAppRegistryService(any()) } returns ocAppRegistryService ocRemoteAppRegistryDataSource = OCRemoteAppRegistryDataSource(clientManager) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt index e6c2608bd93..7ed7188b798 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt @@ -3,6 +3,7 @@ * * @author David González Verdugo * @author Abel García de Prada + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -51,7 +52,7 @@ class OCLocalCapabilitiesDataSourceTest { var rule: TestRule = InstantTaskExecutorRule() @Before - fun init() { + fun setUp() { ocLocalCapabilitiesDataSource = OCLocalCapabilitiesDataSource( ocCapabilityDao, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt index 732a81f90a5..c8ec2589ddc 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt @@ -3,6 +3,7 @@ * * @author David González Verdugo * @author Jesús Recio + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -43,7 +44,7 @@ class OCRemoteCapabilitiesDataSourceTest { private val remoteCapabilityMapper = RemoteCapabilityMapper() @Before - fun init() { + fun setUp() { every { clientManager.getCapabilityService(any()) } returns ocCapabilityService ocRemoteCapabilitiesDataSource = diff --git a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt index e7167c66cb1..707786b1d50 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt @@ -2,6 +2,7 @@ * ownCloud Android client application * * @author Abel García de Prada + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -40,6 +41,7 @@ import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals @@ -65,7 +67,7 @@ class OCLocalFileDataSourceTest { ) @Before - fun init() { + fun setUp() { dao = spyk() localDataSource = OCLocalFileDataSource(dao) } @@ -103,11 +105,9 @@ class OCLocalFileDataSourceTest { fun `getFileByIdAsFlow returns a flow of OCFile`() = runTest { every { dao.getFileByIdAsFlow(any()) } returns flowOf(DUMMY_FILE_ENTITY) - val result = localDataSource.getFileByIdAsFlow(OC_FILE.id!!) + val resultActual = localDataSource.getFileByIdAsFlow(OC_FILE.id!!).first() - result.collect { result -> - assertEquals(OC_FILE, result) - } + assertEquals(OC_FILE, resultActual) verify(exactly = 1) { dao.getFileByIdAsFlow(OC_FILE.id!!) } } @@ -116,11 +116,9 @@ class OCLocalFileDataSourceTest { fun `getFileByIdAsFlow returns null`() = runTest { every { dao.getFileByIdAsFlow(any()) } returns flowOf(null) - val result = localDataSource.getFileByIdAsFlow(DUMMY_FILE_ENTITY.id) + val result = localDataSource.getFileByIdAsFlow(DUMMY_FILE_ENTITY.id).first() - result.collect { result -> - assertNull(result) - } + assertNull(result) verify(exactly = 1) { dao.getFileByIdAsFlow(DUMMY_FILE_ENTITY.id) } } @@ -137,11 +135,9 @@ class OCLocalFileDataSourceTest { every { dao.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } returns flowOf(ocFileAndFileSync) - val result = localDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + val result = localDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!).first() - result.collect { emittedFileWithSyncInfo -> - assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, emittedFileWithSyncInfo) - } + assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, result) verify(exactly = 1) { dao.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } } @@ -151,11 +147,9 @@ class OCLocalFileDataSourceTest { every { dao.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } returns flowOf(null) - val result = localDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + val result = localDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!).first() - result.collect { emittedFileWithSyncInfo -> - assertNull(emittedFileWithSyncInfo) - } + assertNull(result) verify(exactly = 1) { dao.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } } @@ -165,11 +159,9 @@ class OCLocalFileDataSourceTest { every { dao.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } throws Exception() - val result = localDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) + val result = localDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!).first() - result.collect { emittedFileWithSyncInfo -> - assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, emittedFileWithSyncInfo) - } + assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, result) verify(exactly = 1) { dao.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } } @@ -349,11 +341,9 @@ class OCLocalFileDataSourceTest { every { dao.getFolderContentWithSyncInfoAsFlow(any()) } returns flowOf(listOf(ocFileAndFileSync)) - val result = localDataSource.getFolderContentWithSyncInfoAsFlow(OC_FILE.id!!) + val result = localDataSource.getFolderContentWithSyncInfoAsFlow(OC_FILE.id!!).first() - result.collect { result -> - assertEquals(listOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE), result) - } + assertEquals(listOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE), result) verify(exactly = 1) { dao.getFolderContentWithSyncInfoAsFlow(OC_FILE.id!!) @@ -393,11 +383,9 @@ class OCLocalFileDataSourceTest { fun `getSharedByLinkWithSyncInfoForAccountAsFlow returns a flow of list of OCFileWithSyncInfo`() = runTest { every { dao.getFilesWithSyncInfoSharedByLinkAsFlow(any()) } returns flowOf(listOf(ocFileAndFileSync)) - val result = localDataSource.getSharedByLinkWithSyncInfoForAccountAsFlow(DUMMY_FILE_ENTITY.owner) + val result = localDataSource.getSharedByLinkWithSyncInfoForAccountAsFlow(DUMMY_FILE_ENTITY.owner).first() - result.collect { result -> - assertEquals(listOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE), result) - } + assertEquals(listOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE), result) verify(exactly = 1) { dao.getFilesWithSyncInfoSharedByLinkAsFlow(DUMMY_FILE_ENTITY.owner) @@ -417,11 +405,9 @@ class OCLocalFileDataSourceTest { fun `getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow returns a flow of list of OCFileWithSyncInfo`() = runTest { every { dao.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(any()) } returns flowOf(listOf(ocFileAndFileSync)) - val result = localDataSource.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(DUMMY_FILE_ENTITY.owner) + val result = localDataSource.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(DUMMY_FILE_ENTITY.owner).first() - result.collect { result -> - assertEquals(listOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE), result) - } + assertEquals(listOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE), result) verify(exactly = 1) { dao.getFilesWithSyncInfoAvailableOfflineFromAccountAsFlow(DUMMY_FILE_ENTITY.owner) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt index 11e6c8a7f31..7ff69ccca95 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt @@ -2,6 +2,7 @@ * ownCloud Android client application * * @author Abel García de Prada + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -82,7 +83,7 @@ class OCRemoteFileDataSourceTest { ) @Before - fun init() { + fun setUp() { every { clientManager.getFileService(any()) } returns ocFileService ocRemoteFileDataSource = OCRemoteFileDataSource(clientManager) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt index c18d73b7920..6d10a980b05 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt @@ -1,17 +1,36 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * + * Copyright (C) 2023 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.owncloud.android.data.folderbackup.datasources.implementation -import com.owncloud.android.data.OwncloudDatabase import com.owncloud.android.data.folderbackup.datasources.implementation.OCFolderBackupLocalDataSource.Companion.toModel -import com.owncloud.android.data.folderbackup.db.FolderBackUpEntity import com.owncloud.android.data.folderbackup.db.FolderBackupDao import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration -import com.owncloud.android.domain.camerauploads.model.UploadBehavior -import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import com.owncloud.android.testutil.OC_BACKUP +import com.owncloud.android.testutil.OC_BACKUP_ENTITY import io.mockk.every -import io.mockk.mockkClass +import io.mockk.mockk import io.mockk.verify import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertNull +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking import org.junit.Before @@ -20,47 +39,22 @@ import org.junit.Test class OCFolderBackupLocalDataSourceTest { private lateinit var ocFolderBackupLocalDataSource: OCFolderBackupLocalDataSource - private val folderBackupDao = mockkClass(FolderBackupDao::class) - private val db = mockkClass(OwncloudDatabase::class) - - private val ocFolderBackUpEntity = FolderBackUpEntity( - accountName = OC_ACCOUNT_NAME, - behavior = UploadBehavior.COPY.name, - sourcePath = "/Photos", - uploadPath = "/Photos", - wifiOnly = true, - chargingOnly = true, - lastSyncTimestamp = 1542628397, - name = "" - ) - private val ocFolderBackUpConfiguration = FolderBackUpConfiguration( - accountName = OC_ACCOUNT_NAME, - behavior = UploadBehavior.COPY, - sourcePath = "/Photos", - uploadPath = "/Photos", - wifiOnly = true, - chargingOnly = true, - lastSyncTimestamp = 1542628397, - name = "" - ) + private val folderBackupDao = mockk(relaxed = true) @Before - fun init() { - - every { db.folderBackUpDao() } returns folderBackupDao - + fun setUp() { ocFolderBackupLocalDataSource = OCFolderBackupLocalDataSource(folderBackupDao) } @Test - fun `getCameraUploadsConfiguration with valid configurations returns a CameraUploadsConfiguration object`() { - every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns ocFolderBackUpEntity - every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns ocFolderBackUpEntity + fun `getCameraUploadsConfiguration returns a CameraUploadsConfiguration when having valid configurations`() { + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns OC_BACKUP_ENTITY + every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns OC_BACKUP_ENTITY val resultCurrent = ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() - assertEquals(ocFolderBackUpEntity.toModel(), resultCurrent?.pictureUploadsConfiguration) - assertEquals(ocFolderBackUpEntity.toModel(), resultCurrent?.videoUploadsConfiguration) + assertEquals(OC_BACKUP_ENTITY.toModel(), resultCurrent?.pictureUploadsConfiguration) + assertEquals(OC_BACKUP_ENTITY.toModel(), resultCurrent?.videoUploadsConfiguration) verify(exactly = 1) { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) @@ -68,17 +62,8 @@ class OCFolderBackupLocalDataSourceTest { } } - @Test(expected = Exception::class) - fun `getCameraUploadsConfiguration with valid configurations returns an exception when service receive an exception`() { - every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() - every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } throws Exception() - - ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() - - } - @Test - fun `getCameraUploadsConfiguration with no configurations returns null`() { + fun `getCameraUploadsConfiguration returns null when there are not configurations `() { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns null every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns null @@ -92,78 +77,37 @@ class OCFolderBackupLocalDataSourceTest { } } - @Test(expected = Exception::class) - fun `getCameraUploadsConfiguration with no configurations returns an exception when service receive an exception`() { - every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() - every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } throws Exception() - - ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() - - } - @Test - fun `getFolderBackupConfigurationByNameAsFlow with valid configurations returns a flow of CameraUploadsConfiguration`() = runBlocking { + fun `getFolderBackupConfigurationByNameAsFlow returns a flow of CameraUploadsConfiguration when having valid configurations `() = runBlocking { every { folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) } returns flowOf( - ocFolderBackUpEntity + OC_BACKUP_ENTITY ) val resultCurrent = ocFolderBackupLocalDataSource.getFolderBackupConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) - resultCurrent.collect { result -> - assertEquals(ocFolderBackUpEntity.toModel(), result) - } + val result = resultCurrent.first() + assertEquals(OC_BACKUP_ENTITY.toModel(), result) + verify(exactly = 1) { folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) } } - @Test(expected = Exception::class) - fun `getFolderBackupConfigurationByNameAsFlow when dao receive an exception returns an exception`() = runBlocking { - every { folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) } throws Exception() - - val resultCurrent = ocFolderBackupLocalDataSource.getFolderBackupConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) - - resultCurrent.collect { result -> - assertEquals(ocFolderBackUpEntity.toModel(), result) - } - } - @Test - fun `saveFolderBackupConfiguration with valid configurations returns unit and save the information`() { - every { folderBackupDao.update(ocFolderBackUpEntity) } returns 1 - - ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(ocFolderBackUpConfiguration) + fun `saveFolderBackupConfiguration with valid configurations save the information`() { + ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(OC_BACKUP) verify(exactly = 1) { - folderBackupDao.update(ocFolderBackUpEntity) + folderBackupDao.update(OC_BACKUP_ENTITY) } } - @Test(expected = Exception::class) - fun `saveFolderBackupConfiguration when dao receive an exception returns an exception`() { - every { folderBackupDao.update(ocFolderBackUpEntity) } throws Exception() - - ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(ocFolderBackUpConfiguration) - - } - @Test - fun `resetFolderBackupConfigurationByName when folder backup configuration is reset by name returns unit `() { - every { folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) } returns 1 - + fun `resetFolderBackupConfigurationByName when folder backup configuration is reset by name`() { ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) verify(exactly = 1) { folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) } } - - @Test(expected = Exception::class) - fun `resetFolderBackupConfigurationByName when dao receive an exception returns an exception `() { - every { folderBackupDao.delete(any()) } throws Exception() - - ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) - - } - } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt index b8582022f8b..efac83b6f79 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt @@ -20,10 +20,8 @@ package com.owncloud.android.data.oauth.datasources import com.owncloud.android.data.ClientManager -import com.owncloud.android.data.oauth.OC_REMOTE_CLIENT_REGISTRATION_PARAMS import com.owncloud.android.data.oauth.OC_REMOTE_CLIENT_REGISTRATION_RESPONSE import com.owncloud.android.data.oauth.OC_REMOTE_OIDC_DISCOVERY_RESPONSE -import com.owncloud.android.data.oauth.OC_REMOTE_TOKEN_REQUEST_PARAMS_ACCESS import com.owncloud.android.data.oauth.OC_REMOTE_TOKEN_RESPONSE import com.owncloud.android.data.oauth.datasources.implementation.OCRemoteOAuthDataSource import com.owncloud.android.lib.common.OwnCloudClient @@ -56,7 +54,7 @@ class RemoteOAuthDataSourceTest { private val oidcService: OIDCService = mockk() @Before - fun init() { + fun setUp() { every { clientManager.getClientForAnonymousCredentials(any(), any()) } returns ocClientMocked remoteOAuthDataSource = OCRemoteOAuthDataSource( @@ -66,7 +64,7 @@ class RemoteOAuthDataSourceTest { } @Test - fun `performOIDCDiscovery returns a object of OIDCServerConfiguration`() { + fun `performOIDCDiscovery returns a OIDCServerConfiguration`() { val oidcDiscoveryResult: RemoteOperationResult = createRemoteOperationResultMock(data = OC_REMOTE_OIDC_DISCOVERY_RESPONSE, isSuccess = true) @@ -85,15 +83,6 @@ class RemoteOAuthDataSourceTest { } } - @Test(expected = Exception::class) - fun `performOIDCDiscovery returns an exception when service receive an exception`() { - every { - oidcService.getOIDCServerDiscovery(ocClientMocked) - } throws Exception() - - remoteOAuthDataSource.performOIDCDiscovery(OC_SECURE_BASE_URL) - } - @Test fun `performTokenRequest returns a TokenResponse`() { val tokenResponseResult: RemoteOperationResult = @@ -109,22 +98,13 @@ class RemoteOAuthDataSourceTest { assertEquals(OC_TOKEN_RESPONSE, tokenResponse) verify(exactly = 1) { - clientManager.getClientForAnonymousCredentials(OC_SECURE_BASE_URL, false) + clientManager.getClientForAnonymousCredentials(OC_SECURE_BASE_URL, any()) oidcService.performTokenRequest(ocClientMocked, any()) } } - @Test(expected = Exception::class) - fun `performTokenRequest returns an exception when service receive an exception`() { - every { - oidcService.performTokenRequest(ocClientMocked, OC_REMOTE_TOKEN_REQUEST_PARAMS_ACCESS) - } throws Exception() - - remoteOAuthDataSource.performTokenRequest(OC_TOKEN_REQUEST_ACCESS) - } - @Test - fun `registerClient returns a ClientRegistrationInfo object`() { + fun `registerClient returns a ClientRegistrationInfo`() { val clientRegistrationResponse: RemoteOperationResult = createRemoteOperationResultMock(data = OC_REMOTE_CLIENT_REGISTRATION_RESPONSE, isSuccess = true) @@ -138,17 +118,8 @@ class RemoteOAuthDataSourceTest { assertEquals(OC_CLIENT_REGISTRATION, clientRegistrationInfo) verify(exactly = 1) { - clientManager.getClientForAnonymousCredentials(any(), false) + clientManager.getClientForAnonymousCredentials(OC_CLIENT_REGISTRATION_REQUEST.registrationEndpoint, any()) oidcService.registerClientWithRegistrationEndpoint(ocClientMocked, any()) } } - - @Test(expected = Exception::class) - fun `registerClient returns an exception when service receive an exception`() { - every { - oidcService.registerClientWithRegistrationEndpoint(ocClientMocked, OC_REMOTE_CLIENT_REGISTRATION_PARAMS) - } throws Exception() - - remoteOAuthDataSource.registerClient(OC_CLIENT_REGISTRATION_REQUEST) - } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/server/datasources/implementation/OCRemoteServerInfoDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/server/datasources/implementation/OCRemoteServerInfoDataSourceTest.kt index bfaefb85204..f0b9d7419ed 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/server/datasources/implementation/OCRemoteServerInfoDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/server/datasources/implementation/OCRemoteServerInfoDataSourceTest.kt @@ -67,7 +67,7 @@ class OCRemoteServerInfoDataSourceTest { private val authHeaderBearer = listOf(basicAuthHeader, bearerHeader) @Before - fun init() { + fun setUp() { ocRemoteServerInfoDatasource = OCRemoteServerInfoDataSource(ocServerInfoService, clientManager) every { clientManager.getClientForAnonymousCredentials(any(), any()) } returns ocClientMocked } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt index e11a63376fa..39e0a2eb00c 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt @@ -2,6 +2,7 @@ * ownCloud Android client application * * @author David González Verdugo + * @author David González Verdugo * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -48,7 +49,7 @@ class OCRemoteShareesDataSourceTest { private lateinit var sharees: List @Before - fun init() { + fun setUp() { every { clientManager.getShareeService(any()) } returns ocShareeService ocRemoteShareesDataSource = OCRemoteShareeDataSource(clientManager, RemoteShareeMapper()) @@ -59,30 +60,39 @@ class OCRemoteShareesDataSourceTest { ) every { - ocShareeService.getSharees("user", 1, 30) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } returns getRemoteShareesOperationResult // Get sharees from remote datasource + + } + + @Test + fun `getSharees returns a list with the sharees entered as remote sharees`() { sharees = ocRemoteShareesDataSource.getSharees( "user", 1, 30, OC_ACCOUNT_NAME, ) - } - - @Test - fun `getSharees contains sharees entered as remote sharees returns a list of OCSharee`() { assertNotNull(sharees) assertEquals(5, sharees.size) verify(exactly = 1) { - ocShareeService.getSharees("user", 1, 30,) + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees contains exact user match returns a list of OCSharee`() { + fun `getSharees returns a list of OCSharee when contains exact user match`() { + sharees = ocRemoteShareesDataSource.getSharees( + "user", + 1, + 30, + OC_ACCOUNT_NAME, + ) + val sharee = sharees[0] assertEquals(sharee.label, "User") assertEquals(sharee.shareType, ShareType.USER) @@ -91,12 +101,20 @@ class OCRemoteShareesDataSourceTest { assertTrue(sharee.isExactMatch) verify(exactly = 1) { - ocShareeService.getSharees("user", 1, 30,) + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees contains one user not exactly matched returns a list of OCSharee`() { + fun `getSharees returns a list of OCSharee contains one user not exactly matched`() { + sharees = ocRemoteShareesDataSource.getSharees( + "user", + 1, + 30, + OC_ACCOUNT_NAME, + ) + val sharee = sharees[1] assertEquals("User 1", sharee.label) assertEquals(ShareType.USER, sharee.shareType) @@ -105,12 +123,19 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - ocShareeService.getSharees("user", 1, 30,) + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees contains one user without additional info returns a list of OCSharee`() { + fun `getSharees returns a list of OCSharee when contains one user without additional info`() { + sharees = ocRemoteShareesDataSource.getSharees( + "user", + 1, + 30, + OC_ACCOUNT_NAME, + ) val sharee = sharees[2] assertEquals("User 2", sharee.label) assertEquals(ShareType.USER, sharee.shareType) @@ -119,12 +144,19 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - ocShareeService.getSharees("user", 1, 30,) + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees contains one remote user returns a list of OCSharee`() { + fun `getSharees returns a list of OCSharee when contains one remote user`() { + sharees = ocRemoteShareesDataSource.getSharees( + "user", + 1, + 30, + OC_ACCOUNT_NAME, + ) val sharee = sharees[3] assertEquals("Remoteuser 1", sharee.label) assertEquals(ShareType.FEDERATED, sharee.shareType) @@ -133,12 +165,20 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - ocShareeService.getSharees("user", 1, 30,) + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees contains one group returns a list of OCSharee`() { + fun `getSharees returns a list of OCSharee when contains one group`() { + sharees = ocRemoteShareesDataSource.getSharees( + "user", + 1, + 30, + OC_ACCOUNT_NAME, + ) + val sharee = sharees[4] assertEquals("Group 1", sharee.label) assertEquals(ShareType.GROUP, sharee.shareType) @@ -147,50 +187,35 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - ocShareeService.getSharees("user", 1, 30,) + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees handle empty response returns a list of OCSharee`() { + fun `getSharees returns a list of OCSharee when handle empty response`() { + val getRemoteShareesOperationResult = createRemoteOperationResultMock( EMPTY_REMOTE_SHAREES, true ) - every { - ocShareeService.getSharees("user", 1, 30) + every { + ocShareeService.getSharees( searchString = "user2", page = 2, perPage = 32) } returns getRemoteShareesOperationResult - // Get sharees from remote datasource val emptySharees = ocRemoteShareesDataSource.getSharees( - "user", - 1, - 30, + "user2", + 2, + 32, OC_ACCOUNT_NAME, ) assertTrue(emptySharees.isEmpty()) - verify(exactly = 2) { - ocShareeService.getSharees("user", 1, 30,) - } - } - - @Test(expected = Exception::class) - fun `getSharees returns an exception when service receive an exception`() { - every { - ocShareeService.getSharees("user", 1, 30) - } throws Exception() - - ocRemoteShareesDataSource.getSharees( - "user", - 1, - 30, - OC_ACCOUNT_NAME, - ) - verify(exactly = 2) { - ocShareeService.getSharees("user", 1, 30,) + verify(exactly = 1) { + clientManager.getShareeService(any()) + ocShareeService.getSharees( searchString = "user2", page = 2, perPage = 32) } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index 59d6652255d..06261ad783f 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -2,6 +2,7 @@ * ownCloud Android client application * * @author David González Verdugo + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -21,7 +22,6 @@ package com.owncloud.android.data.shares.datasources import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.lifecycle.MutableLiveData -import com.owncloud.android.data.OwncloudDatabase import com.owncloud.android.data.sharing.shares.datasources.implementation.OCLocalShareDataSource import com.owncloud.android.data.sharing.shares.datasources.implementation.OCLocalShareDataSource.Companion.toEntity import com.owncloud.android.data.sharing.shares.datasources.implementation.OCLocalShareDataSource.Companion.toModel @@ -34,7 +34,7 @@ import com.owncloud.android.testutil.OC_PUBLIC_SHARE import com.owncloud.android.testutil.OC_SHARE import com.owncloud.android.testutil.livedata.getLastEmittedValue import io.mockk.every -import io.mockk.mockkClass +import io.mockk.mockk import io.mockk.verify import org.junit.Assert.assertEquals import org.junit.Before @@ -43,19 +43,14 @@ import org.junit.Test class OCLocalShareDataSourceTest { private lateinit var ocLocalSharesDataSource: OCLocalShareDataSource - private val ocSharesDao = mockkClass(OCShareDao::class) + private val ocSharesDao = mockk(relaxUnitFun = true) @Rule @JvmField val instantExecutorRule = InstantTaskExecutorRule() @Before - fun init() { - val db = mockkClass(OwncloudDatabase::class) - - every { - db.shareDao() - } returns ocSharesDao + fun setUp() { ocLocalSharesDataSource = OCLocalShareDataSource( @@ -83,7 +78,7 @@ class OCLocalShareDataSourceTest { private val privateShareTypes = listOf(ShareType.USER, ShareType.GROUP, ShareType.FEDERATED) @Test - fun `getSharesAsLiveData read local private shares returns a list of LiveData OCShare`() { + fun `getSharesAsLiveData returns a list of LiveData OCShare when read local private shares`() { val privateSharesAsLiveData: MutableLiveData> = MutableLiveData() privateSharesAsLiveData.value = privateShares @@ -119,21 +114,6 @@ class OCLocalShareDataSourceTest { } } - @Test(expected = Exception::class) - fun `getSharesAsLiveData read local private shares returns an exception when dao receive an exception`() { - every { - ocSharesDao.getSharesAsLiveData( - "/Docs/doc1.doc", - "admin@server", - privateShareTypes.map { it.value }) - } throws Exception() - - ocLocalSharesDataSource.getSharesAsLiveData( - "/Docs/doc1.doc", "admin@server", privateShareTypes - ).getLastEmittedValue()!! - - } - @Test fun `getSharesAsLiveData read local private share returns a OCShare`() { val privateShareAsLiveData: MutableLiveData = MutableLiveData() @@ -151,15 +131,6 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.getShareAsLiveData(OC_SHARE.remoteId) } } - @Test(expected = Exception::class) - fun `getSharesAsLiveData read local private share returns an exception when dao receive an exception`() { - - every { ocSharesDao.getShareAsLiveData(OC_SHARE.remoteId) } throws Exception() - - ocLocalSharesDataSource.getShareAsLiveData(OC_SHARE.remoteId).getLastEmittedValue()!! - - } - @Test fun `insert private OCShare into repository returns a long`() { every { ocSharesDao.insertOrReplace(privateShares[0]) } returns 10 @@ -176,20 +147,6 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(privateShares[0]) } } - @Test(expected = Exception::class) - fun `insert private OCShare into repository returns an exception when dao receive an exception`() { - every { ocSharesDao.insertOrReplace(privateShares[0]) } throws Exception() - - ocLocalSharesDataSource.insert( - OC_PRIVATE_SHARE.copy( - path = "/Docs/doc1.doc", - shareWith = "username", - sharedWithDisplayName = "Sophie" - ) - ) - } - - @Test fun `insert list of private OCShares into repository returns a list of long`() { @@ -205,18 +162,8 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(privateShares) } } - @Test(expected = Exception::class) - fun `insert list of private OCShares into repository returns an exception when dao receive an exception`() { - - every { ocSharesDao.insertOrReplace(privateShares) } throws Exception() - - ocLocalSharesDataSource.insert( - privateShares.map { it.toModel() } - ) - } - @Test - fun `update private OCShare and returns a long`() { + fun `update private OCShare returns a long`() { every { ocSharesDao.update(privateShares[1]) } returns 3 val updatedShareId = ocLocalSharesDataSource.update( @@ -231,19 +178,6 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.update(privateShares[1]) } } - @Test(expected = Exception::class) - fun `update private OCShare and returns returns an exception when dao receive an exception`() { - every { ocSharesDao.update(privateShares[1]) } throws Exception() - - ocLocalSharesDataSource.update( - OC_PRIVATE_SHARE.copy( - path = "/Docs/doc1.doc", - shareWith = "user.name", - sharedWithDisplayName = "Nicole" - ) - ) - } - /****************************************************************************************************** ******************************************* PUBLIC SHARES ******************************************** ******************************************************************************************************/ @@ -302,23 +236,6 @@ class OCLocalShareDataSourceTest { } } - @Test(expected = Exception::class) - fun `getSharesAsLiveData read local public shares returns an exception when dao receive an exception`() { - every { - ocSharesDao.getSharesAsLiveData( - "/Photos/", - "admin@server", - listOf(ShareType.PUBLIC_LINK.value) - ) - } throws Exception() - - ocLocalSharesDataSource.getSharesAsLiveData( - "/Photos/", - "admin@server", - listOf(ShareType.PUBLIC_LINK) - ).getLastEmittedValue()!! - } - @Test fun `insert public OCShare into repository returns a long`() { every { ocSharesDao.insertOrReplace(publicShares[0]) } returns 7 @@ -336,20 +253,6 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(publicShares[0]) } } - @Test(expected = Exception::class) - fun `insert public OCShare into repository returns an exception when dao receive an exception`() { - every { ocSharesDao.insertOrReplace(publicShares[0]) } throws Exception() - - ocLocalSharesDataSource.insert( - OC_PUBLIC_SHARE.copy( - path = "/Photos/", - isFolder = true, - name = "Photos link", - shareLink = "http://server:port/s/1" - ) - ) - } - @Test fun `insert list of public OCShares into repository returns a list of long`() { val expectedValues = listOf(1, 2) @@ -364,18 +267,10 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.insertOrReplace(publicShares) } } - @Test(expected = Exception::class) - fun `insert list of public OCShares into repository returns an exception when dao receive an exception`() { - - every { ocSharesDao.insertOrReplace(publicShares) } throws Exception() - ocLocalSharesDataSource.insert( - publicShares.map { it.toModel() } - ) - } @Test - fun `update public OCShare and returns a long`() { + fun `update public OCShare returns a long`() { every { ocSharesDao.update(publicShares[1]) } returns 8 val updatedShareId = ocLocalSharesDataSource.update( @@ -391,26 +286,12 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.update(publicShares[1]) } } - @Test(expected = Exception::class) - fun `update public OCShare and returns an exception when dao receive an exception`() { - every { ocSharesDao.update(publicShares[1]) } throws Exception() - - ocLocalSharesDataSource.update( - OC_PUBLIC_SHARE.copy( - path = "/Photos/", - isFolder = true, - name = "Photos link 2", - shareLink = "http://server:port/s/2" - ) - ) - } - /************************************************************************************************************** *************************************************** COMMON *************************************************** **************************************************************************************************************/ @Test - fun `replaceShares OCShares and returns a list of long`() { + fun `replaceShares returns a list of long`() { val expectedValues = listOf(1, 2) every { ocSharesDao.replaceShares(publicShares) } returns expectedValues @@ -423,33 +304,15 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.replaceShares(publicShares) } } - @Test(expected = Exception::class) - fun `replaceShares returns returns an exception when dao receive an exception`() { - - every { ocSharesDao.replaceShares(publicShares) } throws Exception() - - ocLocalSharesDataSource.replaceShares( - publicShares.map { it.toModel() } - ) - } - @Test - fun `deleteSharesForFile returns Unit`() { - every { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } returns Unit + fun deleteSharesForFile() { ocLocalSharesDataSource.deleteSharesForFile("file", OC_ACCOUNT_NAME) verify(exactly = 1) { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } } - @Test(expected = Exception::class) - fun `deleteSharesForFile returns an exception when dao receive an exception`() { - every { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } throws Exception() - ocLocalSharesDataSource.deleteSharesForFile("file", OC_ACCOUNT_NAME) - } - - @Test - fun `deleteShare OCShare by remoteId and returns a Int`() { + fun `deleteShare returns a Int`() { every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } returns 1 val deletedRows = ocLocalSharesDataSource.deleteShare(OC_SHARE.remoteId) @@ -458,27 +321,12 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.deleteShare(OC_SHARE.remoteId) } } - - @Test(expected = Exception::class) - fun `deleteShare OCShare by remoteId returns an exception when dao receive an exception`() { - every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } throws Exception() - - ocLocalSharesDataSource.deleteShare(OC_SHARE.remoteId) - } - @Test - fun `deleteSharesForAccount by account returns unit`() { - every { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } returns Unit + fun deleteSharesForAccount() { ocLocalSharesDataSource.deleteSharesForAccount(OC_SHARE.accountOwner) verify(exactly = 1) { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } } - @Test(expected = Exception::class) - fun `deleteSharesForAccount by account returns an exception when dao receive an exception`() { - every { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } throws Exception() - - ocLocalSharesDataSource.deleteSharesForAccount(OC_SHARE.accountOwner) - } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt index d393d4e4bd0..9006b08f6b9 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt @@ -3,6 +3,7 @@ * * @author David González Verdugo * @author Jesús Recio + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -48,7 +49,7 @@ class OCRemoteShareDataSourceTest { private val clientManager: ClientManager = mockk(relaxed = true) @Before - fun init() { + fun setUp() { every { clientManager.getShareService(any()) } returns ocShareService ocRemoteShareDataSource = OCRemoteShareDataSource(clientManager, remoteShareMapper) @@ -78,7 +79,15 @@ class OCRemoteShareDataSourceTest { ) every { - ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + ocShareService.insertShare( + remoteFilePath = "Photos/", + shareType = com.owncloud.android.lib.resources.shares.ShareType.fromValue(ShareType.USER.value)!!, + shareWith = "user", + permissions = 1, + name = "", + password = "", + expirationDate = 0, + ) } returns createRemoteShareOperationResult // Insert share on remote datasource @@ -99,26 +108,19 @@ class OCRemoteShareDataSourceTest { assertEquals(1, privateShareAdded.permissions) verify(exactly = 1) { - ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + clientManager.getShareService(any()) + ocShareService.insertShare( + remoteFilePath = "Photos/", + shareType = com.owncloud.android.lib.resources.shares.ShareType.fromValue(ShareType.USER.value)!!, + shareWith = "user", + permissions = 1, + name = "", + password = "", + expirationDate = 0, + ) } } - @Test(expected = Exception::class) - fun `insert private share returns an exception when service receive an exception`() { - - every { - ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) - } throws Exception() - - ocRemoteShareDataSource.insert( - remoteFilePath = "Photos/", - shareType = ShareType.USER, - shareWith = "user", - permissions = 1, - accountName = "user@server" - ) - } - @Test fun `updateShare update a private share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( @@ -140,7 +142,13 @@ class OCRemoteShareDataSourceTest { ) every { - ocShareService.updateShare(any(), any(), any(), any(), any()) + ocShareService.updateShare( + remoteId = "3", + name = "", + password = "", + expirationDate = 0, + permissions = 17, + ) } returns updateRemoteShareOperationResult // Update share on remote datasource @@ -159,24 +167,17 @@ class OCRemoteShareDataSourceTest { assertEquals(false, privateShareUpdated.isFolder) verify(exactly = 1) { - ocShareService.updateShare(any(), any(), any(), any(), any()) + clientManager.getShareService(any()) + ocShareService.updateShare( + remoteId = "3", + name = "", + password = "", + expirationDate = 0, + permissions = 17, + ) } } - @Test(expected = Exception::class) - fun `updateShare update a private share returns an exception when service receive an exception`() { - - every { - ocShareService.updateShare(any(), any(), any(), any(), any()) - } throws Exception() - - ocRemoteShareDataSource.updateShare( - remoteId = "3", - permissions = 17, - accountName = "user@server" - ) - } - /****************************************************************************************************** ******************************************* PUBLIC SHARES ******************************************** ******************************************************************************************************/ @@ -200,7 +201,15 @@ class OCRemoteShareDataSourceTest { ) every { - ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + ocShareService.insertShare( + remoteFilePath = "Photos/img1.png", + shareType = com.owncloud.android.lib.resources.shares.ShareType.fromValue(ShareType.PUBLIC_LINK.value)!!, + shareWith = "", + permissions = 1, + name = "", + password = "", + expirationDate = 0 + ) } returns createRemoteShareOperationResult // Insert share on remote datasource @@ -222,25 +231,19 @@ class OCRemoteShareDataSourceTest { assertEquals("http://server:port/s/112ejbhdasyd1", publicShareAdded.shareLink) verify(exactly = 1) { - ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) + clientManager.getShareService(any()) + ocShareService.insertShare( + remoteFilePath = "Photos/img1.png", + shareType = com.owncloud.android.lib.resources.shares.ShareType.fromValue(ShareType.PUBLIC_LINK.value)!!, + shareWith = "", + permissions = 1, + name = "", + password = "", + expirationDate = 0 + ) } } - @Test(expected = Exception::class) - fun `insert public share returns an exception when service receive an exception`() { - every { - ocShareService.insertShare(any(), any(), any(), any(), any(), any(), any()) - } throws Exception() - - ocRemoteShareDataSource.insert( - "Photos/img1.png", - ShareType.PUBLIC_LINK, - "", - 1, - accountName = "user@server" - ) - } - @Test fun `updateShare update a public share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( @@ -262,7 +265,13 @@ class OCRemoteShareDataSourceTest { ) every { - ocShareService.updateShare(any(), any(), any(), any(), any()) + ocShareService.updateShare( + remoteId = "3", + name = "", + password = "", + expirationDate = 0, + permissions = 17, + ) } returns updateRemoteShareOperationResult // Update share on remote datasource @@ -282,25 +291,17 @@ class OCRemoteShareDataSourceTest { assertEquals("http://server:port/s/1275farv", publicShareUpdated.shareLink) verify(exactly = 1) { - ocShareService.updateShare(any(), any(), any(), any(), any()) + clientManager.getShareService(any()) + ocShareService.updateShare( + remoteId = "3", + name = "", + password = "", + expirationDate = 0, + permissions = 17, + ) } } - @Test(expected = Exception::class) - fun `updateShare update a public share returns an exception when service receive an exception`() { - - every { - ocShareService.updateShare(any(), any(), any(), any(), any()) - } throws Exception() - - ocRemoteShareDataSource.updateShare( - remoteId = "3", - permissions = 17, - accountName = "user@server" - ) - - } - /****************************************************************************************************** *********************************************** COMMON *********************************************** ******************************************************************************************************/ @@ -390,6 +391,7 @@ class OCRemoteShareDataSourceTest { assertEquals("My family", groupShare.sharedWithDisplayName) verify(exactly = 1) { + clientManager.getShareService(any()) ocShareService.getShares( remoteFilePath = "/Documents/doc", reshares = true, @@ -398,23 +400,6 @@ class OCRemoteShareDataSourceTest { } } - @Test(expected = Exception::class) - fun `getShares returns an exception when service receive an exception`() { - - every { - ocShareService.getShares(any(), any(), any()) - } throws Exception() - - // Get shares from remote datasource - ocRemoteShareDataSource.getShares( - remoteFilePath = "/Documents/doc", - reshares = true, - subfiles = true, - accountName = "user@server" - ) - - } - @Test(expected = ShareNotFoundException::class) fun `insert share file not found`() { createShareOperationWithError(RemoteOperationResult.ResultCode.SHARE_NOT_FOUND) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt index 249390fe280..de37b4b0c35 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt @@ -1,31 +1,40 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.owncloud.android.data.spaces.datasource.implementation -import com.owncloud.android.data.OwncloudDatabase import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource.Companion.toEntity import com.owncloud.android.data.spaces.datasources.implementation.OCLocalSpacesDataSource.Companion.toModel -import com.owncloud.android.data.spaces.db.SpaceRootEntity import com.owncloud.android.data.spaces.db.SpaceSpecialEntity import com.owncloud.android.data.spaces.db.SpacesDao import com.owncloud.android.data.spaces.db.SpacesEntity -import com.owncloud.android.data.spaces.db.SpacesWithSpecials import com.owncloud.android.domain.spaces.model.OCSpace import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARES -import com.owncloud.android.domain.spaces.model.SpaceDeleted -import com.owncloud.android.domain.spaces.model.SpaceOwner -import com.owncloud.android.domain.spaces.model.SpaceQuota -import com.owncloud.android.domain.spaces.model.SpaceRoot -import com.owncloud.android.domain.spaces.model.SpaceUser -import com.owncloud.android.testutil.OC_ACCOUNT_ID import com.owncloud.android.testutil.OC_ACCOUNT_NAME -import com.owncloud.android.testutil.OC_CLIENT_ID import com.owncloud.android.testutil.OC_SPACE_PERSONAL -import com.owncloud.android.testutil.OC_SPACE_SPECIAL_IMAGE -import com.owncloud.android.testutil.OC_SPACE_SPECIAL_README +import com.owncloud.android.testutil.OC_SPACE_PROJECT_WITH_IMAGE +import com.owncloud.android.testutil.SPACE_WITH_SPECIALS import io.mockk.Runs import io.mockk.every import io.mockk.just -import io.mockk.mockkClass +import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking @@ -36,94 +45,21 @@ import org.junit.Test class OCLocalSpacesDataSourceTest { private lateinit var ocLocalSpacesDataSource: OCLocalSpacesDataSource - private val spacesDao = mockkClass(SpacesDao::class) + private val spacesDao = mockk() private val WEB_DAV_URL = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9" - private val spaceWithSpecials = SpacesWithSpecials( - SpacesEntity( - accountName = OC_ACCOUNT_NAME, - driveAlias = "driveAlias", - driveType = "driveType", - id = OC_ACCOUNT_ID, - ownerId = OC_CLIENT_ID, - lastModifiedDateTime = "lastModifiedDateTime", - name = "name", - quota = null, - root = SpaceRootEntity( - eTag = "eTag", - id = "id", - webDavUrl = WEB_DAV_URL, - deleteState = "state" - ), - webUrl = "webUrl", - description = "description" - ), - listOf( - SpaceSpecialEntity( - accountName = OC_ACCOUNT_NAME, - eTag = "eTag", - fileMimeType = "fileMimeType", - id = OC_ACCOUNT_ID, - spaceId = OC_SPACE_PERSONAL.id, - lastModifiedDateTime = "lastModifiedDateTime", - name = "name", - webDavUrl = WEB_DAV_URL, - size = 100, - specialFolderName = OC_SPACE_SPECIAL_IMAGE.name - ) - ) - ) - - private val listSpaceSpecial = listOf( - OCSpace( - accountName = OC_ACCOUNT_NAME, - driveAlias = "driveAlias", - driveType = "driveType", - id = OC_ACCOUNT_ID, - lastModifiedDateTime = "lastModifiedDateTime", - name = "name", - owner = SpaceOwner( - user = SpaceUser( - id = "id" - ) - ), - quota = SpaceQuota( - remaining = 100, - state = "quotaResponse.state", - total = 100, - used = 100, - ), - root = SpaceRoot( - eTag = "eTag", - id = "id", - webDavUrl = WEB_DAV_URL, - deleted = SpaceDeleted(state = "state") - ), - webUrl = "webUrl", - description = "description", - special = listOf( - OC_SPACE_SPECIAL_IMAGE, - OC_SPACE_SPECIAL_README - ) - ) - ) - @Before - fun init() { - val db = mockkClass(OwncloudDatabase::class) - - every { db.spacesDao() } returns spacesDao - + fun setUp() { ocLocalSpacesDataSource = OCLocalSpacesDataSource(spacesDao) } @Test - fun `saveSpacesForAccount inserts spaces and special spaces returns unit`() { + fun `saveSpacesForAccount inserts spaces and special spaces`() { val spaceEntities = mutableListOf() val spaceSpecialEntities = mutableListOf() - listSpaceSpecial.forEach { spaceModel -> + listOf(OC_SPACE_PROJECT_WITH_IMAGE).forEach { spaceModel -> spaceEntities.add(spaceModel.toEntity()) spaceModel.special?.let { listOfSpacesSpecials -> spaceSpecialEntities.addAll(listOfSpacesSpecials.map { it.toEntity(spaceModel.accountName, spaceModel.id) }) @@ -134,32 +70,13 @@ class OCLocalSpacesDataSourceTest { spacesDao.insertOrDeleteSpaces(any(), any()) } just Runs - ocLocalSpacesDataSource.saveSpacesForAccount(listSpaceSpecial) + ocLocalSpacesDataSource.saveSpacesForAccount(listOf(OC_SPACE_PROJECT_WITH_IMAGE)) verify(exactly = 1) { spacesDao.insertOrDeleteSpaces(spaceEntities, spaceSpecialEntities) } } - @Test(expected = Exception::class) - fun `saveSpacesForAccount inserts spaces and special spaces returns an exception when dao receive an exception`() { - val spaceEntities = mutableListOf() - val spaceSpecialEntities = mutableListOf() - - listSpaceSpecial.forEach { spaceModel -> - spaceEntities.add(spaceModel.toEntity()) - spaceModel.special?.let { listOfSpacesSpecials -> - spaceSpecialEntities.addAll(listOfSpacesSpecials.map { it.toEntity(spaceModel.accountName, spaceModel.id) }) - } - } - - every { - spacesDao.insertOrDeleteSpaces(any(), any()) - } throws Exception() - - ocLocalSpacesDataSource.saveSpacesForAccount(listSpaceSpecial) - } - @Test fun `getPersonalSpaceForAccount by drive type returns a OCSpace`() { every { @@ -175,40 +92,21 @@ class OCLocalSpacesDataSourceTest { } } - @Test(expected = Exception::class) - fun `getPersonalSpaceForAccount by drive type returns an exception when dao receive an exception`() { - every { - spacesDao.getSpacesByDriveTypeForAccount(any(), any()) - } throws Exception() - - ocLocalSpacesDataSource.getPersonalSpaceForAccount(OC_ACCOUNT_NAME) - } - - @Test fun `getSharesSpaceForAccount returns a OCSpace`() { every { spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) - } returns OC_SPACE_PERSONAL.toEntity() + } returns SPACE_WITH_SPECIALS.space val resultActual = ocLocalSpacesDataSource.getSharesSpaceForAccount(OC_ACCOUNT_NAME) - assertEquals(OC_SPACE_PERSONAL, resultActual) + assertEquals(SPACE_WITH_SPECIALS.space.toModel(), resultActual) verify(exactly = 1) { spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) } } - @Test(expected = Exception::class) - fun `getSharesSpaceForAccount returns an exception when dao receive an exception`() { - every { - spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) - } throws Exception() - - ocLocalSpacesDataSource.getSharesSpaceForAccount(OC_ACCOUNT_NAME) - } - @Test fun `getSpacesFromEveryAccountAsStream returns a flow of OCSpace`() = runBlocking { @@ -237,21 +135,6 @@ class OCLocalSpacesDataSourceTest { } } - @Test(expected = Exception::class) - fun `getSpacesFromEveryAccountAsStream returns an exception when dao receive an exception`() { - - every { - spacesDao.getSpacesByDriveTypeFromEveryAccountAsStream( - setOf( - OCSpace.DRIVE_TYPE_PERSONAL, - OCSpace.DRIVE_TYPE_PROJECT - ) - ) - } throws Exception() - - ocLocalSpacesDataSource.getSpacesFromEveryAccountAsStream() - } - @Test fun `getSpacesByDriveTypeWithSpecialsForAccountAsFlow returns a flow of OCSpace list`() = runBlocking { @@ -263,7 +146,7 @@ class OCLocalSpacesDataSourceTest { OCSpace.DRIVE_TYPE_PROJECT ) ) - } returns flowOf(listOf(spaceWithSpecials)) + } returns flowOf(listOf(SPACE_WITH_SPECIALS)) val resultActual = ocLocalSpacesDataSource.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( OC_ACCOUNT_NAME, setOf( @@ -273,7 +156,7 @@ class OCLocalSpacesDataSourceTest { ) resultActual.collect { result -> - assertEquals(listOf(spaceWithSpecials.toModel()), result) + assertEquals(listOf(SPACE_WITH_SPECIALS.toModel()), result) } verify(exactly = 1) { @@ -287,26 +170,6 @@ class OCLocalSpacesDataSourceTest { } } - @Test(expected = Exception::class) - fun `getSpacesByDriveTypeWithSpecialsForAccountAsFlow returns an exception when dao receive an exception`() { - - every { - spacesDao.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( - OC_ACCOUNT_NAME, - setOf( - OCSpace.DRIVE_TYPE_PERSONAL, - OCSpace.DRIVE_TYPE_PROJECT - ) - ) - } throws Exception() - - ocLocalSpacesDataSource.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( - OC_ACCOUNT_NAME, setOf( - OCSpace.DRIVE_TYPE_PERSONAL, - OCSpace.DRIVE_TYPE_PROJECT - ) - ) - } @Test fun `getPersonalAndProjectSpacesForAccount returns a list of OCSpace`() { @@ -336,31 +199,16 @@ class OCLocalSpacesDataSourceTest { } } - @Test(expected = Exception::class) - fun `getPersonalAndProjectSpacesForAccount returns an exception when dao receive an exception`() { - - every { - spacesDao.getSpacesByDriveTypeForAccount( - OC_ACCOUNT_NAME, - setOf( - OCSpace.DRIVE_TYPE_PERSONAL, - OCSpace.DRIVE_TYPE_PROJECT - ) - ) - } throws Exception() - - ocLocalSpacesDataSource.getPersonalAndProjectSpacesForAccount(OC_ACCOUNT_NAME) - } @Test fun `getSpaceWithSpecialsByIdForAccount returns a OCSpace`() { every { spacesDao.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - } returns spaceWithSpecials + } returns SPACE_WITH_SPECIALS val resultActual = ocLocalSpacesDataSource.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - assertEquals(spaceWithSpecials.toModel(), resultActual) + assertEquals(SPACE_WITH_SPECIALS.toModel(), resultActual) verify(exactly = 1) { spacesDao.getSpaceWithSpecialsByIdForAccount( @@ -369,16 +217,6 @@ class OCLocalSpacesDataSourceTest { } } - @Test(expected = Exception::class) - fun `getSpaceWithSpecialsByIdForAccount returns an exception when dao receive an exception`() { - - every { - spacesDao.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - } throws Exception() - - ocLocalSpacesDataSource.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - } - @Test fun `getWebDavUrlForSpace returns a string of webDavUrl`() { @@ -397,19 +235,8 @@ class OCLocalSpacesDataSourceTest { } } - @Test(expected = Exception::class) - fun `getWebDavUrlForSpace returns an exception when dao receive an exception`() { - - every { - spacesDao.getWebDavUrlForSpace(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - } throws Exception() - - ocLocalSpacesDataSource.getWebDavUrlForSpace(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - - } - @Test - fun `deleteSpacesForAccount delete the space by account returns Unit`() { + fun `deleteSpacesForAccount delete the space by account`() { every { spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) @@ -421,15 +248,4 @@ class OCLocalSpacesDataSourceTest { spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) } } - - @Test(expected = Exception::class) - fun `deleteSpacesForAccount delete the space by account returns an exception when dao receive an exception`() { - - every { - spacesDao.deleteSpacesForAccount(OC_ACCOUNT_NAME) - } throws Exception() - - ocLocalSpacesDataSource.deleteSpacesForAccount(OC_ACCOUNT_NAME) - - } -} \ No newline at end of file +} diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt index 37da22053ad..223d24a9760 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt @@ -1,14 +1,30 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.owncloud.android.data.spaces.datasource.implementation import com.owncloud.android.data.ClientManager import com.owncloud.android.data.spaces.datasources.implementation.OCRemoteSpacesDataSource import com.owncloud.android.data.spaces.datasources.implementation.OCRemoteSpacesDataSource.Companion.toModel -import com.owncloud.android.lib.resources.spaces.responses.QuotaResponse -import com.owncloud.android.lib.resources.spaces.responses.RootResponse -import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse import com.owncloud.android.lib.resources.spaces.services.OCSpacesService -import com.owncloud.android.testutil.OC_ACCOUNT_ID import com.owncloud.android.testutil.OC_ACCOUNT_NAME +import com.owncloud.android.testutil.SPACE_RESPONSE import com.owncloud.android.utils.createRemoteOperationResultMock import io.mockk.every import io.mockk.mockk @@ -24,34 +40,8 @@ class OCRemoteSpacesDataSourceTest { private val ocSpaceService: OCSpacesService = mockk() private val clientManager: ClientManager = mockk(relaxed = true) - private val spaceResponse = - SpaceResponse( - driveAlias = "driveAlias", - driveType = "driveType", - id = OC_ACCOUNT_ID, - lastModifiedDateTime = "lastModifiedDateTime", - name = "name", - webUrl = "webUrl", - description = "description", - owner = null, - root = RootResponse( - eTag = "eTag", - id = OC_ACCOUNT_ID, - webDavUrl = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9", - deleted = null - ), - quota = QuotaResponse( - remaining = 1, - state = "state", - total = 10, - used = 1 - ), - special = null, - - ) - @Before - fun init() { + fun setUp() { ocRemoteSpacesDataSource = OCRemoteSpacesDataSource(clientManager) every { clientManager.getSpacesService(any()) } returns ocSpaceService } @@ -59,28 +49,20 @@ class OCRemoteSpacesDataSourceTest { @Test fun `refreshSpacesForAccount returns a list of OCSpace`() { val removeRemoteSpaceOperationResult = createRemoteOperationResultMock( - listOf(spaceResponse), isSuccess = true + listOf(SPACE_RESPONSE), isSuccess = true ) every { ocSpaceService.getSpaces() } returns removeRemoteSpaceOperationResult val resultActual = ocRemoteSpacesDataSource.refreshSpacesForAccount(OC_ACCOUNT_NAME) - assertEquals( - listOf(spaceResponse.toModel(OC_ACCOUNT_NAME)), resultActual + assertEquals( + listOf(SPACE_RESPONSE.toModel(OC_ACCOUNT_NAME)), resultActual ) verify(exactly = 1) { + clientManager.getSpacesService(any()) ocSpaceService.getSpaces() } } - - @Test(expected = Exception::class) - fun `refreshSpacesForAccount returns an exception when service receive an exception`() { - - every { ocSpaceService.getSpaces() } throws Exception() - - ocRemoteSpacesDataSource.refreshSpacesForAccount(OC_ACCOUNT_NAME) - } - } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt index b0906b27975..c6daa0c5131 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt @@ -1,3 +1,23 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + package com.owncloud.android.data.transfers.implementation import com.owncloud.android.data.OwncloudDatabase @@ -15,6 +35,7 @@ import com.owncloud.android.testutil.OC_ACCOUNT_NAME import io.mockk.every import io.mockk.mockkClass import io.mockk.verify +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals @@ -36,10 +57,11 @@ class OCLocalTransferDataSourceTest { forceOverwrite = true, createdBy = UploadEnqueuedBy.ENQUEUED_BY_USER ) - private val transferEntity: OCTransferEntity = ocTransfer.toEntity() + + private var transferEntity: OCTransferEntity = ocTransfer.toEntity() @Before - fun init() { + fun setUp() { val db = mockkClass(OwncloudDatabase::class) every { db.transferDao() } returns transferDao @@ -63,15 +85,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `saveTransfer returns an exception when dao receive an exception`() { - - every { - transferDao.insertOrReplace(any()) - } throws Exception() - - ocLocalTransferDataSource.saveTransfer(ocTransfer) - } @Test fun `updateTransfer returns a Long`() { val resultExpected = 1L @@ -86,16 +99,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `updateTransfer returns an exception when dao receive an exception`() { - every { - transferDao.insertOrReplace(any()) - } throws Exception() - - ocLocalTransferDataSource.updateTransfer(ocTransfer) - } @Test - fun `updateTransferStatusToInProgressById returns a unit`() { + fun updateTransferStatusToInProgressById() { val resultExpected = 10L every { transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_IN_PROGRESS.value) @@ -108,19 +113,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `updateTransferStatusToInProgressById returns an exception when dao receive an exception`() { - val resultExpected = 10L - every { - transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_IN_PROGRESS.value) - } throws Exception() - - ocLocalTransferDataSource.updateTransferStatusToInProgressById(resultExpected) - - } - @Test - fun `updateTransferStatusToEnqueuedById returns a unit`() { + fun updateTransferStatusToEnqueuedById() { val resultExpected = 10L every { transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_QUEUED.value) @@ -133,18 +127,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `updateTransferStatusToEnqueuedById returns an exception when dao receive an exception`() { - val resultExpected = 10L - every { - transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_QUEUED.value) - } throws Exception() - - ocLocalTransferDataSource.updateTransferStatusToEnqueuedById(resultExpected) - - } @Test - fun `updateTransferWhenFinished returns a unit`() { + fun updateTransferWhenFinished() { val timestamp = System.currentTimeMillis() every { transferDao.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED.value, timestamp, TransferResult.UPLOADED.value) @@ -157,19 +141,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `updateTransferWhenFinished returns an exception when dao receive an exception`() { - val timestamp = System.currentTimeMillis() - every { - transferDao.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED.value, timestamp, TransferResult.UPLOADED.value) - } throws Exception() - - ocLocalTransferDataSource.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED, timestamp, TransferResult.UPLOADED) - - } - @Test - fun `updateTransferLocalPath returns a unit`() { + fun updateTransferLocalPath() { every { transferDao.updateTransferLocalPath(id, ocTransfer.localPath) } returns Unit @@ -181,18 +154,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `updateTransferLocalPath returns an exception when dao receive an exception`() { - every { - transferDao.updateTransferLocalPath(id, ocTransfer.localPath) - } throws Exception() - - ocLocalTransferDataSource.updateTransferLocalPath(id, ocTransfer.localPath) - - } - @Test - fun `updateTransferStorageDirectoryInLocalPath returns a unit`() { + fun updateTransferStorageDirectoryInLocalPath() { val oldDirectory = "oldDirectory" val newDirectory = "newDirectory" @@ -207,20 +170,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `updateTransferStorageDirectoryInLocalPath returns an exception when dao receive an exception`() { - val oldDirectory = "oldDirectory" - val newDirectory = "newDirectory" - - every { - transferDao.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) - } throws Exception() - - ocLocalTransferDataSource.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) - - } @Test - fun `deleteTransferById returns a unit`() { + fun deleteTransferById() { every { transferDao.deleteTransferWithId(id) } returns Unit @@ -232,17 +183,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `deleteTransferById returns an exception when dao receive an exception`() { - every { - transferDao.deleteTransferWithId(id) - } throws Exception() - - ocLocalTransferDataSource.deleteTransferById(id) - - } @Test - fun `deleteAllTransfersFromAccount returns a unit`() { + fun deleteAllTransfersFromAccount() { every { transferDao.deleteTransfersWithAccountName(OC_ACCOUNT_NAME) } returns Unit @@ -254,15 +196,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `deleteAllTransfersFromAccount returns an exception when dao receive an exception`() { - every { - transferDao.deleteTransfersWithAccountName(OC_ACCOUNT_NAME) - } throws Exception() - - ocLocalTransferDataSource.deleteAllTransfersFromAccount(OC_ACCOUNT_NAME) - - } @Test fun `getTransferById returns a OCTransfer`() { every { @@ -278,16 +211,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `getTransferById returns an exception when dao receive an exception`() { - every { - transferDao.getTransferWithId(any()) - } throws Exception() - - ocLocalTransferDataSource.getTransferById(id) - - } - @Test fun `getAllTransfers returns a list of OCTransfer`() { @@ -304,46 +227,50 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `getAllTransfers returns an exception when dao receive an exception`() { + @Test + fun `getAllTransfersAsStream returns a flow of list of OCTransfer with transferStatus in progress`() = runBlocking { - every { - transferDao.getAllTransfers() - } throws Exception() + val transferEntityInProgress: OCTransferEntity = ocTransfer.toEntity() + transferEntityInProgress.status = 0 - ocLocalTransferDataSource.getAllTransfers() + val transferEntityQueue: OCTransferEntity = ocTransfer.toEntity() + transferEntityQueue.status = 1 - } + val transferEntityFailed: OCTransferEntity = ocTransfer.toEntity() + transferEntityFailed.status = 2 - @Test - fun `getAllTransfersAsStream returns a flow of list of OCTransfer`() = runBlocking { + val transferEntitySucceeded: OCTransferEntity = ocTransfer.toEntity() + transferEntitySucceeded.status = 3 - every { - transferDao.getAllTransfersAsStream() - } returns flowOf(listOf(transferEntity)) + val transferListRandom = listOf(transferEntityQueue, transferEntityFailed, transferEntityInProgress, transferEntitySucceeded) - val actualResult = ocLocalTransferDataSource.getAllTransfersAsStream() - actualResult.collect { result -> - assertEquals(listOf(transferEntity.toModel()), result) - } + val transferQueue = ocTransfer.copy() + transferQueue.status = TransferStatus.TRANSFER_QUEUED - verify(exactly = 1) { - transferDao.getAllTransfersAsStream() - } - } + val transferFailed = ocTransfer.copy() + transferFailed.status = TransferStatus.TRANSFER_FAILED - @Test(expected = Exception::class) - fun `getAllTransfersAsStream returns an exception when dao receive an exception`() { + val transferSucceeded = ocTransfer.copy() + transferSucceeded.status = TransferStatus.TRANSFER_SUCCEEDED + + val transferListOrdered = listOf(ocTransfer, transferQueue, transferFailed, transferSucceeded) every { transferDao.getAllTransfersAsStream() - } throws Exception() + } returns flowOf(transferListRandom) + + val actualResult = ocLocalTransferDataSource.getAllTransfersAsStream().first().map { it } + val expectedStatusList = transferListOrdered.map { it } - ocLocalTransferDataSource.getAllTransfersAsStream() + assertEquals(expectedStatusList, actualResult) + verify(exactly = 1) { + transferDao.getAllTransfersAsStream() + } } + @Test fun `getLastTransferFor returns a OCTransfer`() { @@ -360,18 +287,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `getLastTransferFor returns an exception`() { - - every { - transferDao.getLastTransferWithRemotePathAndAccountName(ocTransfer.remotePath, OC_ACCOUNT_NAME) - } throws Exception() - - ocLocalTransferDataSource.getLastTransferFor(ocTransfer.remotePath, OC_ACCOUNT_NAME) - - } - - @Test fun `getCurrentAndPendingTransfers returns a list of OCTransfer`() { @@ -388,17 +303,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `getCurrentAndPendingTransfers returns an exception when dao receive an exception`() { - - every { - transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_IN_PROGRESS.value, TransferStatus.TRANSFER_QUEUED.value)) - } throws Exception() - - ocLocalTransferDataSource.getCurrentAndPendingTransfers() - - } - @Test fun `getFailedTransfers returns a list of OCTransfer`() { @@ -415,17 +319,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `getFailedTransfers returns an Exception when dao receive an exception`() { - - every { - transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_FAILED.value)) - } throws Exception() - - ocLocalTransferDataSource.getFailedTransfers() - - } - @Test fun `getFinishedTransfers returns a list of OCTransfer`() { @@ -442,17 +335,6 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `getFinishedTransfers returns an exception when dao receive an exception`() { - - every { - transferDao.getTransfersWithStatus(listOf(TransferStatus.TRANSFER_SUCCEEDED.value)) - } throws Exception() - - ocLocalTransferDataSource.getFinishedTransfers() - - } - @Test fun `clearFailedTransfers returns unit`() { @@ -467,19 +349,8 @@ class OCLocalTransferDataSourceTest { } } - @Test(expected = Exception::class) - fun `clearFailedTransfers returns an exception when dao receive an exception`() { - - every { - transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_FAILED.value) - } throws Exception() - - ocLocalTransferDataSource.clearFailedTransfers() - - } - @Test - fun `clearSuccessfulTransfers returns unit`() { + fun clearSuccessfulTransfers() { every { transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) @@ -491,15 +362,4 @@ class OCLocalTransferDataSourceTest { transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) } } - - @Test(expected = Exception::class) - fun `clearSuccessfulTransfers returns an exception when dao receive an exception`() { - - every { - transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) - } throws Exception() - - ocLocalTransferDataSource.clearSuccessfulTransfers() - - } } \ No newline at end of file diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt index 340d5e777c9..024f04f59f1 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt @@ -2,6 +2,7 @@ * ownCloud Android client application * * @author Abel García de Prada + * @author Aitor Ballesteros Pavón * Copyright (C) 2020 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify @@ -22,6 +23,7 @@ package com.owncloud.android.data.user.datasources import androidx.arch.core.executor.testing.InstantTaskExecutorRule import com.owncloud.android.data.user.datasources.implementation.OCLocalUserDataSource import com.owncloud.android.data.user.datasources.implementation.OCLocalUserDataSource.Companion.toEntity +import com.owncloud.android.data.user.datasources.implementation.OCLocalUserDataSource.Companion.toModel import com.owncloud.android.data.user.db.UserDao import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_USER_QUOTA @@ -37,7 +39,7 @@ import org.junit.rules.TestRule class OCLocalUserDataSourceTest { private lateinit var ocLocalUserDataSource: OCLocalUserDataSource - private val ocUserQuotaDao = mockk(relaxed = true) + private val ocUserQuotaDao = mockk(relaxUnitFun = true) private val userQuotaEntity = OC_USER_QUOTA.toEntity() @@ -46,13 +48,12 @@ class OCLocalUserDataSourceTest { var rule: TestRule = InstantTaskExecutorRule() @Before - fun init() { + fun setUp() { ocLocalUserDataSource = OCLocalUserDataSource(ocUserQuotaDao) } @Test - fun `saveQuotaForAccount return Unit`() { - every { ocUserQuotaDao.insertOrReplace(any()) } returns Unit + fun saveQuotaForAccount() { ocLocalUserDataSource.saveQuotaForAccount(OC_ACCOUNT_NAME, OC_USER_QUOTA) @@ -61,13 +62,6 @@ class OCLocalUserDataSourceTest { } } - @Test(expected = Exception::class) - fun `saveQuotaForAccount returns an exception when dao receive an exception`() { - every { ocUserQuotaDao.insertOrReplace(any()) } throws Exception() - ocLocalUserDataSource.saveQuotaForAccount(OC_ACCOUNT_NAME, OC_USER_QUOTA) - - } - @Test fun `getQuotaForAccount returns a UserQuota`() { every { ocUserQuotaDao.getQuotaForAccount(any()) } returns userQuotaEntity @@ -94,17 +88,8 @@ class OCLocalUserDataSourceTest { } } - @Test(expected = Exception::class) - fun `getQuotaForAccount returns an exception when dao receive an exception`() { - every { ocUserQuotaDao.getQuotaForAccount(any()) } throws Exception() - - ocLocalUserDataSource.getQuotaForAccount(OC_ACCOUNT_NAME) - - } - @Test - fun `deleteQuotaForAccount returns unit`() { - every { ocUserQuotaDao.deleteQuotaForAccount(any()) } returns Unit + fun deleteQuotaForAccount() { ocLocalUserDataSource.deleteQuotaForAccount(OC_ACCOUNT_NAME) @@ -113,11 +98,18 @@ class OCLocalUserDataSourceTest { } } - @Test(expected = Exception::class) - fun `deleteQuotaForAccount returns an exception when dao receive an exception`() { - every { ocUserQuotaDao.deleteQuotaForAccount(any()) } throws Exception() + @Test + fun `getAllUserQuotas returns a UserQuote List`() { - ocLocalUserDataSource.deleteQuotaForAccount(OC_ACCOUNT_NAME) + every { ocUserQuotaDao.getAllUserQuotas() } returns listOf(userQuotaEntity) + + + val resultActual = ocLocalUserDataSource.getAllUserQuotas() + assertEquals(listOf(userQuotaEntity.toModel()), resultActual) + + verify(exactly = 1) { + ocUserQuotaDao.getAllUserQuotas() + } } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt index a88634a94f8..2916b3732f0 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt @@ -65,7 +65,7 @@ class OCRemoteUserDataSourceTest { ) @Before - fun init() { + fun setUp() { every { clientManager.getUserService(any()) } returns ocUserService ocRemoteUserDataSource = OCRemoteUserDataSource( diff --git a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt index 4f57757ed9c..7fd70c08419 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt @@ -1,3 +1,22 @@ +/** + * ownCloud Android client application + * + * @author Aitor Ballesteros Pavón + * Copyright (C) 2020 ownCloud GmbH. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.owncloud.android.data.webfinger.datasource.implementation import com.owncloud.android.data.ClientManager @@ -24,10 +43,10 @@ class OCRemoteWebFingerDatasourceTest { private val clientManager: ClientManager = mockk(relaxed = true) private val ownCloudClient: OwnCloudClient = mockk(relaxed = true) private val ocWebFingerService: OCWebFingerService = mockk() - private val listString: List = mockk(relaxed = true) + private val listString: List = emptyList() @Before - fun init() { + fun setUp() { ocRemoteWebFingerDatasource = OCRemoteWebFingerDatasource( ocWebFingerService, clientManager, @@ -71,25 +90,6 @@ class OCRemoteWebFingerDatasourceTest { } } - @Test(expected = Exception::class) - fun `getInstancesFromWebFinger returns an exception when service receive an exception`() { - - every { - ocWebFingerService.getInstancesFromWebFinger( - lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, - any(), - ) - } throws Exception() - - ocRemoteWebFingerDatasource.getInstancesFromWebFinger( - lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - rel = WebFingerRel.OIDC_ISSUER_DISCOVERY, - resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - ) - } - @Test fun `getInstancesFromAuthenticatedWebFinger returns a list of web finger`() { @@ -116,6 +116,7 @@ class OCRemoteWebFingerDatasourceTest { assertEquals(getInstancesFromAuthenticatedWebFingerResult.data, actualResult) verify(exactly = 1) { + ownCloudClient.credentials = any() clientManager.getClientForAnonymousCredentials(any(), false) ocWebFingerService.getInstancesFromWebFinger( lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, @@ -125,26 +126,4 @@ class OCRemoteWebFingerDatasourceTest { ) } } - - @Test(expected = Exception::class) - fun `getInstancesFromAuthenticatedWebFinger returns an exception when service receive an exception`() { - - every { - ocWebFingerService.getInstancesFromWebFinger( - lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - rel = WebFingerRel.OIDC_ISSUER_DISCOVERY.uri, - ownCloudClient, - ) - } throws Exception() - - ocRemoteWebFingerDatasource.getInstancesFromAuthenticatedWebFinger( - lookupServer = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - rel = WebFingerRel.OIDC_ISSUER_DISCOVERY, - resource = OC_SECURE_SERVER_INFO_BASIC_AUTH.baseUrl, - username = OC_ACCOUNT_ID, - accessToken = OC_ACCESS_TOKEN - ) - - } } \ No newline at end of file diff --git a/owncloudTestUtil/build.gradle b/owncloudTestUtil/build.gradle index c81b34d9031..961796bd4e5 100644 --- a/owncloudTestUtil/build.gradle +++ b/owncloudTestUtil/build.gradle @@ -21,7 +21,7 @@ android { dependencies { implementation project(':owncloudDomain') implementation project(':owncloudComLibrary') - + implementation project(path: ':owncloudData') implementation libs.kotlin.stdlib implementation libs.androidx.lifecycle.livedata.ktx } diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFolderBackUpConfiguration.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFolderBackUpConfiguration.kt index dc84c660249..73a12e7d18d 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFolderBackUpConfiguration.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCFolderBackUpConfiguration.kt @@ -22,6 +22,7 @@ package com.owncloud.android.testutil import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration import com.owncloud.android.domain.camerauploads.model.UploadBehavior +import com.owncloud.android.data.folderbackup.db.FolderBackUpEntity val OC_BACKUP = FolderBackUpConfiguration( accountName = "", @@ -33,3 +34,14 @@ val OC_BACKUP = FolderBackUpConfiguration( lastSyncTimestamp = 1542628397, name = "", ) + +val OC_BACKUP_ENTITY = FolderBackUpEntity( + accountName = "", + behavior = UploadBehavior.COPY.name, + sourcePath = "/Photos", + uploadPath = "/Photos", + wifiOnly = true, + chargingOnly = true, + lastSyncTimestamp = 1542628397, + name = "" +) diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt index 8df42c44c3f..ca152338740 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt @@ -20,6 +20,10 @@ package com.owncloud.android.testutil +import com.owncloud.android.data.spaces.db.SpaceRootEntity +import com.owncloud.android.data.spaces.db.SpaceSpecialEntity +import com.owncloud.android.data.spaces.db.SpacesEntity +import com.owncloud.android.data.spaces.db.SpacesWithSpecials import com.owncloud.android.domain.spaces.model.OCSpace import com.owncloud.android.domain.spaces.model.SpaceDeleted import com.owncloud.android.domain.spaces.model.SpaceFile @@ -29,6 +33,13 @@ import com.owncloud.android.domain.spaces.model.SpaceRoot import com.owncloud.android.domain.spaces.model.SpaceSpecial import com.owncloud.android.domain.spaces.model.SpaceSpecialFolder import com.owncloud.android.domain.spaces.model.SpaceUser +import com.owncloud.android.lib.resources.spaces.responses.QuotaResponse +import com.owncloud.android.lib.resources.spaces.responses.RootResponse +import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse + +private val WEB_DAV_URL = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9" + + val OC_SPACE_SPECIAL_README = SpaceSpecial( eTag = "71f78349c3598c9e431a67de5a283fc0", @@ -130,3 +141,64 @@ val OC_SPACE_PROJECT_DISABLED = OC_SPACE_PROJECT_WITH_IMAGE.copy( ), special = null ) + +val SPACE_WITH_SPECIALS = SpacesWithSpecials( + SpacesEntity( + accountName = OC_ACCOUNT_NAME, + driveAlias = "driveAlias", + driveType = "driveType", + id = OC_ACCOUNT_ID, + ownerId = OC_CLIENT_ID, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + quota = null, + root = SpaceRootEntity( + eTag = "eTag", + id = "id", + webDavUrl = WEB_DAV_URL, + deleteState = "state" + ), + webUrl = "webUrl", + description = "description" + ), + listOf( + SpaceSpecialEntity( + accountName = OC_ACCOUNT_NAME, + eTag = "eTag", + fileMimeType = "fileMimeType", + id = OC_ACCOUNT_ID, + spaceId = OC_SPACE_PERSONAL.id, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + webDavUrl = WEB_DAV_URL, + size = 100, + specialFolderName = OC_SPACE_SPECIAL_IMAGE.name + ) + ) +) + +val SPACE_RESPONSE = + SpaceResponse( + driveAlias = "driveAlias", + driveType = "driveType", + id = OC_ACCOUNT_ID, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + webUrl = "webUrl", + description = "description", + owner = null, + root = RootResponse( + eTag = "eTag", + id = OC_ACCOUNT_ID, + webDavUrl = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9", + deleted = null + ), + quota = QuotaResponse( + remaining = 1, + state = "state", + total = 10, + used = 1 + ), + special = null, + + ) \ No newline at end of file From 76f39931efdaa50b07ed24d7cdfeffb993af7700 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 9 Oct 2023 10:53:34 +0100 Subject: [PATCH 12/20] Fix from CR 2 --- .../OCLocalAuthenticationDataSourceTest.kt | 4 +- .../OCLocalAppRegistryDataSourceTest.kt | 52 +++++------- .../OCRemoteAppRegistryDataSourceTest.kt | 8 +- .../OCLocalCapabilitiesDataSourceTest.kt | 3 +- .../OCRemoteCapabilitiesDataSourceTest.kt | 3 +- .../datasources/OCLocalFileDataSourceTest.kt | 3 +- .../datasources/OCRemoteFileDataSourceTest.kt | 3 +- .../OCFolderBackupLocalDataSourceTest.kt | 10 +-- ...Test.kt => OCRemoteOAuthDataSourceTest.kt} | 4 +- ...est.kt => OCRemoteShareeDataSourceTest.kt} | 30 ++++--- .../datasources/OCLocalShareDataSourceTest.kt | 25 +++--- .../OCRemoteShareDataSourceTest.kt | 30 +++---- .../OCLocalSpacesDataSourceTest.kt | 31 ++++--- .../OCRemoteSpacesDataSourceTest.kt | 5 +- .../OCLocalTransferDataSourceTest.kt | 84 +++++-------------- .../datasources/OCLocalUserDataSourceTest.kt | 5 +- .../datasources/OCRemoteUserDataSourceTest.kt | 29 +------ .../OCRemoteWebFingerDatasourceTest.kt | 11 ++- .../GetFileWithSyncInfoByIdUseCaseTest.kt | 25 ++---- owncloudTestUtil/build.gradle | 2 +- .../com/owncloud/android/testutil/OCSpace.kt | 7 +- 21 files changed, 147 insertions(+), 227 deletions(-) rename owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/{RemoteOAuthDataSourceTest.kt => OCRemoteOAuthDataSourceTest.kt} (98%) rename owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/{OCRemoteShareesDataSourceTest.kt => OCRemoteShareeDataSourceTest.kt} (90%) diff --git a/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt b/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt index 8b0a44b594a..5c1a679a7a4 100644 --- a/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt +++ b/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt @@ -57,7 +57,7 @@ import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH import com.owncloud.android.testutil.OC_USER_INFO import com.owncloud.android.testutil.oauth.OC_CLIENT_REGISTRATION import io.mockk.every -import io.mockk.mockkClass +import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import org.junit.Assert.assertEquals @@ -73,7 +73,7 @@ class OCLocalAuthenticationDataSourceTest { val instantExecutorRule = InstantTaskExecutorRule() private lateinit var ocLocalAuthenticationDataSource: OCLocalAuthenticationDataSource - private val accountManager = mockkClass(AccountManager::class) + private val accountManager = mockk() private val preferencesProvider = spyk() @Before diff --git a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt index 8c381895875..a0c440a856e 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCLocalAppRegistryDataSourceTest.kt @@ -2,7 +2,8 @@ * ownCloud Android client application * * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -20,7 +21,6 @@ package com.owncloud.android.data.appRegistry.datasources.implementation import androidx.arch.core.executor.testing.InstantTaskExecutorRule -import com.owncloud.android.data.OwncloudDatabase import com.owncloud.android.data.appregistry.datasources.implementation.OCLocalAppRegistryDataSource import com.owncloud.android.data.appregistry.db.AppRegistryDao import com.owncloud.android.data.appregistry.db.AppRegistryEntity @@ -29,13 +29,14 @@ import com.owncloud.android.domain.appregistry.model.AppRegistryMimeType import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_APP_REGISTRY_MIMETYPE import io.mockk.every -import io.mockk.mockkClass +import io.mockk.mockk import io.mockk.verify +import kotlinx.coroutines.flow.first import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest -import org.junit.Assert import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull import org.junit.Before import org.junit.Rule import org.junit.Test @@ -43,7 +44,7 @@ import org.junit.Test @ExperimentalCoroutinesApi class OCLocalAppRegistryDataSourceTest { private lateinit var ocLocalAppRegistryDataSource: OCLocalAppRegistryDataSource - private val appRegistryDao = mockkClass(AppRegistryDao::class) + private val appRegistryDao = mockk(relaxUnitFun = true) private val mimetype = "DIR" private val ocAppRegistryEntity = AppRegistryEntity( accountName = OC_ACCOUNT_NAME, @@ -64,12 +65,6 @@ class OCLocalAppRegistryDataSourceTest { @Before fun setUp() { - val db = mockkClass(OwncloudDatabase::class) - - every { - db.appRegistryDao() - } returns appRegistryDao - ocLocalAppRegistryDataSource = OCLocalAppRegistryDataSource( appRegistryDao, @@ -83,9 +78,8 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryForMimeTypeAsStream(OC_ACCOUNT_NAME, mimetype) - appRegistry.collect { appRegistryEmitted -> - assertEquals(OC_APP_REGISTRY_MIMETYPE, appRegistryEmitted) - } + val result = appRegistry.first() + assertEquals(OC_APP_REGISTRY_MIMETYPE, result) verify(exactly = 1) { appRegistryDao.getAppRegistryForMimeType(OC_ACCOUNT_NAME, mimetype) } } @@ -97,9 +91,9 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryForMimeTypeAsStream(OC_ACCOUNT_NAME, mimetype) - appRegistry.collect { appRegistryEmitted -> - Assert.assertNull(appRegistryEmitted) - } + val result = appRegistry.first() + assertNull(result) + verify(exactly = 1) { appRegistryDao.getAppRegistryForMimeType(OC_ACCOUNT_NAME, mimetype) } } @@ -110,9 +104,8 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryForMimeTypeAsStream(OC_ACCOUNT_NAME, mimetype) - appRegistry.collect { appRegistryEmitted -> - Assert.assertNull(appRegistryEmitted) - } + val result = appRegistry.first() + assertNull(result) verify(exactly = 1) { appRegistryDao.getAppRegistryForMimeType(OC_ACCOUNT_NAME, mimetype) } } @@ -123,9 +116,9 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) - appRegistry.collect { appRegistryEmitted -> - assertEquals(listOf(OC_APP_REGISTRY_MIMETYPE), appRegistryEmitted) - } + val result = appRegistry.first() + assertEquals(listOf(OC_APP_REGISTRY_MIMETYPE), result) + verify(exactly = 1) { appRegistryDao.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) } } @@ -137,9 +130,8 @@ class OCLocalAppRegistryDataSourceTest { val appRegistry = ocLocalAppRegistryDataSource.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) - appRegistry.collect { listEmitted -> - assertEquals(emptyList(), listEmitted) - } + val result = appRegistry.first() + assertEquals(emptyList(), result) verify(exactly = 1) { appRegistryDao.getAppRegistryWhichAllowCreation(OC_ACCOUNT_NAME) } } @@ -153,9 +145,6 @@ class OCLocalAppRegistryDataSourceTest { ) ) - every { appRegistryDao.deleteAppRegistryForAccount(OC_ACCOUNT_NAME) } returns Unit - every { appRegistryDao.upsertAppRegistries(any()) } returns Unit - ocLocalAppRegistryDataSource.saveAppRegistryForAccount(appRegistry) verify(exactly = 1) { appRegistryDao.deleteAppRegistryForAccount(appRegistry.accountName) } @@ -183,11 +172,8 @@ class OCLocalAppRegistryDataSourceTest { @Test fun `deleteAppRegistryForAccount should delete appRegistry`() = runTest { - every { appRegistryDao.deleteAppRegistryForAccount(OC_ACCOUNT_NAME) } returns Unit - ocLocalAppRegistryDataSource.deleteAppRegistryForAccount(OC_ACCOUNT_NAME) verify(exactly = 1) { appRegistryDao.deleteAppRegistryForAccount(any()) } } - -} \ No newline at end of file +} diff --git a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt index 1890d7a70d4..58f3afb5378 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/appRegistry/datasources/implementation/OCRemoteAppRegistryDataSourceTest.kt @@ -1,9 +1,9 @@ -package com.owncloud.android.data.appRegistry.datasources.implementation /** * ownCloud Android client application * * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -18,6 +18,8 @@ package com.owncloud.android.data.appRegistry.datasources.implementation * along with this program. If not, see . */ +package com.owncloud.android.data.appRegistry.datasources.implementation + import com.owncloud.android.data.ClientManager import com.owncloud.android.data.appregistry.datasources.implementation.OCRemoteAppRegistryDataSource import com.owncloud.android.domain.appregistry.model.AppRegistry @@ -181,4 +183,4 @@ class OCRemoteAppRegistryDataSourceTest { filename = OC_FILE.fileName, ) } -} \ No newline at end of file +} diff --git a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt index 7ed7188b798..0815ea54ddb 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCLocalCapabilitiesDataSourceTest.kt @@ -4,7 +4,8 @@ * @author David González Verdugo * @author Abel García de Prada * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt index c8ec2589ddc..9166595be94 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/capabilities/datasources/OCRemoteCapabilitiesDataSourceTest.kt @@ -4,7 +4,8 @@ * @author David González Verdugo * @author Jesús Recio * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt index 707786b1d50..2d20f53449b 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCLocalFileDataSourceTest.kt @@ -3,7 +3,8 @@ * * @author Abel García de Prada * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt index 7ff69ccca95..3ab938da6cc 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/file/datasources/OCRemoteFileDataSourceTest.kt @@ -3,7 +3,8 @@ * * @author Abel García de Prada * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt index 6d10a980b05..f14b1b21cdf 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt @@ -63,7 +63,7 @@ class OCFolderBackupLocalDataSourceTest { } @Test - fun `getCameraUploadsConfiguration returns null when there are not configurations `() { + fun `getCameraUploadsConfiguration returns null when there are not configurations`() { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns null every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns null @@ -78,7 +78,7 @@ class OCFolderBackupLocalDataSourceTest { } @Test - fun `getFolderBackupConfigurationByNameAsFlow returns a flow of CameraUploadsConfiguration when having valid configurations `() = runBlocking { + fun `getFolderBackupConfigurationByNameAsFlow returns a flow of CameraUploadsConfiguration when having valid configurations`() = runBlocking { every { folderBackupDao.getFolderBackUpConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) } returns flowOf( OC_BACKUP_ENTITY ) @@ -94,7 +94,7 @@ class OCFolderBackupLocalDataSourceTest { } @Test - fun `saveFolderBackupConfiguration with valid configurations save the information`() { + fun `saveFolderBackupConfiguration with valid configurations saves the information`() { ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(OC_BACKUP) verify(exactly = 1) { @@ -103,11 +103,11 @@ class OCFolderBackupLocalDataSourceTest { } @Test - fun `resetFolderBackupConfigurationByName when folder backup configuration is reset by name`() { + fun `resetFolderBackupConfigurationByName removes current folder backup configuration`() { ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) verify(exactly = 1) { folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) } } -} \ No newline at end of file +} diff --git a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/OCRemoteOAuthDataSourceTest.kt similarity index 98% rename from owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt rename to owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/OCRemoteOAuthDataSourceTest.kt index efac83b6f79..3c3dc706082 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/RemoteOAuthDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/oauth/datasources/OCRemoteOAuthDataSourceTest.kt @@ -45,7 +45,7 @@ import org.junit.Assert.assertNotNull import org.junit.Before import org.junit.Test -class RemoteOAuthDataSourceTest { +class OCRemoteOAuthDataSourceTest { private lateinit var remoteOAuthDataSource: RemoteOAuthDataSource private val clientManager: ClientManager = mockk(relaxed = true) @@ -118,7 +118,7 @@ class RemoteOAuthDataSourceTest { assertEquals(OC_CLIENT_REGISTRATION, clientRegistrationInfo) verify(exactly = 1) { - clientManager.getClientForAnonymousCredentials(OC_CLIENT_REGISTRATION_REQUEST.registrationEndpoint, any()) + clientManager.getClientForAnonymousCredentials(OC_CLIENT_REGISTRATION_REQUEST.registrationEndpoint, false) oidcService.registerClientWithRegistrationEndpoint(ocClientMocked, any()) } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt similarity index 90% rename from owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt rename to owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt index 39e0a2eb00c..98e481f01ed 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt @@ -2,8 +2,9 @@ * ownCloud Android client application * * @author David González Verdugo - * @author David González Verdugo - * Copyright (C) 2020 ownCloud GmbH. + * @author Aitor Ballesteros Pavón + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -42,7 +43,7 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test -class OCRemoteShareesDataSourceTest { +class OCRemoteShareeDataSourceTest { private lateinit var ocRemoteShareesDataSource: OCRemoteShareeDataSource private val ocShareeService: OCShareeService = mockk() private val clientManager: ClientManager = mockk() @@ -50,7 +51,7 @@ class OCRemoteShareesDataSourceTest { @Before fun setUp() { - every { clientManager.getShareeService(any()) } returns ocShareeService + every { clientManager.getShareeService(OC_ACCOUNT_NAME) } returns ocShareeService ocRemoteShareesDataSource = OCRemoteShareeDataSource(clientManager, RemoteShareeMapper()) @@ -62,13 +63,10 @@ class OCRemoteShareesDataSourceTest { every { ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } returns getRemoteShareesOperationResult - - // Get sharees from remote datasource - } @Test - fun `getSharees returns a list with the sharees entered as remote sharees`() { + fun `getSharees returns a list of OCSharee entered as remote sharees`() { sharees = ocRemoteShareesDataSource.getSharees( "user", 1, @@ -79,7 +77,7 @@ class OCRemoteShareesDataSourceTest { assertEquals(5, sharees.size) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @@ -101,13 +99,13 @@ class OCRemoteShareesDataSourceTest { assertTrue(sharee.isExactMatch) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @Test - fun `getSharees returns a list of OCSharee contains one user not exactly matched`() { + fun `getSharees returns a list of OCSharee when contains one user not exactly matched`() { sharees = ocRemoteShareesDataSource.getSharees( "user", 1, @@ -123,7 +121,7 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @@ -144,7 +142,7 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @@ -165,7 +163,7 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @@ -187,7 +185,7 @@ class OCRemoteShareesDataSourceTest { assertFalse(sharee.isExactMatch) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) } } @@ -214,7 +212,7 @@ class OCRemoteShareesDataSourceTest { assertTrue(emptySharees.isEmpty()) verify(exactly = 1) { - clientManager.getShareeService(any()) + clientManager.getShareeService(OC_ACCOUNT_NAME) ocShareeService.getSharees( searchString = "user2", page = 2, perPage = 32) } } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index 06261ad783f..03d1ff52e31 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -3,7 +3,8 @@ * * @author David González Verdugo * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -115,7 +116,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `getSharesAsLiveData read local private share returns a OCShare`() { + fun `getShareAsLiveData read local private share returns a OCShare`() { val privateShareAsLiveData: MutableLiveData = MutableLiveData() privateShareAsLiveData.value = privateShares.first() @@ -132,7 +133,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `insert private OCShare into repository returns a long`() { + fun `insert private OCShare saves it correctly`() { every { ocSharesDao.insertOrReplace(privateShares[0]) } returns 10 val insertedShareId = ocLocalSharesDataSource.insert( @@ -148,7 +149,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `insert list of private OCShares into repository returns a list of long`() { + fun `insert list of private OCShares saves it correctly`() { val expectedValues = listOf(1, 2) every { ocSharesDao.insertOrReplace(privateShares) } returns expectedValues @@ -163,7 +164,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `update private OCShare returns a long`() { + fun `update private OCShare changes it correctly`() { every { ocSharesDao.update(privateShares[1]) } returns 3 val updatedShareId = ocLocalSharesDataSource.update( @@ -237,7 +238,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `insert public OCShare into repository returns a long`() { + fun `insert public OCShare saves it correctly`() { every { ocSharesDao.insertOrReplace(publicShares[0]) } returns 7 val insertedShareId = ocLocalSharesDataSource.insert( @@ -254,7 +255,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `insert list of public OCShares into repository returns a list of long`() { + fun `insert list of public OCShares saves it correctly`() { val expectedValues = listOf(1, 2) every { ocSharesDao.insertOrReplace(publicShares) } returns expectedValues @@ -270,7 +271,7 @@ class OCLocalShareDataSourceTest { @Test - fun `update public OCShare returns a long`() { + fun `update public OCShare changes it correctly`() { every { ocSharesDao.update(publicShares[1]) } returns 8 val updatedShareId = ocLocalSharesDataSource.update( @@ -291,7 +292,7 @@ class OCLocalShareDataSourceTest { **************************************************************************************************************/ @Test - fun `replaceShares returns a list of long`() { + fun `replaceShares renewal shares related to a list of files`() { val expectedValues = listOf(1, 2) every { ocSharesDao.replaceShares(publicShares) } returns expectedValues @@ -305,14 +306,14 @@ class OCLocalShareDataSourceTest { } @Test - fun deleteSharesForFile() { + fun `deleteSharesForFile removes shares related to a file`() { ocLocalSharesDataSource.deleteSharesForFile("file", OC_ACCOUNT_NAME) verify(exactly = 1) { ocSharesDao.deleteSharesForFile("file", OC_ACCOUNT_NAME) } } @Test - fun `deleteShare returns a Int`() { + fun `deleteShare removes a share related to a file`() { every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } returns 1 val deletedRows = ocLocalSharesDataSource.deleteShare(OC_SHARE.remoteId) @@ -322,7 +323,7 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.deleteShare(OC_SHARE.remoteId) } } @Test - fun deleteSharesForAccount() { + fun `deleteSharesForAccount removes shares related to a file`() { ocLocalSharesDataSource.deleteSharesForAccount(OC_SHARE.accountOwner) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt index 9006b08f6b9..72eb382255f 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt @@ -4,7 +4,8 @@ * @author David González Verdugo * @author Jesús Recio * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -30,6 +31,7 @@ import com.owncloud.android.domain.sharing.shares.model.ShareType import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.shares.ShareResponse import com.owncloud.android.lib.resources.shares.services.implementation.OCShareService +import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_SHARE import com.owncloud.android.utils.createRemoteOperationResultMock import io.mockk.every @@ -96,7 +98,7 @@ class OCRemoteShareDataSourceTest { shareType = ShareType.USER, shareWith = "user", permissions = 1, - accountName = "user@server" + accountName = OC_ACCOUNT_NAME ) assertThat(privateShareAdded, notNullValue()) @@ -108,7 +110,7 @@ class OCRemoteShareDataSourceTest { assertEquals(1, privateShareAdded.permissions) verify(exactly = 1) { - clientManager.getShareService(any()) + clientManager.getShareService(OC_ACCOUNT_NAME) ocShareService.insertShare( remoteFilePath = "Photos/", shareType = com.owncloud.android.lib.resources.shares.ShareType.fromValue(ShareType.USER.value)!!, @@ -122,7 +124,7 @@ class OCRemoteShareDataSourceTest { } @Test - fun `updateShare update a private share returns OCShare`() { + fun `updateShare for private share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( ShareResponse( listOf( @@ -155,7 +157,7 @@ class OCRemoteShareDataSourceTest { val privateShareUpdated = ocRemoteShareDataSource.updateShare( remoteId = "3", permissions = 17, - accountName = "user@server" + accountName = OC_ACCOUNT_NAME ) assertThat(privateShareUpdated, notNullValue()) @@ -167,7 +169,7 @@ class OCRemoteShareDataSourceTest { assertEquals(false, privateShareUpdated.isFolder) verify(exactly = 1) { - clientManager.getShareService(any()) + clientManager.getShareService(OC_ACCOUNT_NAME) ocShareService.updateShare( remoteId = "3", name = "", @@ -218,7 +220,7 @@ class OCRemoteShareDataSourceTest { ShareType.PUBLIC_LINK, "", 1, - accountName = "user@server" + accountName = OC_ACCOUNT_NAME ) assertThat(publicShareAdded, notNullValue()) @@ -231,7 +233,7 @@ class OCRemoteShareDataSourceTest { assertEquals("http://server:port/s/112ejbhdasyd1", publicShareAdded.shareLink) verify(exactly = 1) { - clientManager.getShareService(any()) + clientManager.getShareService(OC_ACCOUNT_NAME) ocShareService.insertShare( remoteFilePath = "Photos/img1.png", shareType = com.owncloud.android.lib.resources.shares.ShareType.fromValue(ShareType.PUBLIC_LINK.value)!!, @@ -278,7 +280,7 @@ class OCRemoteShareDataSourceTest { val publicShareUpdated = ocRemoteShareDataSource.updateShare( remoteId = "3", permissions = 17, - accountName = "user@server" + accountName = OC_ACCOUNT_NAME ) assertThat(publicShareUpdated, notNullValue()) @@ -291,7 +293,7 @@ class OCRemoteShareDataSourceTest { assertEquals("http://server:port/s/1275farv", publicShareUpdated.shareLink) verify(exactly = 1) { - clientManager.getShareService(any()) + clientManager.getShareService(OC_ACCOUNT_NAME) ocShareService.updateShare( remoteId = "3", name = "", @@ -357,7 +359,7 @@ class OCRemoteShareDataSourceTest { remoteFilePath = "/Documents/doc", reshares = true, subfiles = true, - accountName = "user@server" + accountName = OC_ACCOUNT_NAME ) assertEquals(4, shares.size) @@ -391,7 +393,7 @@ class OCRemoteShareDataSourceTest { assertEquals("My family", groupShare.sharedWithDisplayName) verify(exactly = 1) { - clientManager.getShareService(any()) + clientManager.getShareService(OC_ACCOUNT_NAME) ocShareService.getShares( remoteFilePath = "/Documents/doc", reshares = true, @@ -427,7 +429,7 @@ class OCRemoteShareDataSourceTest { ShareType.PUBLIC_LINK, "", 1, - accountName = "user@server" + accountName = OC_ACCOUNT_NAME ) } @@ -461,7 +463,7 @@ class OCRemoteShareDataSourceTest { } @Test - fun `deleteShare delete a share returns unit`() { + fun `deleteShare remove a share correctly`() { val removeRemoteShareOperationResult = createRemoteOperationResultMock( Unit, isSuccess = true diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt index de37b4b0c35..cf2d515e156 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt @@ -2,7 +2,8 @@ * ownCloud Android client application * * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -30,12 +31,14 @@ import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARE import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_SPACE_PERSONAL import com.owncloud.android.testutil.OC_SPACE_PROJECT_WITH_IMAGE -import com.owncloud.android.testutil.SPACE_WITH_SPECIALS +import com.owncloud.android.testutil.SPACE_ENTITY_WITH_SPECIALS +import com.owncloud.android.testutil.WEB_DAV_URL import io.mockk.Runs import io.mockk.every import io.mockk.just import io.mockk.mockk import io.mockk.verify +import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals @@ -47,8 +50,6 @@ class OCLocalSpacesDataSourceTest { private lateinit var ocLocalSpacesDataSource: OCLocalSpacesDataSource private val spacesDao = mockk() - private val WEB_DAV_URL = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9" - @Before fun setUp() { ocLocalSpacesDataSource = OCLocalSpacesDataSource(spacesDao) @@ -96,11 +97,11 @@ class OCLocalSpacesDataSourceTest { fun `getSharesSpaceForAccount returns a OCSpace`() { every { spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) - } returns SPACE_WITH_SPECIALS.space + } returns SPACE_ENTITY_WITH_SPECIALS.space val resultActual = ocLocalSpacesDataSource.getSharesSpaceForAccount(OC_ACCOUNT_NAME) - assertEquals(SPACE_WITH_SPECIALS.space.toModel(), resultActual) + assertEquals(SPACE_ENTITY_WITH_SPECIALS.space.toModel(), resultActual) verify(exactly = 1) { spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) @@ -119,11 +120,9 @@ class OCLocalSpacesDataSourceTest { ) } returns flowOf(listOf(OC_SPACE_PERSONAL.toEntity())) - val resultActual = ocLocalSpacesDataSource.getSpacesFromEveryAccountAsStream() + val resultActual = ocLocalSpacesDataSource.getSpacesFromEveryAccountAsStream().first() - resultActual.collect { result -> - assertEquals(listOf(OC_SPACE_PERSONAL), result) - } + assertEquals(listOf(OC_SPACE_PERSONAL), resultActual) verify(exactly = 1) { spacesDao.getSpacesByDriveTypeFromEveryAccountAsStream( @@ -146,7 +145,7 @@ class OCLocalSpacesDataSourceTest { OCSpace.DRIVE_TYPE_PROJECT ) ) - } returns flowOf(listOf(SPACE_WITH_SPECIALS)) + } returns flowOf(listOf(SPACE_ENTITY_WITH_SPECIALS)) val resultActual = ocLocalSpacesDataSource.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( OC_ACCOUNT_NAME, setOf( @@ -155,9 +154,9 @@ class OCLocalSpacesDataSourceTest { ) ) - resultActual.collect { result -> - assertEquals(listOf(SPACE_WITH_SPECIALS.toModel()), result) - } + val result = resultActual.first() + assertEquals(listOf(SPACE_ENTITY_WITH_SPECIALS.toModel()), result) + verify(exactly = 1) { spacesDao.getSpacesByDriveTypeWithSpecialsForAccountAsFlow( @@ -204,11 +203,11 @@ class OCLocalSpacesDataSourceTest { every { spacesDao.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - } returns SPACE_WITH_SPECIALS + } returns SPACE_ENTITY_WITH_SPECIALS val resultActual = ocLocalSpacesDataSource.getSpaceWithSpecialsByIdForAccount(OC_SPACE_PERSONAL.id, OC_ACCOUNT_NAME) - assertEquals(SPACE_WITH_SPECIALS.toModel(), resultActual) + assertEquals(SPACE_ENTITY_WITH_SPECIALS.toModel(), resultActual) verify(exactly = 1) { spacesDao.getSpaceWithSpecialsByIdForAccount( diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt index 223d24a9760..1e41e0d0263 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCRemoteSpacesDataSourceTest.kt @@ -2,7 +2,8 @@ * ownCloud Android client application * * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -65,4 +66,4 @@ class OCRemoteSpacesDataSourceTest { ocSpaceService.getSpaces() } } -} \ No newline at end of file +} diff --git a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt index c6daa0c5131..8328efec9d6 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt @@ -2,7 +2,8 @@ * ownCloud Android client application * * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -20,7 +21,6 @@ package com.owncloud.android.data.transfers.implementation -import com.owncloud.android.data.OwncloudDatabase import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource.Companion.toEntity import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource.Companion.toModel @@ -33,7 +33,7 @@ import com.owncloud.android.domain.transfers.model.TransferStatus import com.owncloud.android.domain.transfers.model.UploadEnqueuedBy import com.owncloud.android.testutil.OC_ACCOUNT_NAME import io.mockk.every -import io.mockk.mockkClass +import io.mockk.mockk import io.mockk.verify import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.flowOf @@ -44,8 +44,8 @@ import org.junit.Test class OCLocalTransferDataSourceTest { private lateinit var ocLocalTransferDataSource: OCLocalTransferDataSource - private val transferDao = mockkClass(TransferDao::class) - private val id = -1L + private val transferDao = mockk(relaxUnitFun = true) + private val id = 0L private val ocTransfer = OCTransfer( id = id, localPath = "/local/path", @@ -62,15 +62,12 @@ class OCLocalTransferDataSourceTest { @Before fun setUp() { - val db = mockkClass(OwncloudDatabase::class) - - every { db.transferDao() } returns transferDao ocLocalTransferDataSource = OCLocalTransferDataSource(transferDao) } @Test - fun `saveTransfer returns a Long`() { + fun `saveTransfer inserts it correctly`() { val resultExpected = 1L every { transferDao.insertOrReplace(any()) @@ -86,7 +83,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun `updateTransfer returns a Long`() { + fun `updateTransfer changes it correctly`() { val resultExpected = 1L every { transferDao.insertOrReplace(any()) @@ -100,11 +97,8 @@ class OCLocalTransferDataSourceTest { } @Test - fun updateTransferStatusToInProgressById() { + fun `updateTransferStatusToInProgressById changes transfer status correctly`() { val resultExpected = 10L - every { - transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_IN_PROGRESS.value) - } returns Unit ocLocalTransferDataSource.updateTransferStatusToInProgressById(resultExpected) @@ -114,11 +108,8 @@ class OCLocalTransferDataSourceTest { } @Test - fun updateTransferStatusToEnqueuedById() { + fun `updateTransferStatusToEnqueuedById changes transfer status correctly`() { val resultExpected = 10L - every { - transferDao.updateTransferStatusWithId(resultExpected, TransferStatus.TRANSFER_QUEUED.value) - } returns Unit ocLocalTransferDataSource.updateTransferStatusToEnqueuedById(resultExpected) @@ -128,11 +119,8 @@ class OCLocalTransferDataSourceTest { } @Test - fun updateTransferWhenFinished() { + fun `updateTransferWhenFinished changes transfer status correctly`() { val timestamp = System.currentTimeMillis() - every { - transferDao.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED.value, timestamp, TransferResult.UPLOADED.value) - } returns Unit ocLocalTransferDataSource.updateTransferWhenFinished(id, TransferStatus.TRANSFER_SUCCEEDED, timestamp, TransferResult.UPLOADED) @@ -142,10 +130,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun updateTransferLocalPath() { - every { - transferDao.updateTransferLocalPath(id, ocTransfer.localPath) - } returns Unit + fun `updateTransferLocalPath changes transfer local path correctly` () { ocLocalTransferDataSource.updateTransferLocalPath(id, ocTransfer.localPath) @@ -155,14 +140,10 @@ class OCLocalTransferDataSourceTest { } @Test - fun updateTransferStorageDirectoryInLocalPath() { + fun `updateTransferStorageDirectoryInLocalPath changes directory correctly`() { val oldDirectory = "oldDirectory" val newDirectory = "newDirectory" - every { - transferDao.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) - } returns Unit - ocLocalTransferDataSource.updateTransferStorageDirectoryInLocalPath(id, oldDirectory, newDirectory) verify(exactly = 1) { @@ -171,10 +152,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun deleteTransferById() { - every { - transferDao.deleteTransferWithId(id) - } returns Unit + fun `deleteTransferById removes it correctly`() { ocLocalTransferDataSource.deleteTransferById(id) @@ -184,10 +162,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun deleteAllTransfersFromAccount() { - every { - transferDao.deleteTransfersWithAccountName(OC_ACCOUNT_NAME) - } returns Unit + fun `deleteAllTransfersFromAccount removes all transfers correctly`() { ocLocalTransferDataSource.deleteAllTransfersFromAccount(OC_ACCOUNT_NAME) @@ -228,19 +203,15 @@ class OCLocalTransferDataSourceTest { } @Test - fun `getAllTransfersAsStream returns a flow of list of OCTransfer with transferStatus in progress`() = runBlocking { + fun `getAllTransfersAsStream returns a flow of list of OCTransfer ordered by status`() = runBlocking { - val transferEntityInProgress: OCTransferEntity = ocTransfer.toEntity() - transferEntityInProgress.status = 0 + val transferEntityInProgress: OCTransferEntity = ocTransfer.toEntity().copy(status = 0) - val transferEntityQueue: OCTransferEntity = ocTransfer.toEntity() - transferEntityQueue.status = 1 + val transferEntityQueue: OCTransferEntity = ocTransfer.toEntity().copy(status = 1) - val transferEntityFailed: OCTransferEntity = ocTransfer.toEntity() - transferEntityFailed.status = 2 + val transferEntityFailed: OCTransferEntity = ocTransfer.toEntity().copy(status = 2) - val transferEntitySucceeded: OCTransferEntity = ocTransfer.toEntity() - transferEntitySucceeded.status = 3 + val transferEntitySucceeded: OCTransferEntity = ocTransfer.toEntity().copy(status = 3) val transferListRandom = listOf(transferEntityQueue, transferEntityFailed, transferEntityInProgress, transferEntitySucceeded) @@ -261,9 +232,8 @@ class OCLocalTransferDataSourceTest { } returns flowOf(transferListRandom) val actualResult = ocLocalTransferDataSource.getAllTransfersAsStream().first().map { it } - val expectedStatusList = transferListOrdered.map { it } - assertEquals(expectedStatusList, actualResult) + assertEquals(transferListOrdered, actualResult) verify(exactly = 1) { transferDao.getAllTransfersAsStream() @@ -336,11 +306,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun `clearFailedTransfers returns unit`() { - - every { - transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_FAILED.value) - } returns Unit + fun `clearFailedTransfers clears it correctly`() { ocLocalTransferDataSource.clearFailedTransfers() @@ -350,11 +316,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun clearSuccessfulTransfers() { - - every { - transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) - } returns Unit + fun `clearSuccessfulTransfers clears it correctly`() { ocLocalTransferDataSource.clearSuccessfulTransfers() @@ -362,4 +324,4 @@ class OCLocalTransferDataSourceTest { transferDao.deleteTransfersWithStatus(TransferStatus.TRANSFER_SUCCEEDED.value) } } -} \ No newline at end of file +} diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt index 024f04f59f1..4fc5b78ccc1 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt @@ -3,7 +3,8 @@ * * @author Abel García de Prada * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -99,7 +100,7 @@ class OCLocalUserDataSourceTest { } @Test - fun `getAllUserQuotas returns a UserQuote List`() { + fun `getAllUserQuotas returns a list of UserQuote`() { every { ocUserQuotaDao.getAllUserQuotas() } returns listOf(userQuotaEntity) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt index 2916b3732f0..31f481931ad 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCRemoteUserDataSourceTest.kt @@ -91,16 +91,6 @@ class OCRemoteUserDataSourceTest { verify(exactly = 1) { ocUserService.getUserInfo() } } - @Test(expected = Exception::class) - fun `getUserInfo returns an exception when service receive a exception`() { - - every { - ocUserService.getUserInfo() - } throws Exception() - - ocRemoteUserDataSource.getUserInfo(OC_ACCOUNT_NAME) - } - @Test fun `getUserQuota returns UserQuota`() { val getUserQuotaResult: RemoteOperationResult = @@ -118,15 +108,6 @@ class OCRemoteUserDataSourceTest { verify(exactly = 1) { ocUserService.getUserQuota() } } - @Test(expected = Exception::class) - fun `getUserQuota returns an exception when service receive an exception`() { - every { - ocUserService.getUserQuota() - } throws Exception() - - ocRemoteUserDataSource.getUserQuota(OC_ACCOUNT_NAME) - } - @Test fun `getUserAvatar returns UserAvatar`() { val getUserAvatarResult: RemoteOperationResult = @@ -143,13 +124,5 @@ class OCRemoteUserDataSourceTest { verify(exactly = 1) { ocUserService.getUserAvatar(avatarDimension) } } - - @Test(expected = Exception::class) - fun `getUserAvatar returns an exception when service receive exception`() { - every { - ocUserService.getUserAvatar(avatarDimension) - } throws Exception() - - ocRemoteUserDataSource.getUserAvatar(OC_ACCOUNT_NAME) - } } + diff --git a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt index 7fd70c08419..885a93819ba 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt @@ -2,7 +2,8 @@ * ownCloud Android client application * * @author Aitor Ballesteros Pavón - * Copyright (C) 2020 ownCloud GmbH. + * + * Copyright (C) 2023 ownCloud GmbH. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@ -43,7 +44,11 @@ class OCRemoteWebFingerDatasourceTest { private val clientManager: ClientManager = mockk(relaxed = true) private val ownCloudClient: OwnCloudClient = mockk(relaxed = true) private val ocWebFingerService: OCWebFingerService = mockk() - private val listString: List = emptyList() + private val listString: List = listOf( + "http://webfinger.owncloud/tests/server-instance1", + "http://webfinger.owncloud/tests/server-instance2", + "http://webfinger.owncloud/tests/server-instance3", + ) @Before fun setUp() { @@ -126,4 +131,4 @@ class OCRemoteWebFingerDatasourceTest { ) } } -} \ No newline at end of file +} diff --git a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/GetFileWithSyncInfoByIdUseCaseTest.kt b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/GetFileWithSyncInfoByIdUseCaseTest.kt index 03af700a4fc..eb4beed3cb1 100644 --- a/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/GetFileWithSyncInfoByIdUseCaseTest.kt +++ b/owncloudDomain/src/test/java/com/owncloud/android/domain/files/usecases/GetFileWithSyncInfoByIdUseCaseTest.kt @@ -6,6 +6,7 @@ import com.owncloud.android.testutil.OC_FILE_WITH_SYNC_INFO_AND_SPACE import io.mockk.every import io.mockk.spyk import io.mockk.verify +import kotlinx.coroutines.flow.first import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest @@ -20,20 +21,18 @@ class GetFileWithSyncInfoByIdUseCaseTest { private val useCaseParams = GetFileWithSyncInfoByIdUseCase.Params(OC_FILE.id!!) @Test - fun `get file with sync by id returns OCFileWithSyncInfo when no error`() = runTest { + fun `getFileWithSyncInfoByIdAsFlow returns OCFileWithSyncInfo when no error`() = runTest { every { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } returns flowOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE) - val useCaseResult = useCase(useCaseParams) + val useCaseResult = useCase(useCaseParams).first() - useCaseResult.collect { result -> - Assert.assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, result) - } + Assert.assertEquals(OC_FILE_WITH_SYNC_INFO_AND_SPACE, useCaseResult) verify(exactly = 1) { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } } @Test - fun `get file with sync by id returns true when repository is null`() = runTest { + fun `getFileWithSyncInfoByIdAsFlow returns true when repository is null`() = runTest { val useCaseResult = useCase(useCaseParams) every { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } returns flowOf(null) @@ -41,16 +40,4 @@ class GetFileWithSyncInfoByIdUseCaseTest { verify(exactly = 1) { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } } - - @Test(expected = Exception::class) - fun `get file with sync by id returns an exception`() = runTest { - every { repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) } throws Exception() - - useCase(useCaseParams) - - verify(exactly = 1) { - repository.getFileWithSyncInfoByIdAsFlow(useCaseParams.fileId) - } - } - -} \ No newline at end of file +} diff --git a/owncloudTestUtil/build.gradle b/owncloudTestUtil/build.gradle index 961796bd4e5..3d67e667cec 100644 --- a/owncloudTestUtil/build.gradle +++ b/owncloudTestUtil/build.gradle @@ -20,8 +20,8 @@ android { dependencies { implementation project(':owncloudDomain') + implementation project(':owncloudData') implementation project(':owncloudComLibrary') - implementation project(path: ':owncloudData') implementation libs.kotlin.stdlib implementation libs.androidx.lifecycle.livedata.ktx } diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt index ca152338740..e098de721ae 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt @@ -37,7 +37,7 @@ import com.owncloud.android.lib.resources.spaces.responses.QuotaResponse import com.owncloud.android.lib.resources.spaces.responses.RootResponse import com.owncloud.android.lib.resources.spaces.responses.SpaceResponse -private val WEB_DAV_URL = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9" +const val WEB_DAV_URL = "https://server.url/dav/spaces/8871f4f3-fc6f-4a66-8bed-62f175f76f3805bca744-d89f-4e9c-a990-25a0d7f03fe9" @@ -142,7 +142,7 @@ val OC_SPACE_PROJECT_DISABLED = OC_SPACE_PROJECT_WITH_IMAGE.copy( special = null ) -val SPACE_WITH_SPECIALS = SpacesWithSpecials( +val SPACE_ENTITY_WITH_SPECIALS = SpacesWithSpecials( SpacesEntity( accountName = OC_ACCOUNT_NAME, driveAlias = "driveAlias", @@ -200,5 +200,4 @@ val SPACE_RESPONSE = used = 1 ), special = null, - - ) \ No newline at end of file + ) From b1dd8118426b467359fcb1e409643213a7420ae4 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 9 Oct 2023 11:47:16 +0100 Subject: [PATCH 13/20] Fix from CR 2.1 --- .../OCLocalSpacesDataSourceTest.kt | 5 +-- .../com/owncloud/android/testutil/OCSpace.kt | 35 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt index cf2d515e156..227719a7afb 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/spaces/datasource/implementation/OCLocalSpacesDataSourceTest.kt @@ -31,6 +31,7 @@ import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARE import com.owncloud.android.testutil.OC_ACCOUNT_NAME import com.owncloud.android.testutil.OC_SPACE_PERSONAL import com.owncloud.android.testutil.OC_SPACE_PROJECT_WITH_IMAGE +import com.owncloud.android.testutil.SPACE_ENTITY_SHARE import com.owncloud.android.testutil.SPACE_ENTITY_WITH_SPECIALS import com.owncloud.android.testutil.WEB_DAV_URL import io.mockk.Runs @@ -97,11 +98,11 @@ class OCLocalSpacesDataSourceTest { fun `getSharesSpaceForAccount returns a OCSpace`() { every { spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) - } returns SPACE_ENTITY_WITH_SPECIALS.space + } returns SPACE_ENTITY_SHARE.space val resultActual = ocLocalSpacesDataSource.getSharesSpaceForAccount(OC_ACCOUNT_NAME) - assertEquals(SPACE_ENTITY_WITH_SPECIALS.space.toModel(), resultActual) + assertEquals(SPACE_ENTITY_SHARE.space.toModel(), resultActual) verify(exactly = 1) { spacesDao.getSpaceByIdForAccount(SPACE_ID_SHARES, OC_ACCOUNT_NAME) diff --git a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt index e098de721ae..8953a295f5d 100644 --- a/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt +++ b/owncloudTestUtil/src/main/java/com/owncloud/android/testutil/OCSpace.kt @@ -25,6 +25,7 @@ import com.owncloud.android.data.spaces.db.SpaceSpecialEntity import com.owncloud.android.data.spaces.db.SpacesEntity import com.owncloud.android.data.spaces.db.SpacesWithSpecials import com.owncloud.android.domain.spaces.model.OCSpace +import com.owncloud.android.domain.spaces.model.OCSpace.Companion.SPACE_ID_SHARES import com.owncloud.android.domain.spaces.model.SpaceDeleted import com.owncloud.android.domain.spaces.model.SpaceFile import com.owncloud.android.domain.spaces.model.SpaceOwner @@ -177,6 +178,40 @@ val SPACE_ENTITY_WITH_SPECIALS = SpacesWithSpecials( ) ) +val SPACE_ENTITY_SHARE = SpacesWithSpecials( + SpacesEntity( + accountName = OC_ACCOUNT_NAME, + driveAlias = "driveAlias", + driveType = "driveType", + id = SPACE_ID_SHARES, + ownerId = OC_CLIENT_ID, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + quota = null, + root = SpaceRootEntity( + eTag = "eTag", + id = "id", + webDavUrl = WEB_DAV_URL, + deleteState = "state" + ), + webUrl = "webUrl", + description = "description" + ), + listOf( + SpaceSpecialEntity( + accountName = OC_ACCOUNT_NAME, + eTag = "eTag", + fileMimeType = "fileMimeType", + id = OC_ACCOUNT_ID, + spaceId = OC_SPACE_PERSONAL.id, + lastModifiedDateTime = "lastModifiedDateTime", + name = "name", + webDavUrl = WEB_DAV_URL, + size = 100, + specialFolderName = OC_SPACE_SPECIAL_IMAGE.name + ) + ) +) val SPACE_RESPONSE = SpaceResponse( driveAlias = "driveAlias", From 6334b6b6a7321eef4155ff20777eaa4c535e5675 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Tue, 10 Oct 2023 09:29:27 +0100 Subject: [PATCH 14/20] Fix from CR 2.2 --- .../com/owncloud/android/data/transfers/db/OCTransferEntity.kt | 2 +- .../data/shares/datasources/OCLocalShareDataSourceTest.kt | 1 - .../transfers/implementation/OCLocalTransferDataSourceTest.kt | 1 - .../android/data/user/datasources/OCLocalUserDataSourceTest.kt | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt b/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt index c5dab107ca3..32d3da8f56e 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/transfers/db/OCTransferEntity.kt @@ -46,7 +46,7 @@ data class OCTransferEntity( val remotePath: String, val accountName: String, val fileSize: Long, - var status: Int, + val status: Int, val localBehaviour: Int, val forceOverwrite: Boolean, val transferEndTimestamp: Long? = null, diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index 03d1ff52e31..cc7ce7144a0 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -329,5 +329,4 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.deleteSharesForAccount(OC_SHARE.accountOwner) } } - } diff --git a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt index 8328efec9d6..a0605c50a44 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt @@ -18,7 +18,6 @@ * along with this program. If not, see . */ - package com.owncloud.android.data.transfers.implementation import com.owncloud.android.data.transfers.datasources.implementation.OCLocalTransferDataSource diff --git a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt index 4fc5b78ccc1..f3bb0d1e030 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/user/datasources/OCLocalUserDataSourceTest.kt @@ -104,7 +104,6 @@ class OCLocalUserDataSourceTest { every { ocUserQuotaDao.getAllUserQuotas() } returns listOf(userQuotaEntity) - val resultActual = ocLocalUserDataSource.getAllUserQuotas() assertEquals(listOf(userQuotaEntity.toModel()), resultActual) From 9bc1b428fd08f265d8a0bf9ab4b7b49486e85b04 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Wed, 11 Oct 2023 11:57:38 +0100 Subject: [PATCH 15/20] Renamed names in tests class and added relaxing mock in LocalAuthenticationDataSource --- .../OCLocalAuthenticationDataSourceTest.kt | 75 ++++--------------- .../datasources/OCLocalShareDataSourceTest.kt | 6 +- .../OCRemoteShareDataSourceTest.kt | 4 +- .../OCLocalTransferDataSourceTest.kt | 15 ++-- .../OCRemoteWebFingerDatasourceTest.kt | 6 +- 5 files changed, 28 insertions(+), 78 deletions(-) diff --git a/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt b/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt index 5c1a679a7a4..a2276af7ead 100644 --- a/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt +++ b/owncloudData/src/androidTest/java/com/owncloud/android/data/authentication/datasources/implementation/OCLocalAuthenticationDataSourceTest.kt @@ -73,7 +73,7 @@ class OCLocalAuthenticationDataSourceTest { val instantExecutorRule = InstantTaskExecutorRule() private lateinit var ocLocalAuthenticationDataSource: OCLocalAuthenticationDataSource - private val accountManager = mockk() + private val accountManager = mockk(relaxUnitFun = true) private val preferencesProvider = spyk() @Before @@ -86,6 +86,13 @@ class OCLocalAuthenticationDataSourceTest { preferencesProvider, OC_ACCOUNT.type ) + getAccountsByType(OC_ACCOUNT.type, arrayOf(OC_ACCOUNT)) + } + + private fun getAccountsByType(accountType: String, accounts: Array) { + every { + accountManager.getAccountsByType(accountType) + } returns accounts } @Test @@ -102,7 +109,7 @@ class OCLocalAuthenticationDataSourceTest { null ) - val newAccount = Account(OC_ACCOUNT_NAME, "owncloud") + val newAccount = Account(OC_ACCOUNT_NAME, OC_ACCOUNT.type) // One for checking if the account exists and another one for getting the new account verifyAccountsByTypeAreGot(newAccount.type, 2) @@ -115,9 +122,6 @@ class OCLocalAuthenticationDataSourceTest { @Test(expected = AccountNotNewException::class) fun addBasicAccountAlreadyExistsNoUpdate() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf(OC_ACCOUNT) // The account is already there ocLocalAuthenticationDataSource.addBasicAccount( OC_ACCOUNT_ID, @@ -131,17 +135,6 @@ class OCLocalAuthenticationDataSourceTest { @Test fun addBasicAccountAlreadyExistsUpdateSameUsername() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf(OC_ACCOUNT) // The account is already there - - every { - accountManager.setPassword(any(), any()) - } returns Unit - - every { - accountManager.setUserData(any(), any(), any()) - } returns Unit mockSelectedAccountNameInPreferences() @@ -167,10 +160,6 @@ class OCLocalAuthenticationDataSourceTest { @Test fun addBasicAccountAlreadyExistsUpdateDifferentUsername() { - every { - accountManager.setUserData(any(), any(), any()) - } returns Unit - mockSelectedAccountNameInPreferences() try { @@ -198,10 +187,6 @@ class OCLocalAuthenticationDataSourceTest { mockRegularAccountCreationFlow() mockSelectedAccountNameInPreferences() - every { - accountManager.setAuthToken(any(), any(), any()) - } returns Unit - val newAccountName = ocLocalAuthenticationDataSource.addOAuthAccount( OC_ACCOUNT_ID, OC_REDIRECTION_PATH.lastPermanentLocation, @@ -215,7 +200,7 @@ class OCLocalAuthenticationDataSourceTest { OC_CLIENT_REGISTRATION ) - val newAccount = Account(OC_ACCOUNT_NAME, "owncloud") + val newAccount = Account(OC_ACCOUNT_NAME, OC_ACCOUNT.type) // One for checking if the account exists and another one for getting the new account verifyAccountsByTypeAreGot(newAccount.type, 2) @@ -231,9 +216,6 @@ class OCLocalAuthenticationDataSourceTest { @Test(expected = AccountNotNewException::class) fun addOAuthAccountAlreadyExistsNoUpdate() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf(OC_ACCOUNT) // The account is already there ocLocalAuthenticationDataSource.addOAuthAccount( OC_ACCOUNT_ID, @@ -251,17 +233,6 @@ class OCLocalAuthenticationDataSourceTest { @Test fun addOAuthAccountAlreadyExistsUpdateSameUsername() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf(OC_ACCOUNT) // The account is already there - - every { - accountManager.setUserData(any(), any(), any()) - } returns Unit - - every { - accountManager.setAuthToken(any(), any(), any()) - } returns Unit mockSelectedAccountNameInPreferences() @@ -292,14 +263,6 @@ class OCLocalAuthenticationDataSourceTest { @Test fun addOAuthAccountAlreadyExistsUpdateDifferentUsername() { - every { - accountManager.setUserData(any(), any(), any()) - } returns Unit - - every { - accountManager.setAuthToken(any(), any(), any()) - } returns Unit - mockSelectedAccountNameInPreferences() try { @@ -337,9 +300,6 @@ class OCLocalAuthenticationDataSourceTest { @Test fun supportsOAuthOk() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf(OC_ACCOUNT) every { accountManager.getUserData(OC_ACCOUNT, KEY_SUPPORTS_OAUTH2) @@ -355,18 +315,13 @@ class OCLocalAuthenticationDataSourceTest { @Test(expected = AccountNotFoundException::class) fun supportsOAuthAccountNotFound() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf() // That account does not exist + getAccountsByType(OC_ACCOUNT.type, arrayOf())// That account does not exist ocLocalAuthenticationDataSource.supportsOAuth2(OC_ACCOUNT.name) } @Test fun getBaseUrlOk() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf(OC_ACCOUNT) every { accountManager.getUserData(OC_ACCOUNT, KEY_OC_BASE_URL) @@ -382,9 +337,7 @@ class OCLocalAuthenticationDataSourceTest { @Test(expected = AccountNotFoundException::class) fun getBaseUrlAccountNotFound() { - every { - accountManager.getAccountsByType(OC_ACCOUNT.type) - } returns arrayOf() // That account does not exist + getAccountsByType(OC_ACCOUNT.type, arrayOf()) // That account does not exist ocLocalAuthenticationDataSource.getBaseUrl(OC_ACCOUNT.name) } @@ -402,9 +355,7 @@ class OCLocalAuthenticationDataSourceTest { private fun mockRegularAccountCreationFlow() { // Step 1: Get accounts to know if the current account exists - every { - accountManager.getAccountsByType("owncloud") - } returns arrayOf() // There's no accounts yet + getAccountsByType(OC_ACCOUNT.type, arrayOf()) // There's no accounts yet // Step 2: Add new account every { diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index cc7ce7144a0..aa6e931e37b 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -292,7 +292,7 @@ class OCLocalShareDataSourceTest { **************************************************************************************************************/ @Test - fun `replaceShares renewal shares related to a list of files`() { + fun `replaceShares renewal shares related to a list of shares`() { val expectedValues = listOf(1, 2) every { ocSharesDao.replaceShares(publicShares) } returns expectedValues @@ -313,7 +313,7 @@ class OCLocalShareDataSourceTest { } @Test - fun `deleteShare removes a share related to a file`() { + fun `deleteShare removes a share correctly`() { every { ocSharesDao.deleteShare(OC_SHARE.remoteId) } returns 1 val deletedRows = ocLocalSharesDataSource.deleteShare(OC_SHARE.remoteId) @@ -323,7 +323,7 @@ class OCLocalShareDataSourceTest { verify(exactly = 1) { ocSharesDao.deleteShare(OC_SHARE.remoteId) } } @Test - fun `deleteSharesForAccount removes shares related to a file`() { + fun `deleteSharesForAccount removes shares related to an account`() { ocLocalSharesDataSource.deleteSharesForAccount(OC_SHARE.accountOwner) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt index 72eb382255f..d04a7fda183 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCRemoteShareDataSourceTest.kt @@ -247,7 +247,7 @@ class OCRemoteShareDataSourceTest { } @Test - fun `updateShare update a public share returns OCShare`() { + fun `updateShare for public share returns OCShare`() { val updateRemoteShareOperationResult = createRemoteOperationResultMock( ShareResponse( listOf( @@ -463,7 +463,7 @@ class OCRemoteShareDataSourceTest { } @Test - fun `deleteShare remove a share correctly`() { + fun `deleteShare removes a share correctly`() { val removeRemoteShareOperationResult = createRemoteOperationResultMock( Unit, isSuccess = true diff --git a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt index a0605c50a44..51408bf5c0f 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt @@ -204,17 +204,16 @@ class OCLocalTransferDataSourceTest { @Test fun `getAllTransfersAsStream returns a flow of list of OCTransfer ordered by status`() = runBlocking { - val transferEntityInProgress: OCTransferEntity = ocTransfer.toEntity().copy(status = 0) + val transferEntityInProgress: OCTransferEntity = ocTransfer.copy(status = TransferStatus.TRANSFER_IN_PROGRESS).toEntity() - val transferEntityQueue: OCTransferEntity = ocTransfer.toEntity().copy(status = 1) + val transferEntityQueue: OCTransferEntity = ocTransfer.copy(status = TransferStatus.TRANSFER_QUEUED).toEntity() - val transferEntityFailed: OCTransferEntity = ocTransfer.toEntity().copy(status = 2) + val transferEntityFailed: OCTransferEntity = ocTransfer.copy(status = TransferStatus.TRANSFER_FAILED).toEntity() - val transferEntitySucceeded: OCTransferEntity = ocTransfer.toEntity().copy(status = 3) + val transferEntitySucceeded: OCTransferEntity = ocTransfer.copy(status = TransferStatus.TRANSFER_SUCCEEDED).toEntity() val transferListRandom = listOf(transferEntityQueue, transferEntityFailed, transferEntityInProgress, transferEntitySucceeded) - val transferQueue = ocTransfer.copy() transferQueue.status = TransferStatus.TRANSFER_QUEUED @@ -230,7 +229,7 @@ class OCLocalTransferDataSourceTest { transferDao.getAllTransfersAsStream() } returns flowOf(transferListRandom) - val actualResult = ocLocalTransferDataSource.getAllTransfersAsStream().first().map { it } + val actualResult = ocLocalTransferDataSource.getAllTransfersAsStream().first() assertEquals(transferListOrdered, actualResult) @@ -305,7 +304,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun `clearFailedTransfers clears it correctly`() { + fun `clearFailedTransfers removes transfers correctly`() { ocLocalTransferDataSource.clearFailedTransfers() @@ -315,7 +314,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun `clearSuccessfulTransfers clears it correctly`() { + fun `clearSuccessfulTransfers removes transfers correctly`() { ocLocalTransferDataSource.clearSuccessfulTransfers() diff --git a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt index 885a93819ba..f6067dd9218 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/webfinger/datasource/implementation/OCRemoteWebFingerDatasourceTest.kt @@ -44,7 +44,7 @@ class OCRemoteWebFingerDatasourceTest { private val clientManager: ClientManager = mockk(relaxed = true) private val ownCloudClient: OwnCloudClient = mockk(relaxed = true) private val ocWebFingerService: OCWebFingerService = mockk() - private val listString: List = listOf( + private val urls: List = listOf( "http://webfinger.owncloud/tests/server-instance1", "http://webfinger.owncloud/tests/server-instance2", "http://webfinger.owncloud/tests/server-instance3", @@ -65,7 +65,7 @@ class OCRemoteWebFingerDatasourceTest { fun `getInstancesFromWebFinger returns a list of web finger`() { val getInstancesFromWebFingerResult: RemoteOperationResult> = - createRemoteOperationResultMock(data = listString, isSuccess = true) + createRemoteOperationResultMock(data = urls, isSuccess = true) every { ocWebFingerService.getInstancesFromWebFinger( @@ -99,7 +99,7 @@ class OCRemoteWebFingerDatasourceTest { fun `getInstancesFromAuthenticatedWebFinger returns a list of web finger`() { val getInstancesFromAuthenticatedWebFingerResult: RemoteOperationResult> = - createRemoteOperationResultMock(data = listString, isSuccess = true) + createRemoteOperationResultMock(data = urls, isSuccess = true) every { ocWebFingerService.getInstancesFromWebFinger( From 1a64be09179a6992bbad304bc55a19ee98985bcc Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 16 Oct 2023 12:44:19 +0100 Subject: [PATCH 16/20] changed name OCLocalFolderBackupDataSource --- .../LocalDataSourceModule.kt | 6 +++--- .../android/providers/FileContentProvider.kt | 8 ++++---- .../folderbackup/OCFolderBackupRepository.kt | 12 ++++++------ ...ource.kt => LocalFolderBackupDataSource.kt} | 2 +- ...rce.kt => OCLocalFolderBackupDataSource.kt} | 6 +++--- ...kt => OCLocalFolderBackupDataSourceTest.kt} | 18 +++++++++--------- .../datasources/OCLocalShareDataSourceTest.kt | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) rename owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/{FolderBackupLocalDataSource.kt => LocalFolderBackupDataSource.kt} (96%) rename owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/{OCFolderBackupLocalDataSource.kt => OCLocalFolderBackupDataSource.kt} (96%) rename owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/{OCFolderBackupLocalDataSourceTest.kt => OCLocalFolderBackupDataSourceTest.kt} (83%) diff --git a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/LocalDataSourceModule.kt b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/LocalDataSourceModule.kt index d0577d33e23..b3bda017327 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/LocalDataSourceModule.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/dependecyinjection/LocalDataSourceModule.kt @@ -34,8 +34,8 @@ import com.owncloud.android.data.capabilities.datasources.LocalCapabilitiesDataS import com.owncloud.android.data.capabilities.datasources.implementation.OCLocalCapabilitiesDataSource import com.owncloud.android.data.files.datasources.LocalFileDataSource import com.owncloud.android.data.files.datasources.implementation.OCLocalFileDataSource -import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource -import com.owncloud.android.data.folderbackup.datasources.implementation.OCFolderBackupLocalDataSource +import com.owncloud.android.data.folderbackup.datasources.LocalFolderBackupDataSource +import com.owncloud.android.data.folderbackup.datasources.implementation.OCLocalFolderBackupDataSource import com.owncloud.android.data.providers.SharedPreferencesProvider import com.owncloud.android.data.providers.implementation.OCSharedPreferencesProvider import com.owncloud.android.data.sharing.shares.datasources.LocalShareDataSource @@ -70,7 +70,7 @@ val localDataSourceModule = module { single { ScopedStorageProvider(dataFolder, androidContext()) } factory { OCLocalAuthenticationDataSource(androidContext(), get(), get(), accountType) } - factoryOf(::OCFolderBackupLocalDataSource) bind FolderBackupLocalDataSource::class + factoryOf(::OCLocalFolderBackupDataSource) bind LocalFolderBackupDataSource::class factoryOf(::OCLocalAppRegistryDataSource) bind LocalAppRegistryDataSource::class factoryOf(::OCLocalCapabilitiesDataSource) bind LocalCapabilitiesDataSource::class factoryOf(::OCLocalFileDataSource) bind LocalFileDataSource::class diff --git a/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt b/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt index 982c6619768..4c9dcfc40ac 100644 --- a/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt +++ b/owncloudApp/src/main/java/com/owncloud/android/providers/FileContentProvider.kt @@ -55,8 +55,8 @@ import com.owncloud.android.data.capabilities.datasources.implementation.OCLocal import com.owncloud.android.data.capabilities.datasources.implementation.OCLocalCapabilitiesDataSource.Companion.toModel import com.owncloud.android.data.capabilities.db.OCCapabilityEntity import com.owncloud.android.data.files.db.OCFileEntity -import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource -import com.owncloud.android.data.folderbackup.datasources.implementation.OCFolderBackupLocalDataSource +import com.owncloud.android.data.folderbackup.datasources.LocalFolderBackupDataSource +import com.owncloud.android.data.folderbackup.datasources.implementation.OCLocalFolderBackupDataSource import com.owncloud.android.data.migrations.CameraUploadsMigrationToRoom import com.owncloud.android.data.providers.SharedPreferencesProvider import com.owncloud.android.data.providers.implementation.OCSharedPreferencesProvider @@ -973,8 +973,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi val pictureUploadsConfiguration = migrationToRoom.getPictureUploadsConfigurationPreferences(pictureUploadsTimestamp) val videoUploadsConfiguration = migrationToRoom.getVideoUploadsConfigurationPreferences(videoUploadsTimestamp) - val backupLocalDataSource: FolderBackupLocalDataSource = - OCFolderBackupLocalDataSource(OwncloudDatabase.getDatabase(context!!).folderBackUpDao()) + val backupLocalDataSource: LocalFolderBackupDataSource = + OCLocalFolderBackupDataSource(OwncloudDatabase.getDatabase(context!!).folderBackUpDao()) // Insert camera uploads configuration in new database executors.diskIO().execute { pictureUploadsConfiguration?.let { backupLocalDataSource.saveFolderBackupConfiguration(it) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/OCFolderBackupRepository.kt b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/OCFolderBackupRepository.kt index 04cd065fd7f..a88c5b00659 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/OCFolderBackupRepository.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/OCFolderBackupRepository.kt @@ -18,27 +18,27 @@ */ package com.owncloud.android.data.folderbackup -import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource +import com.owncloud.android.data.folderbackup.datasources.LocalFolderBackupDataSource import com.owncloud.android.domain.camerauploads.FolderBackupRepository import com.owncloud.android.domain.camerauploads.model.CameraUploadsConfiguration import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration import kotlinx.coroutines.flow.Flow class OCFolderBackupRepository( - private val folderBackupLocalDataSource: FolderBackupLocalDataSource + private val localFolderBackupDataSource: LocalFolderBackupDataSource ) : FolderBackupRepository { override fun getCameraUploadsConfiguration(): CameraUploadsConfiguration? = - folderBackupLocalDataSource.getCameraUploadsConfiguration() + localFolderBackupDataSource.getCameraUploadsConfiguration() override fun getFolderBackupConfigurationByNameAsFlow(name: String): Flow = - folderBackupLocalDataSource.getFolderBackupConfigurationByNameAsFlow(name) + localFolderBackupDataSource.getFolderBackupConfigurationByNameAsFlow(name) override fun saveFolderBackupConfiguration(folderBackUpConfiguration: FolderBackUpConfiguration) { - folderBackupLocalDataSource.saveFolderBackupConfiguration(folderBackUpConfiguration) + localFolderBackupDataSource.saveFolderBackupConfiguration(folderBackUpConfiguration) } override fun resetFolderBackupConfigurationByName(name: String) = - folderBackupLocalDataSource.resetFolderBackupConfigurationByName(name) + localFolderBackupDataSource.resetFolderBackupConfigurationByName(name) } diff --git a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/FolderBackupLocalDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/LocalFolderBackupDataSource.kt similarity index 96% rename from owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/FolderBackupLocalDataSource.kt rename to owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/LocalFolderBackupDataSource.kt index 1efe4d6b68b..fcdcd1aa06f 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/FolderBackupLocalDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/LocalFolderBackupDataSource.kt @@ -22,7 +22,7 @@ import com.owncloud.android.domain.camerauploads.model.CameraUploadsConfiguratio import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration import kotlinx.coroutines.flow.Flow -interface FolderBackupLocalDataSource { +interface LocalFolderBackupDataSource { fun getCameraUploadsConfiguration(): CameraUploadsConfiguration? fun getFolderBackupConfigurationByNameAsFlow(name: String): Flow diff --git a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCLocalFolderBackupDataSource.kt similarity index 96% rename from owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt rename to owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCLocalFolderBackupDataSource.kt index a28bbf8b143..5af4e0a5e18 100644 --- a/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSource.kt +++ b/owncloudData/src/main/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCLocalFolderBackupDataSource.kt @@ -19,7 +19,7 @@ package com.owncloud.android.data.folderbackup.datasources.implementation import androidx.annotation.VisibleForTesting -import com.owncloud.android.data.folderbackup.datasources.FolderBackupLocalDataSource +import com.owncloud.android.data.folderbackup.datasources.LocalFolderBackupDataSource import com.owncloud.android.data.folderbackup.db.FolderBackUpEntity import com.owncloud.android.data.folderbackup.db.FolderBackupDao import com.owncloud.android.domain.camerauploads.model.CameraUploadsConfiguration @@ -30,9 +30,9 @@ import com.owncloud.android.domain.camerauploads.model.UploadBehavior import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map -class OCFolderBackupLocalDataSource( +class OCLocalFolderBackupDataSource( private val folderBackupDao: FolderBackupDao, -) : FolderBackupLocalDataSource { +) : LocalFolderBackupDataSource { override fun getCameraUploadsConfiguration(): CameraUploadsConfiguration? { val pictureUploadsConfiguration = folderBackupDao.getFolderBackUpConfigurationByName(pictureUploadsName) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCLocalFolderBackupDataSourceTest.kt similarity index 83% rename from owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt rename to owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCLocalFolderBackupDataSourceTest.kt index f14b1b21cdf..487594e6b23 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCFolderBackupLocalDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/folderbackup/datasources/implementation/OCLocalFolderBackupDataSourceTest.kt @@ -20,7 +20,7 @@ package com.owncloud.android.data.folderbackup.datasources.implementation -import com.owncloud.android.data.folderbackup.datasources.implementation.OCFolderBackupLocalDataSource.Companion.toModel +import com.owncloud.android.data.folderbackup.datasources.implementation.OCLocalFolderBackupDataSource.Companion.toModel import com.owncloud.android.data.folderbackup.db.FolderBackupDao import com.owncloud.android.domain.camerauploads.model.FolderBackUpConfiguration import com.owncloud.android.testutil.OC_BACKUP @@ -36,14 +36,14 @@ import kotlinx.coroutines.runBlocking import org.junit.Before import org.junit.Test -class OCFolderBackupLocalDataSourceTest { +class OCLocalFolderBackupDataSourceTest { - private lateinit var ocFolderBackupLocalDataSource: OCFolderBackupLocalDataSource + private lateinit var mOcLocalFolderBackupDataSource: OCLocalFolderBackupDataSource private val folderBackupDao = mockk(relaxed = true) @Before fun setUp() { - ocFolderBackupLocalDataSource = OCFolderBackupLocalDataSource(folderBackupDao) + mOcLocalFolderBackupDataSource = OCLocalFolderBackupDataSource(folderBackupDao) } @Test @@ -51,7 +51,7 @@ class OCFolderBackupLocalDataSourceTest { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns OC_BACKUP_ENTITY every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns OC_BACKUP_ENTITY - val resultCurrent = ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() + val resultCurrent = mOcLocalFolderBackupDataSource.getCameraUploadsConfiguration() assertEquals(OC_BACKUP_ENTITY.toModel(), resultCurrent?.pictureUploadsConfiguration) assertEquals(OC_BACKUP_ENTITY.toModel(), resultCurrent?.videoUploadsConfiguration) @@ -67,7 +67,7 @@ class OCFolderBackupLocalDataSourceTest { every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) } returns null every { folderBackupDao.getFolderBackUpConfigurationByName(FolderBackUpConfiguration.videoUploadsName) } returns null - val resultCurrent = ocFolderBackupLocalDataSource.getCameraUploadsConfiguration() + val resultCurrent = mOcLocalFolderBackupDataSource.getCameraUploadsConfiguration() assertNull(resultCurrent) @@ -83,7 +83,7 @@ class OCFolderBackupLocalDataSourceTest { OC_BACKUP_ENTITY ) - val resultCurrent = ocFolderBackupLocalDataSource.getFolderBackupConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) + val resultCurrent = mOcLocalFolderBackupDataSource.getFolderBackupConfigurationByNameAsFlow(FolderBackUpConfiguration.pictureUploadsName) val result = resultCurrent.first() assertEquals(OC_BACKUP_ENTITY.toModel(), result) @@ -95,7 +95,7 @@ class OCFolderBackupLocalDataSourceTest { @Test fun `saveFolderBackupConfiguration with valid configurations saves the information`() { - ocFolderBackupLocalDataSource.saveFolderBackupConfiguration(OC_BACKUP) + mOcLocalFolderBackupDataSource.saveFolderBackupConfiguration(OC_BACKUP) verify(exactly = 1) { folderBackupDao.update(OC_BACKUP_ENTITY) @@ -104,7 +104,7 @@ class OCFolderBackupLocalDataSourceTest { @Test fun `resetFolderBackupConfigurationByName removes current folder backup configuration`() { - ocFolderBackupLocalDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) + mOcLocalFolderBackupDataSource.resetFolderBackupConfigurationByName(FolderBackUpConfiguration.pictureUploadsName) verify(exactly = 1) { folderBackupDao.delete(FolderBackUpConfiguration.pictureUploadsName) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index aa6e931e37b..ea1841b898e 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -292,7 +292,7 @@ class OCLocalShareDataSourceTest { **************************************************************************************************************/ @Test - fun `replaceShares renewal shares related to a list of shares`() { + fun `replaceShares update a list of shares correctly`() { val expectedValues = listOf(1, 2) every { ocSharesDao.replaceShares(publicShares) } returns expectedValues From 9e2b7a570f5715126108f1eb32663c496bc75aa1 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 16 Oct 2023 12:46:03 +0100 Subject: [PATCH 17/20] Add "s" --- .../data/shares/datasources/OCLocalShareDataSourceTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt index ea1841b898e..38f951a9122 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/shares/datasources/OCLocalShareDataSourceTest.kt @@ -292,7 +292,7 @@ class OCLocalShareDataSourceTest { **************************************************************************************************************/ @Test - fun `replaceShares update a list of shares correctly`() { + fun `replaceShares updates a list of shares correctly`() { val expectedValues = listOf(1, 2) every { ocSharesDao.replaceShares(publicShares) } returns expectedValues From bd3ffc6fb4a02512fba335d5ff4bf1555d18f6be Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 16 Oct 2023 12:20:22 +0000 Subject: [PATCH 18/20] Calens changelog updated --- CHANGELOG.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a119f42f93d..73ca624b120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Summary * Change - Android library as a module instead of submodule: [#3962](https://github.com/owncloud/android/issues/3962) * Enhancement - Koin DSL: [#3966](https://github.com/owncloud/android/pull/3966) +* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) * Enhancement - "Apply to all" when many name conflicts arise: [#4078](https://github.com/owncloud/android/issues/4078) * Enhancement - "Share to" in oCIS accounts allows upload to any space: [#4088](https://github.com/owncloud/android/issues/4088) * Enhancement - Use invoke operator to execute usecases: [#4179](https://github.com/owncloud/android/pull/4179) @@ -32,6 +33,17 @@ Details https://github.com/owncloud/android/pull/3966 +* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) + + Unit tests of the OCFolderBackupLocalDataSource, OCRemoteOAuthDataSource, + OCRemoteShareeDataSource, OCLocalShareDataSource, OCRemoteShareDataSource, + OCLocalSpacesDataSource, OCRemoteSpacesDataSource, OCLocalTransferDataSource, + OCLocalUserDataSource, OCRemoteUserDataSource, OCRemoteWebFingerDatasource classes + have been done and completed. + + https://github.com/owncloud/android/issues/4072 + https://github.com/owncloud/android/pull/4143 + * Enhancement - "Apply to all" when many name conflicts arise: [#4078](https://github.com/owncloud/android/issues/4078) A new dialog has been created where a checkbox has been added to be able to select all the folders @@ -117,7 +129,6 @@ Summary * Enhancement - Force security if not protected: [#4061](https://github.com/owncloud/android/issues/4061) * Enhancement - Prevent http traffic with branding options: [#4066](https://github.com/owncloud/android/issues/4066) * Enhancement - Unit tests for datasources classes - Part 2: [#4071](https://github.com/owncloud/android/issues/4071) -* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) * Enhancement - Respect app_providers_appsUrl value from capabilities: [#4075](https://github.com/owncloud/android/issues/4075) * Enhancement - Apply (1) to uploads' name conflicts: [#4079](https://github.com/owncloud/android/issues/4079) * Enhancement - Support "per app" language change on Android 13+: [#4082](https://github.com/owncloud/android/issues/4082) @@ -298,17 +309,6 @@ Details https://github.com/owncloud/android/issues/4071 https://github.com/owncloud/android/pull/4123 -* Enhancement - Unit tests for datasources classes - Part 3: [#4072](https://github.com/owncloud/android/issues/4072) - - Unit tests of the OCFolderBackupLocalDataSource, OCRemoteOAuthDataSource, - OCRemoteShareeDataSource, OCLocalShareDataSource, OCRemoteShareDataSource, - OCLocalSpacesDataSource, OCRemoteSpacesDataSource, OCLocalTransferDataSource, - OCLocalUserDataSource, OCRemoteUserDataSource, OCRemoteWebFingerDatasource classes - have been done and completed. - - https://github.com/owncloud/android/issues/4072 - https://github.com/owncloud/android/pull/4143 - * Enhancement - Respect app_providers_appsUrl value from capabilities: [#4075](https://github.com/owncloud/android/issues/4075) Now, the app receives the app_providers_appsUrl from the local database. Before of this From 8dc14be39bb5051d42b12c182ee6e5f9ad51dc88 Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 16 Oct 2023 13:29:08 +0100 Subject: [PATCH 19/20] Fix from bitrise --- .../OCRemoteShareeDataSourceTest.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt index 98e481f01ed..6ee332f9af3 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/sharees/datasources/OCRemoteShareeDataSourceTest.kt @@ -61,7 +61,7 @@ class OCRemoteShareeDataSourceTest { ) every { - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } returns getRemoteShareesOperationResult } @@ -78,7 +78,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } } @@ -100,7 +100,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } } @@ -122,7 +122,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } } @@ -143,7 +143,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } } @@ -164,7 +164,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } } @@ -186,7 +186,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user", page = 1, perPage = 30) + ocShareeService.getSharees(searchString = "user", page = 1, perPage = 30) } } @@ -198,8 +198,8 @@ class OCRemoteShareeDataSourceTest { true ) - every { - ocShareeService.getSharees( searchString = "user2", page = 2, perPage = 32) + every { + ocShareeService.getSharees(searchString = "user2", page = 2, perPage = 32) } returns getRemoteShareesOperationResult val emptySharees = ocRemoteShareesDataSource.getSharees( @@ -213,7 +213,7 @@ class OCRemoteShareeDataSourceTest { verify(exactly = 1) { clientManager.getShareeService(OC_ACCOUNT_NAME) - ocShareeService.getSharees( searchString = "user2", page = 2, perPage = 32) + ocShareeService.getSharees(searchString = "user2", page = 2, perPage = 32) } } From e0a95ae196f1438db9dd4af314df00e95acf9b1f Mon Sep 17 00:00:00 2001 From: Aitorbp Date: Mon, 16 Oct 2023 14:11:15 +0100 Subject: [PATCH 20/20] Fix from bitrise 2 --- .../implementation/OCLocalTransferDataSourceTest.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt index 51408bf5c0f..7ff2ad0a49f 100644 --- a/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt +++ b/owncloudData/src/test/java/com/owncloud/android/data/transfers/implementation/OCLocalTransferDataSourceTest.kt @@ -129,7 +129,7 @@ class OCLocalTransferDataSourceTest { } @Test - fun `updateTransferLocalPath changes transfer local path correctly` () { + fun `updateTransferLocalPath changes transfer local path correctly`() { ocLocalTransferDataSource.updateTransferLocalPath(id, ocTransfer.localPath) @@ -215,13 +215,13 @@ class OCLocalTransferDataSourceTest { val transferListRandom = listOf(transferEntityQueue, transferEntityFailed, transferEntityInProgress, transferEntitySucceeded) val transferQueue = ocTransfer.copy() - transferQueue.status = TransferStatus.TRANSFER_QUEUED + transferQueue.status = TransferStatus.TRANSFER_QUEUED val transferFailed = ocTransfer.copy() - transferFailed.status = TransferStatus.TRANSFER_FAILED + transferFailed.status = TransferStatus.TRANSFER_FAILED val transferSucceeded = ocTransfer.copy() - transferSucceeded.status = TransferStatus.TRANSFER_SUCCEEDED + transferSucceeded.status = TransferStatus.TRANSFER_SUCCEEDED val transferListOrdered = listOf(ocTransfer, transferQueue, transferFailed, transferSucceeded) @@ -238,7 +238,6 @@ class OCLocalTransferDataSourceTest { } } - @Test fun `getLastTransferFor returns a OCTransfer`() {