diff --git a/app/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java b/app/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java index 0631c75698..1f8a26e671 100644 --- a/app/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java +++ b/app/src/androidTest/java/com/nextcloud/client/AuthenticatorActivityIT.java @@ -20,9 +20,9 @@ package com.nextcloud.client; -import android.Manifest; import android.widget.TextView; +import com.nextcloud.test.GrantStoragePermissionRule; import com.owncloud.android.AbstractIT; import com.owncloud.android.R; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -34,8 +34,6 @@ import org.junit.rules.TestRule; import androidx.test.espresso.intent.rule.IntentsTestRule; -import static androidx.test.espresso.Espresso.onView; -import static androidx.test.espresso.action.ViewActions.typeText; import static androidx.test.espresso.matcher.ViewMatchers.withId; diff --git a/app/src/androidTest/java/com/nextcloud/client/CommunityActivityIT.java b/app/src/androidTest/java/com/nextcloud/client/CommunityActivityIT.java index 064baa344e..6027de065b 100644 --- a/app/src/androidTest/java/com/nextcloud/client/CommunityActivityIT.java +++ b/app/src/androidTest/java/com/nextcloud/client/CommunityActivityIT.java @@ -24,6 +24,7 @@ package com.nextcloud.client; import android.app.Activity; +import com.nextcloud.test.GrantStoragePermissionRule; import com.owncloud.android.AbstractIT; import com.owncloud.android.ui.activity.CommunityActivity; import com.owncloud.android.utils.ScreenshotTest; diff --git a/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java b/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java index a27ef3a4cb..d78b3d2b3f 100644 --- a/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java +++ b/app/src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java @@ -25,6 +25,7 @@ package com.nextcloud.client; import android.accounts.AccountManager; import com.nextcloud.test.RandomStringGenerator; +import com.nextcloud.test.RetryTestRule; import com.owncloud.android.AbstractOnServerIT; import com.owncloud.android.datamodel.ArbitraryDataProvider; import com.owncloud.android.datamodel.ArbitraryDataProviderImpl; diff --git a/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt b/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt index d2be2d7103..e6a54e6af4 100644 --- a/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt +++ b/app/src/androidTest/java/com/nextcloud/client/FileDisplayActivityIT.kt @@ -29,6 +29,7 @@ import androidx.test.espresso.contrib.NavigationViewActions import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.matcher.ViewMatchers import androidx.test.platform.app.InstrumentationRegistry +import com.nextcloud.test.RetryTestRule import com.owncloud.android.AbstractOnServerIT import com.owncloud.android.R import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation diff --git a/app/src/androidTest/java/com/nextcloud/client/ScreenshotTestRunner.java b/app/src/androidTest/java/com/nextcloud/client/ScreenshotTestRunner.java deleted file mode 100644 index 7ad672f9e5..0000000000 --- a/app/src/androidTest/java/com/nextcloud/client/ScreenshotTestRunner.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Nextcloud Android client application - * - * @author Tobias Kaminsky - * Copyright (C) 2019 Tobias Kaminsky - * Copyright (C) 2019 Nextcloud GmbH - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.client; - -import android.app.Application; -import android.content.Context; -import android.os.Build; -import android.os.Bundle; - -import com.facebook.testing.screenshot.ScreenshotRunner; -import com.github.tmurakami.dexopener.DexOpener; - -import com.karumi.shot.ShotTestRunner; - -public class ScreenshotTestRunner extends ShotTestRunner { - - @Override - public Application newApplication(ClassLoader cl, String className, Context context) - throws ClassNotFoundException, IllegalAccessException, InstantiationException { - - /* - * Initialize DexOpener only on API below 28 to enable mocking of Kotlin classes. - * On API 28+ the platform supports mocking natively. - */ - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { - DexOpener.install(this); - } - - return super.newApplication(cl, className, context); - } -} diff --git a/app/src/androidTest/java/com/nextcloud/client/ScreenshotTestRunner.kt b/app/src/androidTest/java/com/nextcloud/client/ScreenshotTestRunner.kt new file mode 100644 index 0000000000..66a1c07c23 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/client/ScreenshotTestRunner.kt @@ -0,0 +1,46 @@ +/* + * Nextcloud Android client application + * + * @author Tobias Kaminsky + * @author Álvaro Brey + * Copyright (C) 2019 Tobias Kaminsky + * Copyright (C) 2023 Álvaro Brey + * Copyright (C) 2023 Nextcloud GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . + * + */ +package com.nextcloud.client + +import android.app.Application +import android.app.Instrumentation +import android.content.Context +import android.os.Build +import com.github.tmurakami.dexopener.DexOpener +import com.karumi.shot.ShotTestRunner +import com.nextcloud.test.TestMainApp + +class ScreenshotTestRunner : ShotTestRunner() { + @Throws(ClassNotFoundException::class, IllegalAccessException::class, InstantiationException::class) + override fun newApplication(cl: ClassLoader, className: String, context: Context): Application { + /* + * Initialize DexOpener only on API below 28 to enable mocking of Kotlin classes. + * On API 28+ the platform supports mocking natively. + */ + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { + DexOpener.install(this) + } + return Instrumentation.newApplication(TestMainApp::class.java, context) + } +} diff --git a/app/src/androidTest/java/com/nextcloud/client/SettingsActivityIT.kt b/app/src/androidTest/java/com/nextcloud/client/SettingsActivityIT.kt index 93c0fff386..7b29b29f93 100644 --- a/app/src/androidTest/java/com/nextcloud/client/SettingsActivityIT.kt +++ b/app/src/androidTest/java/com/nextcloud/client/SettingsActivityIT.kt @@ -25,6 +25,7 @@ import android.app.Activity import android.content.Intent import android.os.Looper import androidx.test.espresso.intent.rule.IntentsTestRule +import com.nextcloud.test.GrantStoragePermissionRule import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.ArbitraryDataProviderImpl import com.owncloud.android.ui.activity.RequestCredentialsActivity diff --git a/app/src/androidTest/java/com/nextcloud/client/GrantStoragePermissionRule.kt b/app/src/androidTest/java/com/nextcloud/test/GrantStoragePermissionRule.kt similarity index 98% rename from app/src/androidTest/java/com/nextcloud/client/GrantStoragePermissionRule.kt rename to app/src/androidTest/java/com/nextcloud/test/GrantStoragePermissionRule.kt index 8b16204764..47e1cd4e31 100644 --- a/app/src/androidTest/java/com/nextcloud/client/GrantStoragePermissionRule.kt +++ b/app/src/androidTest/java/com/nextcloud/test/GrantStoragePermissionRule.kt @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -package com.nextcloud.client +package com.nextcloud.test import android.Manifest import android.os.Build diff --git a/app/src/androidTest/java/com/nextcloud/test/InjectionOverrideRule.kt b/app/src/androidTest/java/com/nextcloud/test/InjectionOverrideRule.kt new file mode 100644 index 0000000000..0d61a80ae4 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/test/InjectionOverrideRule.kt @@ -0,0 +1,44 @@ +/* + * Nextcloud Android client application + * + * @author Álvaro Brey + * Copyright (C) 2023 Álvaro Brey + * Copyright (C) 2023 Nextcloud GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . + * + */ + +package com.nextcloud.test + +import android.app.Instrumentation +import androidx.test.platform.app.InstrumentationRegistry +import dagger.android.AndroidInjector +import org.junit.rules.TestRule +import org.junit.runner.Description +import org.junit.runners.model.Statement + +class InjectionOverrideRule(private val overrideInjectors: Map, AndroidInjector<*>>) : TestRule { + override fun apply(base: Statement, description: Description): Statement = object : Statement() { + override fun evaluate() { + val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation() + val testApp = instrumentation.targetContext.applicationContext as TestMainApp + overrideInjectors.entries.forEach { + testApp.addTestInjector(it.key, it.value) + } + base.evaluate() + testApp.clearTestInjectors() + } + } +} diff --git a/app/src/androidTest/java/com/nextcloud/test/InjectionTestActivityTest.kt b/app/src/androidTest/java/com/nextcloud/test/InjectionTestActivityTest.kt new file mode 100644 index 0000000000..ff2befb266 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/test/InjectionTestActivityTest.kt @@ -0,0 +1,62 @@ +/* + * Nextcloud Android client application + * + * @author Álvaro Brey + * Copyright (C) 2023 Álvaro Brey + * Copyright (C) 2023 Nextcloud GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . + * + */ + +package com.nextcloud.test + +import androidx.test.core.app.launchActivity +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import com.nextcloud.client.preferences.AppPreferences +import com.owncloud.android.R +import dagger.android.AndroidInjector +import io.mockk.every +import io.mockk.mockk +import org.junit.Rule +import org.junit.Test + +class InjectionTestActivityTest { + + @get:Rule + val injectionOverrideRule = + InjectionOverrideRule( + mapOf( + InjectionTestActivity::class.java to AndroidInjector { activity -> + val appPreferencesMock = mockk() + every { appPreferencesMock.lastUploadPath } returns INJECTED_STRING + activity.appPreferences = appPreferencesMock + } + ) + ) + + @Test + fun testInjectionOverride() { + launchActivity().use { _ -> + onView(withId(R.id.text)).check(matches(withText(INJECTED_STRING))) + } + } + + companion object { + private const val INJECTED_STRING = "injected string" + } +} diff --git a/app/src/androidTest/java/com/nextcloud/client/RetryTestRule.kt b/app/src/androidTest/java/com/nextcloud/test/RetryTestRule.kt similarity index 98% rename from app/src/androidTest/java/com/nextcloud/client/RetryTestRule.kt rename to app/src/androidTest/java/com/nextcloud/test/RetryTestRule.kt index 434783356e..57c0f20552 100644 --- a/app/src/androidTest/java/com/nextcloud/client/RetryTestRule.kt +++ b/app/src/androidTest/java/com/nextcloud/test/RetryTestRule.kt @@ -20,7 +20,7 @@ * along with this program. If not, see . */ -package com.nextcloud.client +package com.nextcloud.test import com.owncloud.android.BuildConfig import com.owncloud.android.lib.common.utils.Log_OC diff --git a/app/src/androidTest/java/com/nextcloud/test/TestMainApp.kt b/app/src/androidTest/java/com/nextcloud/test/TestMainApp.kt new file mode 100644 index 0000000000..99a2bf26f3 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/test/TestMainApp.kt @@ -0,0 +1,74 @@ +/* + * Nextcloud Android client application + * + * @author Álvaro Brey + * Copyright (C) 2023 Álvaro Brey + * Copyright (C) 2023 Nextcloud GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . + * + */ + +package com.nextcloud.test + +import com.owncloud.android.MainApp +import com.owncloud.android.lib.common.utils.Log_OC +import dagger.android.AndroidInjector +import dagger.android.DispatchingAndroidInjector + +/** + * The purpose of this class is to allow overriding injections in Android classes (which use parameter injection instead + * of constructor injection). + * + * To automate its usage, pair with [InjectionOverrideRule]; or call [addTestInjector] manually for more control. + */ +class TestMainApp : MainApp() { + + val foo = "BAR" + private var overrideInjectors: MutableMap, AndroidInjector<*>> = mutableMapOf() + + /** + * If you call this before a test please remember to call [clearTestInjectors] afterwards + */ + fun addTestInjector(clazz: Class<*>, injector: AndroidInjector<*>) { + Log_OC.d(TAG, "addTestInjector: added injector for $clazz") + overrideInjectors[clazz] = injector + } + + fun clearTestInjectors() { + overrideInjectors.clear() + } + + override fun androidInjector(): AndroidInjector { + @Suppress("UNCHECKED_CAST") + return InjectorWrapper(dispatchingAndroidInjector, overrideInjectors as Map, AndroidInjector>) + } + + class InjectorWrapper( + private val baseInjector: DispatchingAndroidInjector, + private val overrideInjectors: Map, AndroidInjector> + ) : AndroidInjector { + override fun inject(instance: Any) { + baseInjector.inject(instance) + overrideInjectors[instance.javaClass]?.let { customInjector -> + Log_OC.d(TAG, "Injecting ${instance.javaClass} with ${customInjector.javaClass}") + customInjector.inject(instance) + } + } + } + + companion object { + private const val TAG = "TestMainApp" + } +} diff --git a/app/src/androidTest/java/com/nextcloud/ui/BitmapIT.kt b/app/src/androidTest/java/com/nextcloud/ui/BitmapIT.kt index 23bfb671c8..753ad0c893 100644 --- a/app/src/androidTest/java/com/nextcloud/ui/BitmapIT.kt +++ b/app/src/androidTest/java/com/nextcloud/ui/BitmapIT.kt @@ -26,7 +26,7 @@ import android.graphics.BitmapFactory import android.widget.ImageView import android.widget.LinearLayout import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.utils.BitmapUtils diff --git a/app/src/androidTest/java/com/owncloud/android/AbstractIT.java b/app/src/androidTest/java/com/owncloud/android/AbstractIT.java index f84f00ad4d..2be8c335b6 100644 --- a/app/src/androidTest/java/com/owncloud/android/AbstractIT.java +++ b/app/src/androidTest/java/com/owncloud/android/AbstractIT.java @@ -14,7 +14,7 @@ import android.view.View; import com.facebook.testing.screenshot.Screenshot; import com.facebook.testing.screenshot.internal.TestNameDetector; -import com.nextcloud.client.GrantStoragePermissionRule; +import com.nextcloud.test.GrantStoragePermissionRule; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManagerImpl; diff --git a/app/src/androidTest/java/com/owncloud/android/authentication/PassCodeManagerIT.kt b/app/src/androidTest/java/com/owncloud/android/authentication/PassCodeManagerIT.kt index 65253faea1..c3f17c6e4e 100644 --- a/app/src/androidTest/java/com/owncloud/android/authentication/PassCodeManagerIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/authentication/PassCodeManagerIT.kt @@ -23,9 +23,9 @@ package com.owncloud.android.authentication import androidx.test.core.app.launchActivity -import com.nextcloud.client.TestActivity import com.nextcloud.client.core.Clock import com.nextcloud.client.preferences.AppPreferences +import com.nextcloud.test.TestActivity import com.owncloud.android.ui.activity.SettingsActivity import io.mockk.MockKAnnotations import io.mockk.every diff --git a/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt b/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt index 9839dcecce..ec37cca712 100644 --- a/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt @@ -22,8 +22,8 @@ package com.owncloud.android.files import androidx.test.core.app.launchActivity import androidx.test.ext.junit.runners.AndroidJUnit4 -import com.nextcloud.client.TestActivity import com.nextcloud.client.account.User +import com.nextcloud.test.TestActivity import com.nextcloud.utils.EditorUtils import com.owncloud.android.AbstractIT import com.owncloud.android.R diff --git a/app/src/androidTest/java/com/owncloud/android/providers/UsersAndGroupsSearchProviderIT.kt b/app/src/androidTest/java/com/owncloud/android/providers/UsersAndGroupsSearchProviderIT.kt index 50cf7c04bc..713f16916c 100644 --- a/app/src/androidTest/java/com/owncloud/android/providers/UsersAndGroupsSearchProviderIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/providers/UsersAndGroupsSearchProviderIT.kt @@ -22,7 +22,7 @@ package com.owncloud.android.providers import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractOnServerIT import org.junit.Rule import org.junit.Test diff --git a/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt index ddb5ac29b2..0a53d807f2 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/LoginIT.kt @@ -29,10 +29,10 @@ import androidx.test.espresso.web.webdriver.DriverAtoms import androidx.test.espresso.web.webdriver.Locator import androidx.test.filters.LargeTest import androidx.test.platform.app.InstrumentationRegistry -import com.nextcloud.client.GrantStoragePermissionRule -import com.nextcloud.client.RetryTestRule import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.account.UserAccountManagerImpl +import com.nextcloud.test.GrantStoragePermissionRule +import com.nextcloud.test.RetryTestRule import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.authentication.AuthenticatorActivity diff --git a/app/src/androidTest/java/com/owncloud/android/ui/activity/DrawerActivityIT.java b/app/src/androidTest/java/com/owncloud/android/ui/activity/DrawerActivityIT.java index 73e692d74b..a836169b84 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/activity/DrawerActivityIT.java +++ b/app/src/androidTest/java/com/owncloud/android/ui/activity/DrawerActivityIT.java @@ -27,7 +27,7 @@ import android.accounts.AccountManager; import android.net.Uri; import android.os.Bundle; -import com.nextcloud.client.RetryTestRule; +import com.nextcloud.test.RetryTestRule; import com.nextcloud.client.account.User; import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManagerImpl; diff --git a/app/src/androidTest/java/com/owncloud/android/ui/activity/FileDisplayActivityTest.java b/app/src/androidTest/java/com/owncloud/android/ui/activity/FileDisplayActivityTest.java index 47b8561035..0224235a0f 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/activity/FileDisplayActivityTest.java +++ b/app/src/androidTest/java/com/owncloud/android/ui/activity/FileDisplayActivityTest.java @@ -2,12 +2,10 @@ package com.owncloud.android.ui.activity; import android.app.Activity; -import com.nextcloud.client.GrantStoragePermissionRule; import com.nextcloud.client.onboarding.WhatsNewActivity; import com.owncloud.android.AbstractIT; import org.junit.Test; -import org.junit.rules.TestRule; import androidx.test.core.app.ActivityScenario; import androidx.test.platform.app.InstrumentationRegistry; diff --git a/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt index 49d3b54774..af620133b1 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/activity/UploadFilesActivityIT.kt @@ -23,7 +23,7 @@ package com.owncloud.android.ui.activity import android.content.Intent import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.GrantStoragePermissionRule +import com.nextcloud.test.GrantStoragePermissionRule import com.owncloud.android.AbstractIT import com.owncloud.android.utils.FileStorageUtils import com.owncloud.android.utils.ScreenshotTest diff --git a/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendFilesDialogTest.kt b/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendFilesDialogTest.kt index 79c915789c..4b7c4a0103 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendFilesDialogTest.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendFilesDialogTest.kt @@ -25,7 +25,7 @@ import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.RecyclerView import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.platform.app.InstrumentationRegistry -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.datamodel.OCFile diff --git a/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendShareDialogTest.kt b/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendShareDialogTest.kt index 710221f155..ca4674f3ab 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendShareDialogTest.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/dialog/SendShareDialogTest.kt @@ -24,7 +24,7 @@ package com.owncloud.android.ui.dialog import androidx.fragment.app.FragmentManager import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.platform.app.InstrumentationRegistry -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.resources.status.OCCapability diff --git a/app/src/androidTest/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragmentIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragmentIT.kt index 8780324551..169377c84c 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragmentIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragmentIT.kt @@ -23,7 +23,7 @@ package com.owncloud.android.ui.dialog import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.utils.ScreenshotTest import org.junit.Rule diff --git a/app/src/androidTest/java/com/owncloud/android/ui/fragment/AvatarIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/fragment/AvatarIT.kt index 75995b9be8..ababbe2edd 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/fragment/AvatarIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/fragment/AvatarIT.kt @@ -24,7 +24,7 @@ package com.owncloud.android.ui.fragment import android.graphics.BitmapFactory import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.lib.resources.users.StatusType diff --git a/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailFragmentStaticServerIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailFragmentStaticServerIT.kt index 6104b7f484..50494c6285 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailFragmentStaticServerIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailFragmentStaticServerIT.kt @@ -23,7 +23,7 @@ package com.owncloud.android.ui.fragment import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.datamodel.OCFile diff --git a/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailSharingFragmentIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailSharingFragmentIT.kt index 64ae887d51..3314ec28ac 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailSharingFragmentIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailSharingFragmentIT.kt @@ -37,8 +37,8 @@ import androidx.test.espresso.matcher.ViewMatchers.withText import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultBaseUtils.matchesCheckNames import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews import com.google.android.material.floatingactionbutton.FloatingActionButton -import com.nextcloud.client.RetryTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.RetryTestRule +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.R import com.owncloud.android.datamodel.OCFile diff --git a/app/src/androidTest/java/com/owncloud/android/ui/fragment/GalleryFragmentIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/fragment/GalleryFragmentIT.kt index c6fa674085..0d1b853777 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/fragment/GalleryFragmentIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/fragment/GalleryFragmentIT.kt @@ -27,7 +27,7 @@ import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.ImageDimension import com.owncloud.android.datamodel.OCFile diff --git a/app/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt index 49e5cd1cae..2ac4517e0c 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/fragment/OCFileListFragmentStaticServerIT.kt @@ -23,8 +23,8 @@ package com.owncloud.android.ui.fragment import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.GrantStoragePermissionRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.GrantStoragePermissionRule +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.resources.shares.ShareType diff --git a/app/src/androidTest/java/com/owncloud/android/ui/fragment/UnifiedSearchFragmentIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/fragment/UnifiedSearchFragmentIT.kt index c0c47d7c9d..ed6952754a 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/fragment/UnifiedSearchFragmentIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/fragment/UnifiedSearchFragmentIT.kt @@ -22,7 +22,7 @@ package com.owncloud.android.ui.fragment import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.internal.runner.junit4.statement.UiThreadStatement -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.common.SearchResultEntry diff --git a/app/src/androidTest/java/com/owncloud/android/ui/helpers/UriUploaderIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/helpers/UriUploaderIT.kt index ed68d176fe..dc9cdd13aa 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/helpers/UriUploaderIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/helpers/UriUploaderIT.kt @@ -2,7 +2,7 @@ package com.owncloud.android.ui.helpers import android.net.Uri import androidx.test.core.app.launchActivity -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.files.services.FileUploader import org.junit.Assert diff --git a/app/src/androidTest/java/com/owncloud/android/ui/preview/PreviewImageFragmentIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/preview/PreviewImageFragmentIT.kt index df4aea478e..ed39f90109 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/preview/PreviewImageFragmentIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/preview/PreviewImageFragmentIT.kt @@ -22,7 +22,7 @@ package com.owncloud.android.ui.preview import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import org.junit.Rule diff --git a/app/src/androidTest/java/com/owncloud/android/ui/preview/pdf/PreviewPdfFragmentScreenshotIT.kt b/app/src/androidTest/java/com/owncloud/android/ui/preview/pdf/PreviewPdfFragmentScreenshotIT.kt index 536c075157..a7e7868697 100644 --- a/app/src/androidTest/java/com/owncloud/android/ui/preview/pdf/PreviewPdfFragmentScreenshotIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/ui/preview/pdf/PreviewPdfFragmentScreenshotIT.kt @@ -23,7 +23,7 @@ package com.owncloud.android.ui.preview.pdf import androidx.lifecycle.Lifecycle import androidx.test.espresso.intent.rule.IntentsTestRule -import com.nextcloud.client.TestActivity +import com.nextcloud.test.TestActivity import com.owncloud.android.AbstractIT import com.owncloud.android.datamodel.OCFile import com.owncloud.android.utils.ScreenshotTest diff --git a/app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java b/app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java index 7818da7e63..d346008e8b 100644 --- a/app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java +++ b/app/src/androidTest/java/com/owncloud/android/util/EncryptionTestIT.java @@ -26,7 +26,7 @@ import android.text.TextUtils; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import com.nextcloud.client.RetryTestRule; +import com.nextcloud.test.RetryTestRule; import com.nextcloud.test.RandomStringGenerator; import com.owncloud.android.datamodel.DecryptedFolderMetadata; import com.owncloud.android.datamodel.EncryptedFolderMetadata; diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml index 99a649c542..70db8afd85 100644 --- a/app/src/debug/AndroidManifest.xml +++ b/app/src/debug/AndroidManifest.xml @@ -11,7 +11,9 @@ - - + + diff --git a/app/src/debug/java/com/nextcloud/client/di/BuildTypeComponentsModule.java b/app/src/debug/java/com/nextcloud/client/di/BuildTypeComponentsModule.kt similarity index 73% rename from app/src/debug/java/com/nextcloud/client/di/BuildTypeComponentsModule.java rename to app/src/debug/java/com/nextcloud/client/di/BuildTypeComponentsModule.kt index fa36307174..b66d7f9110 100644 --- a/app/src/debug/java/com/nextcloud/client/di/BuildTypeComponentsModule.java +++ b/app/src/debug/java/com/nextcloud/client/di/BuildTypeComponentsModule.kt @@ -19,19 +19,21 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +package com.nextcloud.client.di -package com.nextcloud.client.di; - -import com.nextcloud.client.TestActivity; - -import dagger.Module; -import dagger.android.ContributesAndroidInjector; +import com.nextcloud.test.InjectionTestActivity +import com.nextcloud.test.TestActivity +import dagger.Module +import dagger.android.ContributesAndroidInjector /** * Register classes that require dependency injection. This class is used by Dagger compiler only. */ @Module -abstract class BuildTypeComponentsModule { +interface BuildTypeComponentsModule { @ContributesAndroidInjector - abstract TestActivity testActivity(); + fun testActivity(): TestActivity? + + @ContributesAndroidInjector + fun injectionTestActivity(): InjectionTestActivity? } diff --git a/app/src/debug/java/com/nextcloud/test/InjectionTestActivity.kt b/app/src/debug/java/com/nextcloud/test/InjectionTestActivity.kt new file mode 100644 index 0000000000..968077c050 --- /dev/null +++ b/app/src/debug/java/com/nextcloud/test/InjectionTestActivity.kt @@ -0,0 +1,46 @@ +/* + * Nextcloud Android client application + * + * @author Álvaro Brey + * Copyright (C) 2023 Álvaro Brey + * Copyright (C) 2023 Nextcloud GmbH + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this program. If not, see . + * + */ + +package com.nextcloud.test + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import com.nextcloud.client.di.Injectable +import com.nextcloud.client.preferences.AppPreferences +import com.owncloud.android.databinding.ActivityInjectionTestBinding +import javax.inject.Inject + +/** + * Sample activity to check test overriding injections + */ +class InjectionTestActivity : AppCompatActivity(), Injectable { + @Inject + lateinit var appPreferences: AppPreferences + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val binding = ActivityInjectionTestBinding.inflate(layoutInflater) + // random pref, just needs to match the one in the test + binding.text.text = appPreferences.lastUploadPath + setContentView(binding.root) + } +} diff --git a/app/src/debug/java/com/nextcloud/client/TestActivity.kt b/app/src/debug/java/com/nextcloud/test/TestActivity.kt similarity index 99% rename from app/src/debug/java/com/nextcloud/client/TestActivity.kt rename to app/src/debug/java/com/nextcloud/test/TestActivity.kt index d201961835..3fb033bfe3 100644 --- a/app/src/debug/java/com/nextcloud/client/TestActivity.kt +++ b/app/src/debug/java/com/nextcloud/test/TestActivity.kt @@ -19,7 +19,7 @@ * along with this program. If not, see . */ -package com.nextcloud.client +package com.nextcloud.test import android.os.Bundle import android.view.View diff --git a/app/src/debug/res/layout/activity_injection_test.xml b/app/src/debug/res/layout/activity_injection_test.xml new file mode 100644 index 0000000000..ff3dcf3af8 --- /dev/null +++ b/app/src/debug/res/layout/activity_injection_test.xml @@ -0,0 +1,42 @@ + + + + + + +