Merge pull request #11248 from nextcloud/test-injection

Enable overriding injections in AndroidInjection classes during connected tests
This commit is contained in:
Álvaro Brey 2023-01-13 12:56:45 +01:00 committed by GitHub
commit bbedbc973a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 360 additions and 93 deletions

View file

@ -20,9 +20,9 @@
package com.nextcloud.client; package com.nextcloud.client;
import android.Manifest;
import android.widget.TextView; import android.widget.TextView;
import com.nextcloud.test.GrantStoragePermissionRule;
import com.owncloud.android.AbstractIT; import com.owncloud.android.AbstractIT;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.authentication.AuthenticatorActivity;
@ -34,8 +34,6 @@ import org.junit.rules.TestRule;
import androidx.test.espresso.intent.rule.IntentsTestRule; 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; import static androidx.test.espresso.matcher.ViewMatchers.withId;

View file

@ -24,6 +24,7 @@ package com.nextcloud.client;
import android.app.Activity; import android.app.Activity;
import com.nextcloud.test.GrantStoragePermissionRule;
import com.owncloud.android.AbstractIT; import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.CommunityActivity; import com.owncloud.android.ui.activity.CommunityActivity;
import com.owncloud.android.utils.ScreenshotTest; import com.owncloud.android.utils.ScreenshotTest;

View file

@ -25,6 +25,7 @@ package com.nextcloud.client;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import com.nextcloud.test.RandomStringGenerator; import com.nextcloud.test.RandomStringGenerator;
import com.nextcloud.test.RetryTestRule;
import com.owncloud.android.AbstractOnServerIT; import com.owncloud.android.AbstractOnServerIT;
import com.owncloud.android.datamodel.ArbitraryDataProvider; import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl; import com.owncloud.android.datamodel.ArbitraryDataProviderImpl;

View file

@ -29,6 +29,7 @@ import androidx.test.espresso.contrib.NavigationViewActions
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import com.nextcloud.test.RetryTestRule
import com.owncloud.android.AbstractOnServerIT import com.owncloud.android.AbstractOnServerIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
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);
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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)
}
}

View file

@ -25,6 +25,7 @@ import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Looper import android.os.Looper
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.test.GrantStoragePermissionRule
import com.owncloud.android.AbstractIT import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl import com.owncloud.android.datamodel.ArbitraryDataProviderImpl
import com.owncloud.android.ui.activity.RequestCredentialsActivity import com.owncloud.android.ui.activity.RequestCredentialsActivity

View file

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.nextcloud.client package com.nextcloud.test
import android.Manifest import android.Manifest
import android.os.Build import android.os.Build

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<Class<*>, 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()
}
}
}

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<InjectionTestActivity> { activity ->
val appPreferencesMock = mockk<AppPreferences>()
every { appPreferencesMock.lastUploadPath } returns INJECTED_STRING
activity.appPreferences = appPreferencesMock
}
)
)
@Test
fun testInjectionOverride() {
launchActivity<InjectionTestActivity>().use { _ ->
onView(withId(R.id.text)).check(matches(withText(INJECTED_STRING)))
}
}
companion object {
private const val INJECTED_STRING = "injected string"
}
}

View file

@ -20,7 +20,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.nextcloud.client package com.nextcloud.test
import com.owncloud.android.BuildConfig import com.owncloud.android.BuildConfig
import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.common.utils.Log_OC

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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<Class<*>, 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<Any> {
@Suppress("UNCHECKED_CAST")
return InjectorWrapper(dispatchingAndroidInjector, overrideInjectors as Map<Class<*>, AndroidInjector<Any>>)
}
class InjectorWrapper(
private val baseInjector: DispatchingAndroidInjector<Any>,
private val overrideInjectors: Map<Class<*>, AndroidInjector<Any>>
) : AndroidInjector<Any> {
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"
}
}

View file

@ -26,7 +26,7 @@ import android.graphics.BitmapFactory
import android.widget.ImageView import android.widget.ImageView
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.test.espresso.intent.rule.IntentsTestRule 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.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.utils.BitmapUtils import com.owncloud.android.utils.BitmapUtils

View file

@ -14,7 +14,7 @@ import android.view.View;
import com.facebook.testing.screenshot.Screenshot; import com.facebook.testing.screenshot.Screenshot;
import com.facebook.testing.screenshot.internal.TestNameDetector; 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.User;
import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.account.UserAccountManagerImpl; import com.nextcloud.client.account.UserAccountManagerImpl;

