Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.nextcloud.client.assistant

import com.nextcloud.client.assistant.repository.remote.AssistantRemoteRepositoryImpl
import com.nextcloud.test.SinceServer
import com.owncloud.android.AbstractOnServerIT
import com.owncloud.android.lib.resources.assistant.v2.model.TaskTypeData
import com.owncloud.android.lib.resources.status.NextcloudVersion
Expand All @@ -17,6 +18,7 @@ import org.junit.Before
import org.junit.Test

@Suppress("MagicNumber")
@SinceServer(majorVersion = 28)
class AssistantRepositoryTests : AbstractOnServerIT() {

private var sut: AssistantRemoteRepositoryImpl? = null
Expand Down
43 changes: 43 additions & 0 deletions app/src/androidTest/java/com/nextcloud/test/ServerVersionFilter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.test

import androidx.test.platform.app.InstrumentationRegistry
import org.junit.runner.Description
import org.junit.runner.manipulation.Filter

class ServerVersionFilter : Filter() {

private val serverVersion: Int? by lazy {
InstrumentationRegistry
.getArguments()
.getString(SERVER_VERSION_ARGUMENT)
?.toIntOrNull()
}

override fun shouldRun(description: Description): Boolean {
val currentVersion = serverVersion ?: return true

return when {
description.isTest -> description.requiredServerVersion() <= currentVersion
else -> description.children.any { shouldRun(it) }
}
}

override fun describe(): String = "skip tests annotated with @SinceServer above server version $serverVersion"

private fun Description.requiredServerVersion(): Int {
val onMethod = getAnnotation(SinceServer::class.java)?.majorVersion ?: ANY_SERVER
val onClass = testClass?.getAnnotation(SinceServer::class.java)?.majorVersion ?: ANY_SERVER
return maxOf(onMethod, onClass)
}

companion object {
private const val SERVER_VERSION_ARGUMENT = "TEST_SERVER_VERSION"
private const val ANY_SERVER = 0
}
}
11 changes: 11 additions & 0 deletions app/src/androidTest/java/com/nextcloud/test/SinceServer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
package com.nextcloud.test

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS)
annotation class SinceServer(val majorVersion: Int)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.nextcloud.utils

import com.nextcloud.test.SinceServer
import com.nextcloud.utils.autoRename.AutoRename
import com.owncloud.android.AbstractOnServerIT
import com.owncloud.android.datamodel.e2e.v2.decrypted.DecryptedFile
Expand All @@ -18,6 +19,7 @@ import org.junit.Before
import org.junit.Test

@Suppress("TooManyFunctions")
@SinceServer(majorVersion = 30)
class AutoRenameTests : AbstractOnServerIT() {

private var capability: OCCapability = fileDataStorageManager.getCapability(account.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.nextcloud.utils

import com.nextcloud.test.SinceServer
import com.nextcloud.utils.fileNameValidator.FileNameValidator
import com.owncloud.android.AbstractOnServerIT
import com.owncloud.android.R
Expand Down Expand Up @@ -42,6 +43,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testInvalidCharacter() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand All @@ -53,6 +55,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testReservedName() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand All @@ -61,6 +64,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testForbiddenFilenameExtension() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand Down Expand Up @@ -141,6 +145,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testFolderPathWithReservedName() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand All @@ -152,6 +157,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testFilePathWithReservedName() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand All @@ -163,6 +169,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testFolderPathWithInvalidCharacter() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand All @@ -174,6 +181,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testFilePathWithInvalidCharacter() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand Down Expand Up @@ -203,6 +211,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testFilePathWithNestedFolder() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand All @@ -222,6 +231,7 @@ class FileNameValidatorTests : AbstractOnServerIT() {
}

@Test
@SinceServer(majorVersion = 30)
fun testOnlyFolderPathWithOneReservedName() {
testOnlyOnServer(NextcloudVersion.nextcloud_30)

Expand Down
Loading
Loading