mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 05:35:39 +03:00
Merge pull request #11248 from nextcloud/test-injection
Enable overriding injections in AndroidInjection classes during connected tests
This commit is contained in:
commit
bbedbc973a
39 changed files with 360 additions and 93 deletions
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
|
@ -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
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
74
app/src/androidTest/java/com/nextcloud/test/TestMainApp.kt
Normal file
74
app/src/androidTest/java/com/nextcloud/test/TestMainApp.kt
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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?
|
||||||
}
|
}
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
42
app/src/debug/res/layout/activity_injection_test.xml
Normal file
42
app/src/debug/res/layout/activity_injection_test.xml
Normal 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>
|
Loading…
Reference in a new issue