From 8f8cf85bd1252bc62065b42afef104440fb4fe26 Mon Sep 17 00:00:00 2001 From: Steve Elliott Date: Wed, 6 Mar 2024 15:54:50 -0500 Subject: Shareousel ui layer Bug: 302691505 Flag: ACONFIG android.service.chooser.chooser_payload_toggling DEVELOPMENT Test: atest IntentResolver-tests-unit Change-Id: Ia292f2274c94259b173aa09d187840f03921dfc5 --- .../android/intentresolver/MockitoKotlinHelpers.kt | 66 ++++++++++++---------- .../intentresolver/TestContentPreviewViewModel.kt | 14 +---- 2 files changed, 38 insertions(+), 42 deletions(-) (limited to 'tests/shared/src') diff --git a/tests/shared/src/com/android/intentresolver/MockitoKotlinHelpers.kt b/tests/shared/src/com/android/intentresolver/MockitoKotlinHelpers.kt index db9fbd93..b7b97d6f 100644 --- a/tests/shared/src/com/android/intentresolver/MockitoKotlinHelpers.kt +++ b/tests/shared/src/com/android/intentresolver/MockitoKotlinHelpers.kt @@ -14,14 +14,16 @@ * limitations under the License. */ +@file:Suppress("NOTHING_TO_INLINE") + package com.android.intentresolver /** * Kotlin versions of popular mockito methods that can return null in situations when Kotlin expects * a non-null value. Kotlin will throw an IllegalStateException when this takes place ("x must not * be null"). To fix this, we can use methods that modify the return type to be nullable. This - * causes Kotlin to skip the null checks. - * Cloned from frameworks/base/packages/SystemUI/tests/utils/src/com/android/systemui/util/mockito/KotlinMockitoHelpers.kt + * causes Kotlin to skip the null checks. Cloned from + * frameworks/base/packages/SystemUI/tests/utils/src/com/android/systemui/util/mockito/KotlinMockitoHelpers.kt */ import org.mockito.ArgumentCaptor import org.mockito.ArgumentMatcher @@ -33,42 +35,49 @@ import org.mockito.stubbing.OngoingStubbing import org.mockito.stubbing.Stubber /** - * Returns Mockito.eq() as nullable type to avoid java.lang.IllegalStateException when - * null is returned. + * Returns Mockito.eq() as nullable type to avoid java.lang.IllegalStateException when null is + * returned. * * Generic T is nullable because implicitly bounded by Any?. */ -fun eq(obj: T): T = Mockito.eq(obj) +inline fun eq(obj: T): T = Mockito.eq(obj) ?: obj /** - * Returns Mockito.any() as nullable type to avoid java.lang.IllegalStateException when - * null is returned. + * Returns Mockito.same() as nullable type to avoid java.lang.IllegalStateException when null is + * returned. * * Generic T is nullable because implicitly bounded by Any?. */ -fun any(type: Class): T = Mockito.any(type) -inline fun any(): T = any(T::class.java) +inline fun same(obj: T): T = Mockito.same(obj) ?: obj /** - * Returns Mockito.argThat() as nullable type to avoid java.lang.IllegalStateException when - * null is returned. + * Returns Mockito.any() as nullable type to avoid java.lang.IllegalStateException when null is + * returned. * * Generic T is nullable because implicitly bounded by Any?. */ -fun argThat(matcher: ArgumentMatcher): T = Mockito.argThat(matcher) +inline fun any(type: Class): T = Mockito.any(type) + +inline fun any(): T = any(T::class.java) /** - * Kotlin type-inferred version of Mockito.nullable() + * Returns Mockito.argThat() as nullable type to avoid java.lang.IllegalStateException when null is + * returned. + * + * Generic T is nullable because implicitly bounded by Any?. */ +inline fun argThat(matcher: ArgumentMatcher): T = Mockito.argThat(matcher) + +/** Kotlin type-inferred version of Mockito.nullable() */ inline fun nullable(): T? = Mockito.nullable(T::class.java) /** - * Returns ArgumentCaptor.capture() as nullable type to avoid java.lang.IllegalStateException - * when null is returned. + * Returns ArgumentCaptor.capture() as nullable type to avoid java.lang.IllegalStateException when + * null is returned. * * Generic T is nullable because implicitly bounded by Any?. */ -fun capture(argumentCaptor: ArgumentCaptor): T = argumentCaptor.capture() +inline fun capture(argumentCaptor: ArgumentCaptor): T = argumentCaptor.capture() /** * Helper function for creating an argumentCaptor in kotlin. @@ -90,17 +99,18 @@ inline fun mock( apply: T.() -> Unit = {} ): T = Mockito.mock(T::class.java, mockSettings).apply(apply) +/** Matches any array of type T. */ +inline fun anyArray(): Array = Mockito.any(Array::class.java) ?: arrayOf() + /** * Helper function for stubbing methods without the need to use backticks. * * @see Mockito.when */ -fun whenever(methodCall: T): OngoingStubbing = Mockito.`when`(methodCall) +inline fun whenever(methodCall: T): OngoingStubbing = Mockito.`when`(methodCall) -/** - * Helper function for stubbing methods without the need to use backticks. - */ -fun Stubber.whenever(mock: T): T = `when`(mock) +/** Helper function for stubbing methods without the need to use backticks. */ +inline fun Stubber.whenever(mock: T): T = `when`(mock) /** * A kotlin implemented wrapper of [ArgumentCaptor] which prevents the following exception when @@ -128,13 +138,12 @@ inline fun kotlinArgumentCaptor(): KotlinArgumentCaptor = /** * Helper function for creating and using a single-use ArgumentCaptor in kotlin. * - * val captor = argumentCaptor() - * verify(...).someMethod(captor.capture()) - * val captured = captor.value + * val captor = argumentCaptor() verify(...).someMethod(captor.capture()) val captured = + * captor.value * * becomes: * - * val captured = withArgCaptor { verify(...).someMethod(capture()) } + * val captured = withArgCaptor { verify(...).someMethod(capture()) } * * NOTE: this uses the KotlinArgumentCaptor to avoid the NullPointerException. */ @@ -144,13 +153,12 @@ inline fun withArgCaptor(block: KotlinArgumentCaptor.() -> /** * Variant of [withArgCaptor] for capturing multiple arguments. * - * val captor = argumentCaptor() - * verify(...).someMethod(captor.capture()) - * val captured: List = captor.allValues + * val captor = argumentCaptor() verify(...).someMethod(captor.capture()) val captured: + * List = captor.allValues * * becomes: * - * val capturedList = captureMany { verify(...).someMethod(capture()) } + * val capturedList = captureMany { verify(...).someMethod(capture()) } */ inline fun captureMany(block: KotlinArgumentCaptor.() -> Unit): List = kotlinArgumentCaptor().apply { block() }.allValues diff --git a/tests/shared/src/com/android/intentresolver/TestContentPreviewViewModel.kt b/tests/shared/src/com/android/intentresolver/TestContentPreviewViewModel.kt index b352f360..8f246424 100644 --- a/tests/shared/src/com/android/intentresolver/TestContentPreviewViewModel.kt +++ b/tests/shared/src/com/android/intentresolver/TestContentPreviewViewModel.kt @@ -23,7 +23,6 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewmodel.CreationExtras import com.android.intentresolver.contentpreview.BasePreviewViewModel import com.android.intentresolver.contentpreview.ImageLoader -import com.android.intentresolver.contentpreview.PayloadToggleInteractor /** A test content preview model that supports image loader override. */ class TestContentPreviewViewModel( @@ -34,23 +33,12 @@ class TestContentPreviewViewModel( override val previewDataProvider get() = viewModel.previewDataProvider - override val payloadToggleInteractor: PayloadToggleInteractor? - get() = viewModel.payloadToggleInteractor - override fun init( targetIntent: Intent, - chooserIntent: Intent, additionalContentUri: Uri?, - focusedItemIdx: Int, isPayloadTogglingEnabled: Boolean, ) { - viewModel.init( - targetIntent, - chooserIntent, - additionalContentUri, - focusedItemIdx, - isPayloadTogglingEnabled - ) + viewModel.init(targetIntent, additionalContentUri, isPayloadTogglingEnabled) } companion object { -- cgit v1.2.3-59-g8ed1b