View file

@ -23,9 +23,9 @@
package com.owncloud.android.authentication package com.owncloud.android.authentication
import androidx.test.core.app.launchActivity import androidx.test.core.app.launchActivity
import com.nextcloud.client.TestActivity
import com.nextcloud.client.core.Clock import com.nextcloud.client.core.Clock
import com.nextcloud.client.preferences.AppPreferences import com.nextcloud.client.preferences.AppPreferences
import com.nextcloud.test.TestActivity
import com.owncloud.android.ui.activity.SettingsActivity import com.owncloud.android.ui.activity.SettingsActivity
import io.mockk.MockKAnnotations import io.mockk.MockKAnnotations
import io.mockk.every import io.mockk.every

View file

@ -22,8 +22,8 @@ package com.owncloud.android.files
import androidx.test.core.app.launchActivity import androidx.test.core.app.launchActivity
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.nextcloud.client.TestActivity
import com.nextcloud.client.account.User import com.nextcloud.client.account.User
import com.nextcloud.test.TestActivity
import com.nextcloud.utils.EditorUtils import com.nextcloud.utils.EditorUtils
import com.owncloud.android.AbstractIT import com.owncloud.android.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R

View file

@ -22,7 +22,7 @@
package com.owncloud.android.providers package com.owncloud.android.providers
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.client.TestActivity import com.nextcloud.test.TestActivity
import com.owncloud.android.AbstractOnServerIT import com.owncloud.android.AbstractOnServerIT
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test

View file

@ -29,10 +29,10 @@ import androidx.test.espresso.web.webdriver.DriverAtoms
import androidx.test.espresso.web.webdriver.Locator import androidx.test.espresso.web.webdriver.Locator
import androidx.test.filters.LargeTest import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry 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.UserAccountManager
import com.nextcloud.client.account.UserAccountManagerImpl 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.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.authentication.AuthenticatorActivity import com.owncloud.android.authentication.AuthenticatorActivity

View file

@ -27,7 +27,7 @@ import android.accounts.AccountManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; 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.User;
import com.nextcloud.client.account.UserAccountManager; import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.account.UserAccountManagerImpl; import com.nextcloud.client.account.UserAccountManagerImpl;

View file

@ -2,12 +2,10 @@ package com.owncloud.android.ui.activity;
import android.app.Activity; import android.app.Activity;
import com.nextcloud.client.GrantStoragePermissionRule;
import com.nextcloud.client.onboarding.WhatsNewActivity; import com.nextcloud.client.onboarding.WhatsNewActivity;
import com.owncloud.android.AbstractIT; import com.owncloud.android.AbstractIT;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestRule;
import androidx.test.core.app.ActivityScenario; import androidx.test.core.app.ActivityScenario;
import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.platform.app.InstrumentationRegistry;

View file

@ -23,7 +23,7 @@ package com.owncloud.android.ui.activity
import android.content.Intent import android.content.Intent
import androidx.test.espresso.intent.rule.IntentsTestRule 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.AbstractIT
import com.owncloud.android.utils.FileStorageUtils import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.ScreenshotTest import com.owncloud.android.utils.ScreenshotTest

View file

@ -25,7 +25,7 @@ import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.platform.app.InstrumentationRegistry 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.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile

View file

@ -24,7 +24,7 @@ package com.owncloud.android.ui.dialog
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.platform.app.InstrumentationRegistry 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.AbstractIT
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.status.OCCapability import com.owncloud.android.lib.resources.status.OCCapability

View file

@ -23,7 +23,7 @@ package com.owncloud.android.ui.dialog
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread 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.AbstractIT
import com.owncloud.android.utils.ScreenshotTest import com.owncloud.android.utils.ScreenshotTest
import org.junit.Rule import org.junit.Rule

View file

@ -24,7 +24,7 @@ package com.owncloud.android.ui.fragment
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.internal.runner.junit4.statement.UiThreadStatement.runOnUiThread 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.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.lib.resources.users.StatusType import com.owncloud.android.lib.resources.users.StatusType

View file

@ -23,7 +23,7 @@
package com.owncloud.android.ui.fragment package com.owncloud.android.ui.fragment
import androidx.test.espresso.intent.rule.IntentsTestRule 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.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile

View file

@ -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.AccessibilityCheckResultBaseUtils.matchesCheckNames
import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews import com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews
import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.nextcloud.client.RetryTestRule import com.nextcloud.test.RetryTestRule
import com.nextcloud.client.TestActivity import com.nextcloud.test.TestActivity
import com.owncloud.android.AbstractIT import com.owncloud.android.AbstractIT
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile

