Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

220, 221: Raise minimum SDK to 21, target/compile SDK to 34 #223

Merged
merged 7 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 3.0.0

- https://github.com/ndtp/android-testify/pull/224 - Upgrade to Kotlin 1.9.24 and Compose to 2024.05.00
- Fix several warnings
- Upgrade dependencies on sample apps
- Warning: The January '24 update to Compose introduces changes to the default font padding which impacts any Compose-base tests that use text. https://android-developers.googleblog.com/2024/01/whats-new-in-jetpack-compose-january-24-release.html
- https://github.com/ndtp/android-testify/pull/219 - Upgrade to Gradle 8.6 and AGP 8.4.1
- Define namespace in build.gradle for library projects
- jvmTarget, sourceCompatibility and targetCompatibility set to Java 17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import dev.testify.accessibility.internal.AccessibilityScreenshotLifecycleObserv
* collects various accessibility-related checks on [View] objects as well as AccessibilityNodeInfo objects (which the
* Android framework derives from Views and sends to AccessibilityServices).
*
* @see https://developer.android.com/training/testing/espresso/accessibility-checking
* @see "https://developer.android.com/training/testing/espresso/accessibility-checking"
*
* All elements within the hierarchy defined by [android.R.id.content] will be available to the check.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import java.io.Reader

