Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TECHNICAL] Unit tests for repository classes - Part 3 #4523

Merged
merged 15 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ownCloud admins and users.

* Change - Replace auto-uploads with automatic uploads: [#4252](https://github.com/owncloud/android/issues/4252)
* Enhancement - Unit tests for repository classes - Part 2: [#4233](https://github.com/owncloud/android/issues/4233)
* Enhancement - Unit tests for repository classes - Part 3: [#4234](https://github.com/owncloud/android/issues/4234)
* Enhancement - Add status message when (un)setting av. offline from preview: [#4382](https://github.com/owncloud/android/issues/4382)
* Enhancement - Quota improvements from GraphAPI: [#4411](https://github.com/owncloud/android/issues/4411)
* Enhancement - Upgraded AGP version to 8.7.2: [#4478](https://github.com/owncloud/android/issues/4478)
Expand All @@ -60,6 +61,15 @@ ownCloud admins and users.
https://github.com/owncloud/android/issues/4233
https://github.com/owncloud/android/pull/4389

* Enhancement - Unit tests for repository classes - Part 3: [#4234](https://github.com/owncloud/android/issues/4234)

Unit tests for OCFolderBackupRepository, OCOAuthRepository,
OCServerInfoRepository, OCShareeRepository, OCShareRepository classes have been
completed.

https://github.com/owncloud/android/issues/4234
https://github.com/owncloud/android/pull/4523

* Enhancement - Add status message when (un)setting av. offline from preview: [#4382](https://github.com/owncloud/android/issues/4382)

A message has been added in all previews when the (un)setting av. offline
Expand Down
7 changes: 7 additions & 0 deletions changelog/unreleased/4523
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Unit tests for repository classes - Part 3

Unit tests for OCFolderBackupRepository, OCOAuthRepository, OCServerInfoRepository,
OCShareeRepository, OCShareRepository classes have been completed.

https://github.com/owncloud/android/issues/4234
https://github.com/owncloud/android/pull/4523
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.owncloud.android.data.appregistry.repository.OCAppRegistryRepository
import com.owncloud.android.data.authentication.repository.OCAuthenticationRepository
import com.owncloud.android.data.capabilities.repository.OCCapabilityRepository
import com.owncloud.android.data.files.repository.OCFileRepository
import com.owncloud.android.data.folderbackup.OCFolderBackupRepository
import com.owncloud.android.data.folderbackup.repository.OCFolderBackupRepository
import com.owncloud.android.data.oauth.repository.OCOAuthRepository
import com.owncloud.android.data.server.repository.OCServerInfoRepository
import com.owncloud.android.data.sharing.sharees.repository.OCShareeRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.data.folderbackup
package com.owncloud.android.data.folderbackup.repository

import com.owncloud.android.data.folderbackup.datasources.LocalFolderBackupDataSource
import com.owncloud.android.domain.automaticuploads.FolderBackupRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* ownCloud Android client application
*
* @author Jorge Aguado Recio
*
* Copyright (C) 2024 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 <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.data.folderbackup.repository
JuancaG05 marked this conversation as resolved.
Show resolved Hide resolved

import com.owncloud.android.data.folderbackup.datasources.LocalFolderBackupDataSource
import com.owncloud.android.testutil.OC_AUTOMATIC_UPLOADS_CONFIGURATION
import com.owncloud.android.testutil.OC_BACKUP
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test

class OCFolderBackupRepositoryTest {

private val localFolderBackupDataSource = mockk<LocalFolderBackupDataSource>(relaxUnitFun = true)
private val ocFolderBackupRepository = OCFolderBackupRepository(localFolderBackupDataSource)

@Test
fun `getAutomaticUploadsConfiguration returns an AutomaticUploadsConfiguration`() {
every {
localFolderBackupDataSource.getAutomaticUploadsConfiguration()
} returns OC_AUTOMATIC_UPLOADS_CONFIGURATION

val automaticUploadsConfiguration = ocFolderBackupRepository.getAutomaticUploadsConfiguration()
assertEquals(OC_AUTOMATIC_UPLOADS_CONFIGURATION, automaticUploadsConfiguration)

verify(exactly = 1) {
localFolderBackupDataSource.getAutomaticUploadsConfiguration()
}
}

@Test
fun `getAutomaticUploadsConfiguration returns null when local datasource returns a null configuration`() {
every {
localFolderBackupDataSource.getAutomaticUploadsConfiguration()
} returns null

val automaticUploadsConfiguration = ocFolderBackupRepository.getAutomaticUploadsConfiguration()
assertNull(automaticUploadsConfiguration)

verify(exactly = 1) {
localFolderBackupDataSource.getAutomaticUploadsConfiguration()
}
}

@Test
fun `getFolderBackupConfigurationByNameAsFlow returns a Flow with a FolderBackUpConfiguration`() = runTest {
every {
localFolderBackupDataSource.getFolderBackupConfigurationByNameAsFlow(OC_BACKUP.name)
} returns flowOf(OC_BACKUP)

val folderBackUpConfiguration = ocFolderBackupRepository.getFolderBackupConfigurationByNameAsFlow(OC_BACKUP.name).first()
assertEquals(OC_BACKUP, folderBackUpConfiguration)

verify(exactly = 1) {
localFolderBackupDataSource.getFolderBackupConfigurationByNameAsFlow(OC_BACKUP.name)
}
}

@Test
fun `getFolderBackupConfigurationByNameAsFlow returns a Flow with null when local datasource returns a Flow with null `() = runTest {
every {
localFolderBackupDataSource.getFolderBackupConfigurationByNameAsFlow(OC_BACKUP.name)
} returns flowOf(null)

val folderBackUpConfiguration = ocFolderBackupRepository.getFolderBackupConfigurationByNameAsFlow(OC_BACKUP.name).first()
assertNull(folderBackUpConfiguration)

verify(exactly = 1) {
localFolderBackupDataSource.getFolderBackupConfigurationByNameAsFlow(OC_BACKUP.name)
}
}

@Test
fun `saveFolderBackupConfiguration saves a folder backup configuration correctly`() {
ocFolderBackupRepository.saveFolderBackupConfiguration(OC_BACKUP)

verify(exactly = 1) {
localFolderBackupDataSource.saveFolderBackupConfiguration(OC_BACKUP)
}
}

@Test
fun `resetFolderBackupConfigurationByName resets a folder backup configuration by name correctly`() {
ocFolderBackupRepository.resetFolderBackupConfigurationByName(OC_BACKUP.name)

verify(exactly = 1) {
localFolderBackupDataSource.resetFolderBackupConfigurationByName(OC_BACKUP.name)
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* ownCloud Android client application
*
* @author Abel García de Prada
* @author Juan Carlos Garrote Gascón
* @author Jorge Aguado Recio
*
* Copyright (C) 2024 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 <http://www.gnu.org/licenses/>.
*/

package com.owncloud.android.data.oauth.repository

import com.owncloud.android.data.oauth.datasources.RemoteOAuthDataSource
import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_OIDC_AUTH
import com.owncloud.android.testutil.oauth.OC_CLIENT_REGISTRATION
import com.owncloud.android.testutil.oauth.OC_CLIENT_REGISTRATION_REQUEST
import com.owncloud.android.testutil.oauth.OC_OIDC_SERVER_CONFIGURATION
import com.owncloud.android.testutil.oauth.OC_TOKEN_REQUEST_ACCESS
import com.owncloud.android.testutil.oauth.OC_TOKEN_RESPONSE
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Test

class OCOAuthRepositoryTest {

private val remoteOAuthDataSource = mockk<RemoteOAuthDataSource>()
private val oAuthRepository = OCOAuthRepository(remoteOAuthDataSource)

@Test
fun `performOIDCDiscovery returns an OIDCServerConfiguration`() {
every {
remoteOAuthDataSource.performOIDCDiscovery(OC_SECURE_SERVER_INFO_OIDC_AUTH.baseUrl)
} returns OC_OIDC_SERVER_CONFIGURATION

val oidcServerConfiguration = oAuthRepository.performOIDCDiscovery(OC_SECURE_SERVER_INFO_OIDC_AUTH.baseUrl)
assertEquals(OC_OIDC_SERVER_CONFIGURATION, oidcServerConfiguration)

verify(exactly = 1) {
remoteOAuthDataSource.performOIDCDiscovery(OC_SECURE_SERVER_INFO_OIDC_AUTH.baseUrl)
}
}

@Test
fun `performTokenRequest returns a TokenResponse`() {
every {
remoteOAuthDataSource.performTokenRequest(OC_TOKEN_REQUEST_ACCESS)
} returns OC_TOKEN_RESPONSE

val tokenResponse = oAuthRepository.performTokenRequest(OC_TOKEN_REQUEST_ACCESS)
assertEquals(OC_TOKEN_RESPONSE, tokenResponse)

verify(exactly = 1) {
remoteOAuthDataSource.performTokenRequest(OC_TOKEN_REQUEST_ACCESS)
}
}

@Test
fun `registerClient returns a ClientRegistrationInfo`() {
every {
remoteOAuthDataSource.registerClient(OC_CLIENT_REGISTRATION_REQUEST)
} returns OC_CLIENT_REGISTRATION

val clientRegistrationInfo = oAuthRepository.registerClient(OC_CLIENT_REGISTRATION_REQUEST)
assertEquals(OC_CLIENT_REGISTRATION, clientRegistrationInfo)

verify(exactly = 1) {
remoteOAuthDataSource.registerClient(OC_CLIENT_REGISTRATION_REQUEST)
}
}
}
Loading
Loading