View file

@ -27,7 +27,7 @@ import android.graphics.Canvas
import android.graphics.Color import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
import androidx.test.espresso.intent.rule.IntentsTestRule 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.AbstractIT
import com.owncloud.android.datamodel.ImageDimension import com.owncloud.android.datamodel.ImageDimension
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile

View file

@ -23,8 +23,8 @@
package com.owncloud.android.ui.fragment package com.owncloud.android.ui.fragment
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import com.nextcloud.client.GrantStoragePermissionRule import com.nextcloud.test.GrantStoragePermissionRule
import com.nextcloud.client.TestActivity import com.nextcloud.test.TestActivity
import com.owncloud.android.AbstractIT import com.owncloud.android.AbstractIT
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.resources.shares.ShareType import com.owncloud.android.lib.resources.shares.ShareType

View file

@ -22,7 +22,7 @@ package com.owncloud.android.ui.fragment
import androidx.test.espresso.intent.rule.IntentsTestRule import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.internal.runner.junit4.statement.UiThreadStatement 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.AbstractIT
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.lib.common.SearchResultEntry import com.owncloud.android.lib.common.SearchResultEntry

View file

@ -2,7 +2,7 @@ package com.owncloud.android.ui.helpers
import android.net.Uri import android.net.Uri
import androidx.test.core.app.launchActivity 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.AbstractIT
import com.owncloud.android.files.services.FileUploader import com.owncloud.android.files.services.FileUploader
import org.junit.Assert import org.junit.Assert

View file

@ -22,7 +22,7 @@
package com.owncloud.android.ui.preview package com.owncloud.android.ui.preview
import androidx.test.espresso.intent.rule.IntentsTestRule 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.AbstractIT
import org.junit.Rule import org.junit.Rule

View file

@ -23,7 +23,7 @@ package com.owncloud.android.ui.preview.pdf
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.test.espresso.intent.rule.IntentsTestRule 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.AbstractIT
import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.utils.ScreenshotTest import com.owncloud.android.utils.ScreenshotTest

View file

@ -26,7 +26,7 @@ import android.text.TextUtils;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.nextcloud.client.RetryTestRule; import com.nextcloud.test.RetryTestRule;
import com.nextcloud.test.RandomStringGenerator; import com.nextcloud.test.RandomStringGenerator;
import com.owncloud.android.datamodel.DecryptedFolderMetadata; import com.owncloud.android.datamodel.DecryptedFolderMetadata;
import com.owncloud.android.datamodel.EncryptedFolderMetadata; import com.owncloud.android.datamodel.EncryptedFolderMetadata;

View file

@ -11,7 +11,9 @@
<application <application
android:testOnly="false" android:testOnly="false"
tools:ignore="GoogleAppIndexingWarning"> tools:ignore="GoogleAppIndexingWarning">
<activity
<activity android:name="com.nextcloud.client.TestActivity" /> android:name="com.nextcloud.test.InjectionTestActivity"
android:exported="false" />
<activity android:name="com.nextcloud.test.TestActivity" />
</application> </application>
</manifest> </manifest>

View file

@ -19,19 +19,21 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.nextcloud.client.di
package com.nextcloud.client.di; import com.nextcloud.test.InjectionTestActivity
import com.nextcloud.test.TestActivity
import com.nextcloud.client.TestActivity; import dagger.Module
import dagger.android.ContributesAndroidInjector
import dagger.Module;
import dagger.android.ContributesAndroidInjector;
/** /**
* Register classes that require dependency injection. This class is used by Dagger compiler only. * Register classes that require dependency injection. This class is used by Dagger compiler only.
*/ */
@Module @Module
abstract class BuildTypeComponentsModule { interface BuildTypeComponentsModule {
@ContributesAndroidInjector @ContributesAndroidInjector
abstract TestActivity testActivity(); fun testActivity(): TestActivity?
@ContributesAndroidInjector
fun injectionTestActivity(): InjectionTestActivity?
} }

View file

@ -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 <http://www.gnu.org/licenses/>.
*
*/
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)
}
}

View file

@ -19,7 +19,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.nextcloud.client package com.nextcloud.test
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ 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 <http://www.gnu.org/licenses/>.
~
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.nextcloud.test.InjectionTestActivity">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Default text"
android:textSize="50sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
</androidx.constraintlayout.widget.ConstraintLayout>