internal class CheckResults(other: List<CheckResult>) : ArrayList<CheckResult>(other) {

val hasErrors: Boolean
private val hasErrors: Boolean
get() {
return this.any { it.type == "ERROR" }
}
Expand Down
3 changes: 2 additions & 1 deletion Ext/Compose/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ android {
targetCompatibility JavaVersion.VERSION_17
}
composeOptions {
kotlinCompilerExtensionVersion "1.4.7"
kotlinCompilerExtensionVersion "1.5.14"
}

dependencies {
implementation project(":Library")

implementation(platform(libs.androidx.compose.bom))
implementation libs.androidx.activity.compose
implementation libs.androidx.appcompat
implementation libs.androidx.core.ktx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package dev.testify.compose.scenario

import android.content.Intent
import android.os.Bundle
import androidx.compose.runtime.Composable
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.launchActivity
import dev.testify.ComposableTestActivity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import android.view.View
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import dev.testify.ScreenshotRule
import dev.testify.capture.fullscreen.provider.excludeNavigationBar
import dev.testify.capture.fullscreen.provider.excludeStatusBar
import dev.testify.core.DEFAULT_NAME_FORMAT
import dev.testify.core.DeviceStringFormatter
import dev.testify.core.TestifyConfigurable
Expand All @@ -47,8 +49,8 @@ import dev.testify.testDescription
* The bitmap will be generated from a PNG at 1:1 scale and 100% quality. The bitmap's size will match the full
* device resolution and include all system UI such as the status bar and navigation bar.
*
* As the system UI content is highly variable, you can use [ScreenshotRule.excludeStatusBar] and/or
* [ScreenshotRule.excludeNavigationBar] to ignore the status bar and navigation bar, respectively.
* As the system UI content is highly variable, you can use [excludeStatusBar] and/or
* [excludeNavigationBar] to ignore the status bar and navigation bar, respectively.
*
* Though the PNG is intended to be lossless, some compression artifacts or GPU-related variance can occur. As such,
* it is recommended to use a small tolerance when capturing fullscreen images.
Expand Down Expand Up @@ -80,7 +82,7 @@ fun fullscreenCapture(activity: Activity, targetView: View?): Bitmap {
if (!device.takeScreenshot(file, 1f, 100)) throw FailedToCaptureFullscreenBitmapException()

/**
* The screenshot is written as a PNG to [file] on the emulator. We can use [loadBitmapFromFile]
* The screenshot is written as a PNG to the [Destination] file on the emulator. We can use [loadBitmapFromFile]
* to load it from a file into memory as a [Bitmap].
*/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ val navigationBarExclusionRectProvider: ExclusionRectProvider = { rootView, excl
* Extension method for [TestifyConfiguration] that will add the rectangle covering the system navigation bar to the
* exclusion area.
*/
@Suppress("unused")
fun TestifyConfiguration.excludeNavigationBar() {
defineExclusionRects(navigationBarExclusionRectProvider)
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ val statusBarExclusionRectProvider: ExclusionRectProvider = { rootView, exclusio
* Extension method for [TestifyConfiguration] that will add the rectangle covering the system status bar to the
* exclusion area.
*/
@Suppress("unused")
fun TestifyConfiguration.excludeStatusBar() {
defineExclusionRects(statusBarExclusionRectProvider)
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ScreenshotLifecycleTest {

try {
rule.assertSame()
} catch (e: ScreenshotBaselineNotDefinedException) {
} catch (_: ScreenshotBaselineNotDefinedException) {
}

assertEquals(6, observer.log.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ScreenshotScenarioLifecycleTest {

try {
rule.assertSame()
} catch (e: ScreenshotBaselineNotDefinedException) {
} catch (_: ScreenshotBaselineNotDefinedException) {
}

assertEquals(6, observer.log.size)
Expand Down
8 changes: 5 additions & 3 deletions Library/src/main/java/dev/testify/ScreenshotRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package dev.testify

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Instrumentation
import android.content.Intent
import android.os.Bundle
import android.view.View.NO_ID
Expand All @@ -37,6 +38,7 @@ import androidx.annotation.LayoutRes
import androidx.annotation.VisibleForTesting
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.rule.ActivityTestRule
import dev.testify.annotation.ScreenshotInstrumentation
import dev.testify.annotation.TestifyLayout
import dev.testify.annotation.findAnnotation
import dev.testify.annotation.getScreenshotAnnotationName
Expand Down Expand Up @@ -247,7 +249,7 @@ open class ScreenshotRule<T : Activity> @JvmOverloads constructor(
/**
* Set the Espresso actions to run on the Activity under test before taking a screenshot.
*
* @see https://developer.android.com/training/testing/espresso
* @see "https://developer.android.com/training/testing/espresso"
*
* @ScreenshotInstrumentation
* @Test
Expand Down Expand Up @@ -519,7 +521,7 @@ open class ScreenshotRule<T : Activity> @JvmOverloads constructor(
* This override of ActivityTestRule.getActivityIntent() allows Testify to set up a custom Intent as if supplied to
* android.content.Context.startActivity.
*/
public final override fun getActivityIntent(): Intent? {
public final override fun getActivityIntent(): Intent {
var intent: Intent? = super.getActivityIntent()
if (intent == null) {
intent = getIntent()
Expand Down Expand Up @@ -635,7 +637,7 @@ open class ScreenshotRule<T : Activity> @JvmOverloads constructor(
/**
* Represents one or more actions to be taken at runtime in the course of running a JUnit test suite.
*/
private inner class ScreenshotStatement constructor(private val base: Statement) : Statement() {
private inner class ScreenshotStatement(private val base: Statement) : Statement() {

override fun evaluate() {
try {
Expand Down
3 changes: 2 additions & 1 deletion Library/src/main/java/dev/testify/ScreenshotUtility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import dev.testify.output.getDestination
import dev.testify.output.getFileRelativeToRoot
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import java.io.File

/**
* The default, preferred [BitmapFactory.Options] to use when decoding a [Bitmap].
Expand All @@ -62,7 +63,7 @@ val preferredBitmapOptions: BitmapFactory.Options
* @param bitmap The [Bitmap] to write to disk. If null, this function will return false.
* @param destination The [Destination] to write the bitmap to.
*
* @throws DestinationNotFoundException if the destination cannot be found.
* @throws Exception if the destination cannot be found.
*
* @return true if the bitmap was successfully written to the destination, false otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ package dev.testify.core
import android.app.Activity
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
import android.graphics.Bitmap
import android.graphics.Rect
import android.view.View
import androidx.annotation.IdRes
import androidx.annotation.VisibleForTesting
Expand Down
6 changes: 3 additions & 3 deletions Library/src/main/java/dev/testify/core/DeviceIdentifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import java.util.Locale
/**
* A typealias for the test class and test name.
*
* @param first - The test class name
* @param second - The test method name
* @param `first` - The test class name
* @param `second` - The test method name
*/
typealias TestName = Pair<String, String>

Expand Down Expand Up @@ -70,7 +70,7 @@ fun getDeviceDescription(context: Context): String {
/**
* Returns a string representing the device description.
*
* @param testName - The name of the currently running test
* @param formatter - Utility class for formatting device description strings
* @param format - The format of the device description string
* The following values will be substituted:
* a: API level (ex. 21)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package dev.testify.core
import android.app.Activity
import android.content.pm.ActivityInfo
import android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
import android.graphics.Bitmap
import android.graphics.Rect
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -279,7 +280,7 @@ data class TestifyConfiguration(
/**
* Returns true if the test has defined any exclusion rects.
*/
internal fun hasExclusionRect() = exclusionRects.isNotEmpty()
private fun hasExclusionRect() = exclusionRects.isNotEmpty()

/**
* Get the CaptureMethod that should be used to capture the bitmap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
package dev.testify.core.exception

import dev.testify.resources.TestifyResourcesOverride

/**
* Exception thrown when an activity is missing the [TestifyResourcesOverride] interface.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package dev.testify.core.exception

import dev.testify.output.Destination

/**
* Exception thrown when the [Destination] could not be finalized.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
package dev.testify.core.exception

/**
* Exception thrown when [annotationName] annotation is missing.
* Exception thrown when `annotationName` annotation is missing.
*
* Use of the Gradle plugin requires the specified annotation.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package dev.testify.core.exception

import dev.testify.scenario.ScreenshotScenarioRule

/**
* Exception thrown when no ActivityScenario instance is provided to the ScreenshotScenarioRule.
* The ActivityScenario instance is required to take screenshots.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ typealias AnalyzePixelFunction = (baselinePixel: Int, currentPixel: Int, positio
* A class that allows for parallel processing of pixels in a bitmap.
*
* Uses coroutines to process pixels in two [Bitmap] objects in parallel.
* Used by [BitmapComparator] to compare two bitmaps in parallel.
* Used by [BitmapTransformer] to transform two bitmaps in parallel.
* [analyze] is used to compare two bitmaps in parallel.
* [transform] is used to transform two bitmaps in parallel.
*/
class ParallelPixelProcessor private constructor(
private val configuration: ParallelProcessorConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import kotlin.math.sqrt
* @param b2 second colour's b component
* @return the CIE 2000 colour difference
*/
@Suppress("LocalVariableName")
fun calculateDeltaE(L1: Double, a1: Double, b1: Double, L2: Double, a2: Double, b2: Double): Double {
val lMean = (L1 + L2) / 2.0
val c1 = sqrt(a1 * a1 + b1 * b1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,28 @@ sealed class ManifestPlaceholder(val key: String) {
*
* For example, if the test is running in the `app` module, this will be `app`.
*/
object Module : ManifestPlaceholder(MANIFEST_MODULE_KEY)
data object Module : ManifestPlaceholder(MANIFEST_MODULE_KEY)

/**
* The name of the destination to use for the test.
*
* For example, this would be `sdcard` if the test output is to be saved to the SD card.
*
*/
object Destination : ManifestPlaceholder(MANIFEST_DESTINATION_KEY)
data object Destination : ManifestPlaceholder(MANIFEST_DESTINATION_KEY)

/**
* Whether or not the test is running in record mode.
*/
object RecordMode : ManifestPlaceholder(MANIFEST_IS_RECORD_MODE)
data object RecordMode : ManifestPlaceholder(MANIFEST_IS_RECORD_MODE)

/**
* The requested number of parallel threads to use for the ParallelPixelProcessor.
* Default, or if 0 is set, is equal to the number of CPU cores.
* Minimum is 1.
* Maximum is 4.
*/
object ParallelThreads : ManifestPlaceholder(MANIFEST_PARALLEL_THREADS)
data object ParallelThreads : ManifestPlaceholder(MANIFEST_PARALLEL_THREADS)
}

/**
Expand All @@ -77,7 +77,6 @@ internal fun getMetaDataBundle(context: Context): Bundle? {
val applicationInfo = if (buildVersionSdkInt() >= android.os.Build.VERSION_CODES.TIRAMISU) {
context.packageManager?.getApplicationInfo(context.packageName, PackageManager.ApplicationInfoFlags.of(0))
} else {
@Suppress("DEPRECATION")
context.packageManager?.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA)
}
return applicationInfo?.metaData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ class OrientationHelper(
*
* If the activity was launched in a different orientation than the requested orientation, perform a rotation.
*
* @param activity The activity to change the orientation of.
* @param requestedOrientation The orientation to change to.
* The value must be one of [SCREEN_ORIENTATION_LANDSCAPE] or [SCREEN_ORIENTATION_PORTRAIT].
*/
fun afterActivityLaunched() {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ object ResourceWrapper {
* @param fontScale The font scale to override. If null, the font scale will not be overridden.
* @param locale The locale to override. If null, the locale will not be overridden.
*/
fun <A : Activity> overrideResourceConfiguration(
fun <@Suppress("unused") A : Activity> overrideResourceConfiguration(
fontScale: Float? = null,
locale: Locale? = null
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import android.content.Context
import android.content.res.Configuration
import android.os.Build
import androidx.annotation.VisibleForTesting
import dev.testify.resources.TestifyResourcesOverride

/**
* A wrapped resource that allows for overriding the font scale of the device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package dev.testify.internal.helpers
import android.app.Activity
import android.content.Context
import dev.testify.internal.extensions.updateLocale
import dev.testify.resources.TestifyResourcesOverride
import java.util.Locale

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import android.os.Looper
import android.view.View
import androidx.annotation.IdRes
import androidx.annotation.WorkerThread
import dev.testify.core.TestifyConfiguration
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package dev.testify.internal.modification

import android.view.View
import android.widget.EditText
import dev.testify.core.TestifyConfiguration

/**
* A [ViewModification] that hides the cursor on an [EditText].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package dev.testify.internal.modification
import android.text.method.PasswordTransformationMethod
import android.view.View
import android.widget.EditText
import dev.testify.core.TestifyConfiguration

/**
* A [ViewModification] that hides the password on an [EditText].
Expand All @@ -35,7 +36,7 @@ import android.widget.EditText
* dots. This is useful for hiding passwords in screenshots and ensures that screenshots do not accidentally capture
* the characters mid-transformation.
*
* @see TestifyConfiguration.hidePassword
* @see TestifyConfiguration.hidePasswords
*/
class HidePasswordViewModification : ViewModification() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package dev.testify.internal.modification

import android.view.View
import dev.testify.core.TestifyConfiguration

/**
* A [ViewModification] that hides the scrollbars on a view.
Expand Down
Loading
Loading