diff --git a/app/src/robolectricTest/java/org/fnives/test/showcase/ui/RobolectricLoginRobot.kt b/app/src/robolectricTest/java/org/fnives/test/showcase/ui/RobolectricLoginRobot.kt index 8ed9cf6..8a912e6 100644 --- a/app/src/robolectricTest/java/org/fnives/test/showcase/ui/RobolectricLoginRobot.kt +++ b/app/src/robolectricTest/java/org/fnives/test/showcase/ui/RobolectricLoginRobot.kt @@ -10,14 +10,13 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import org.fnives.test.showcase.R -import org.fnives.test.showcase.testutils.configuration.SnackbarVerificationHelper -import org.fnives.test.showcase.testutils.viewactions.notIntended +import org.fnives.test.showcase.android.testutil.intent.notIntended +import org.fnives.test.showcase.android.testutil.snackbar.SnackbarVerificationHelper.assertSnackBarIsNotShown +import org.fnives.test.showcase.android.testutil.snackbar.SnackbarVerificationHelper.assertSnackBarIsShownWithText import org.fnives.test.showcase.ui.home.MainActivity import org.hamcrest.core.IsNot.not -class RobolectricLoginRobot( - private val snackbarVerificationHelper: SnackbarVerificationHelper = SnackbarVerificationHelper() -) { +class RobolectricLoginRobot { fun setUsername(username: String): RobolectricLoginRobot = apply { onView(withId(R.id.user_edit_text)) @@ -55,11 +54,11 @@ class RobolectricLoginRobot( } fun assertErrorIsShown(@StringRes stringResID: Int) = apply { - snackbarVerificationHelper.assertIsShownWithText(stringResID) + assertSnackBarIsShownWithText(stringResID) } fun assertErrorIsNotShown() = apply { - snackbarVerificationHelper.assertIsNotShown() + assertSnackBarIsNotShown() } fun assertNavigatedToHome() = apply { diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/HomeRobot.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/HomeRobot.kt index fe95319..7b154a6 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/HomeRobot.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/home/HomeRobot.kt @@ -19,11 +19,11 @@ import androidx.test.espresso.matcher.ViewMatchers.withId import androidx.test.espresso.matcher.ViewMatchers.withParent import androidx.test.espresso.matcher.ViewMatchers.withText import org.fnives.test.showcase.R +import org.fnives.test.showcase.android.testutil.intent.notIntended +import org.fnives.test.showcase.android.testutil.viewaction.imageview.WithDrawable +import org.fnives.test.showcase.android.testutil.viewaction.swiperefresh.PullToRefresh import org.fnives.test.showcase.model.content.Content import org.fnives.test.showcase.model.content.FavouriteContent -import org.fnives.test.showcase.testutils.viewactions.PullToRefresh -import org.fnives.test.showcase.testutils.viewactions.WithDrawable -import org.fnives.test.showcase.testutils.viewactions.notIntended import org.fnives.test.showcase.ui.auth.AuthActivity import org.hamcrest.Matchers.allOf diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/LoginRobot.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/LoginRobot.kt index 0419eec..6ec7cd5 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/LoginRobot.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/LoginRobot.kt @@ -14,15 +14,14 @@ import androidx.test.espresso.matcher.ViewMatchers import androidx.test.espresso.matcher.ViewMatchers.isDisplayed import androidx.test.espresso.matcher.ViewMatchers.withId import org.fnives.test.showcase.R -import org.fnives.test.showcase.testutils.configuration.SnackbarVerificationHelper -import org.fnives.test.showcase.testutils.viewactions.ReplaceProgressBarDrawableToStatic -import org.fnives.test.showcase.testutils.viewactions.notIntended +import org.fnives.test.showcase.android.testutil.intent.notIntended +import org.fnives.test.showcase.android.testutil.snackbar.SnackbarVerificationHelper.assertSnackBarIsNotShown +import org.fnives.test.showcase.android.testutil.snackbar.SnackbarVerificationHelper.assertSnackBarIsShownWithText +import org.fnives.test.showcase.android.testutil.viewaction.progressbar.ReplaceProgressBarDrawableToStatic import org.fnives.test.showcase.ui.home.MainActivity import org.hamcrest.core.IsNot.not -class LoginRobot( - private val snackbarVerificationHelper: SnackbarVerificationHelper = SnackbarVerificationHelper() -) { +class LoginRobot { fun setupIntentResults() { Intents.intending(hasComponent(MainActivity::class.java.canonicalName)) @@ -68,7 +67,7 @@ class LoginRobot( } fun assertErrorIsShown(@StringRes stringResID: Int) = apply { - snackbarVerificationHelper.assertIsShownWithText(stringResID) + assertSnackBarIsShownWithText(stringResID) } fun assertLoadingBeforeRequests() = apply { @@ -82,7 +81,7 @@ class LoginRobot( } fun assertErrorIsNotShown() = apply { - snackbarVerificationHelper.assertIsNotShown() + assertSnackBarIsNotShown() } fun assertNavigatedToHome() = apply { diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/codekata/CodeKataSharedRobotTest.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/codekata/CodeKataSharedRobotTest.kt index fb87018..2c1b5bc 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/codekata/CodeKataSharedRobotTest.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/login/codekata/CodeKataSharedRobotTest.kt @@ -8,14 +8,13 @@ import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.matcher.IntentMatchers import androidx.test.espresso.matcher.ViewMatchers import org.fnives.test.showcase.R -import org.fnives.test.showcase.testutils.configuration.SnackbarVerificationHelper -import org.fnives.test.showcase.testutils.viewactions.notIntended +import org.fnives.test.showcase.android.testutil.snackbar.SnackbarVerificationHelper.assertSnackBarIsNotShown +import org.fnives.test.showcase.android.testutil.snackbar.SnackbarVerificationHelper.assertSnackBarIsShownWithText +import org.fnives.test.showcase.android.testutil.intent.notIntended import org.fnives.test.showcase.ui.home.MainActivity import org.hamcrest.core.IsNot -class CodeKataSharedRobotTest( - private val snackbarVerificationHelper: SnackbarVerificationHelper = SnackbarVerificationHelper() -) { +class CodeKataSharedRobotTest { fun setUsername(username: String): CodeKataSharedRobotTest = apply { Espresso.onView(ViewMatchers.withId(R.id.user_edit_text)) @@ -53,11 +52,11 @@ class CodeKataSharedRobotTest( } fun assertErrorIsShown(@StringRes stringResID: Int): CodeKataSharedRobotTest = apply { - snackbarVerificationHelper.assertIsShownWithText(stringResID) + assertSnackBarIsShownWithText(stringResID) } fun assertErrorIsNotShown(): CodeKataSharedRobotTest = apply { - snackbarVerificationHelper.assertIsNotShown() + assertSnackBarIsNotShown() } fun assertNavigatedToHome(): CodeKataSharedRobotTest = apply { diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashRobot.kt b/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashRobot.kt index 0e941b6..c598d77 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashRobot.kt +++ b/app/src/sharedTest/java/org/fnives/test/showcase/ui/splash/SplashRobot.kt @@ -5,7 +5,7 @@ import android.app.Instrumentation import android.content.Intent import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.matcher.IntentMatchers -import org.fnives.test.showcase.testutils.viewactions.notIntended +import org.fnives.test.showcase.android.testutil.intent.notIntended import org.fnives.test.showcase.ui.auth.AuthActivity import org.fnives.test.showcase.ui.home.MainActivity diff --git a/test-util-android/build.gradle b/test-util-android/build.gradle index 91dbe0b..6530663 100644 --- a/test-util-android/build.gradle +++ b/test-util-android/build.gradle @@ -31,7 +31,14 @@ android { dependencies { implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" + implementation "androidx.test:core:$androidx_test_version" - implementation"androidx.test.espresso:espresso-core:$espresso_version" + implementation "androidx.test.espresso:espresso-core:$espresso_version" + implementation "androidx.test.espresso:espresso-intents:$espresso_version" + implementation "com.squareup.okhttp3:okhttp:$okhttp_version" + + implementation "com.google.android.material:material:$androidx_material_version" + implementation "androidx.swiperefreshlayout:swiperefreshlayout:$androidx_swiperefreshlayout_version" + implementation "androidx.core:core-ktx:$androidx_core_version" } \ No newline at end of file diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/notIntended.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/intent/notIntended.kt similarity index 89% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/notIntended.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/intent/notIntended.kt index a88cf48..d520eb3 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/notIntended.kt +++ b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/intent/notIntended.kt @@ -1,4 +1,4 @@ -package org.fnives.test.showcase.testutils.viewactions +package org.fnives.test.showcase.android.testutil.intent import android.content.Intent import androidx.test.espresso.intent.Intents.intended diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/configuration/SnackbarVerificationHelper.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/snackbar/SnackbarVerificationHelper.kt similarity index 70% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/configuration/SnackbarVerificationHelper.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/snackbar/SnackbarVerificationHelper.kt index 3827bd7..3d49d99 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/configuration/SnackbarVerificationHelper.kt +++ b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/snackbar/SnackbarVerificationHelper.kt @@ -1,5 +1,6 @@ -package org.fnives.test.showcase.testutils.configuration +package org.fnives.test.showcase.android.testutil.snackbar +import android.annotation.SuppressLint import android.view.View import androidx.annotation.StringRes import androidx.test.espresso.Espresso @@ -8,15 +9,16 @@ import androidx.test.espresso.ViewAction import androidx.test.espresso.action.ViewActions import androidx.test.espresso.assertion.ViewAssertions import androidx.test.espresso.matcher.ViewMatchers -import com.google.android.material.R +import com.google.android.material.R as MaterialR import com.google.android.material.snackbar.Snackbar import org.hamcrest.Matcher import org.hamcrest.Matchers -class SnackbarVerificationHelper { +object SnackbarVerificationHelper { - fun assertIsShownWithText(@StringRes stringResID: Int, doDismiss: Boolean = true) { - Espresso.onView(ViewMatchers.withId(R.id.snackbar_text)) + @SuppressLint("RestrictedApi") + fun assertSnackBarIsShownWithText(@StringRes stringResID: Int, doDismiss: Boolean = true) { + Espresso.onView(ViewMatchers.withId(MaterialR.id.snackbar_text)) .check(ViewAssertions.matches(ViewMatchers.withText(stringResID))) if (doDismiss) { Espresso.onView(ViewMatchers.isAssignableFrom(Snackbar.SnackbarLayout::class.java)).perform(ViewActions.swipeRight()) @@ -24,8 +26,8 @@ class SnackbarVerificationHelper { } } - fun assertIsNotShown() { - Espresso.onView(ViewMatchers.withId(R.id.snackbar_text)).check(ViewAssertions.doesNotExist()) + fun assertSnackBarIsNotShown() { + Espresso.onView(ViewMatchers.withId(MaterialR.id.snackbar_text)).check(ViewAssertions.doesNotExist()) } class LoopMainUntilSnackbarDismissed : ViewAction { @@ -39,4 +41,4 @@ class SnackbarVerificationHelper { } } } -} +} \ No newline at end of file diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/WithDrawable.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/imageview/WithDrawable.kt similarity index 89% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/WithDrawable.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/imageview/WithDrawable.kt index 79287c1..2303224 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/WithDrawable.kt +++ b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/imageview/WithDrawable.kt @@ -1,4 +1,4 @@ -package org.fnives.test.showcase.testutils.viewactions +package org.fnives.test.showcase.android.testutil.viewaction.imageview import android.content.res.ColorStateList import android.graphics.PorterDuff @@ -26,7 +26,7 @@ class WithDrawable( override fun matchesSafely(view: View): Boolean { val context = view.context val tintColor = tint?.let { ContextCompat.getColor(view.context, it) } - val expectedBitmap = context.getDrawable(id)?.apply { + val expectedBitmap = ContextCompat.getDrawable(context, id)?.apply { if (tintColor != null) { setTintList(ColorStateList.valueOf(tintColor)) setTintMode(tintMode) diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/ReplaceProgressBarDrawableToStatic.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/progressbar/ReplaceProgressBarDrawableToStatic.kt similarity index 91% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/ReplaceProgressBarDrawableToStatic.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/progressbar/ReplaceProgressBarDrawableToStatic.kt index 44a6367..8293afa 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/ReplaceProgressBarDrawableToStatic.kt +++ b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/progressbar/ReplaceProgressBarDrawableToStatic.kt @@ -1,4 +1,4 @@ -package org.fnives.test.showcase.testutils.viewactions +package org.fnives.test.showcase.android.testutil.viewaction.progressbar import android.graphics.Color import android.graphics.drawable.ColorDrawable diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/swiperefresh/PullToRefresh.kt similarity index 95% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/swiperefresh/PullToRefresh.kt index d1b4751..73cecda 100644 --- a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/PullToRefresh.kt +++ b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/swiperefresh/PullToRefresh.kt @@ -1,4 +1,4 @@ -package org.fnives.test.showcase.testutils.viewactions +package org.fnives.test.showcase.android.testutil.viewaction.swiperefresh import android.view.View import androidx.swiperefreshlayout.widget.SwipeRefreshLayout diff --git a/app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/SwipeRefreshLayoutExtension.kt b/test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/swiperefresh/SwipeRefreshLayoutExtension.kt similarity index 100% rename from app/src/sharedTest/java/org/fnives/test/showcase/testutils/viewactions/SwipeRefreshLayoutExtension.kt rename to test-util-android/src/main/java/org/fnives/test/showcase/android/testutil/viewaction/swiperefresh/SwipeRefreshLayoutExtension.kt