Merge "Add captureMany { } mockito test utility" into tm-qpr-dev am: 3a24aba20e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19859999

Change-Id: Ide09bcd4d0e4d272d51e2910688f582d860bf764
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Steve Elliott
2022-09-08 20:46:40 +00:00
committed by Automerger Merge Worker

View File

@@ -118,3 +118,17 @@ inline fun <reified T : Any> kotlinArgumentCaptor(): KotlinArgumentCaptor<T> =
*/ */
inline fun <reified T : Any> withArgCaptor(block: KotlinArgumentCaptor<T>.() -> Unit): T = inline fun <reified T : Any> withArgCaptor(block: KotlinArgumentCaptor<T>.() -> Unit): T =
kotlinArgumentCaptor<T>().apply { block() }.value kotlinArgumentCaptor<T>().apply { block() }.value
/**
* Variant of [withArgCaptor] for capturing multiple arguments.
*
* val captor = argumentCaptor<Foo>()
* verify(...).someMethod(captor.capture())
* val captured: List<Foo> = captor.allValues
*
* becomes:
*
* val capturedList = captureMany<Foo> { verify(...).someMethod(capture()) }
*/
inline fun <reified T : Any> captureMany(block: KotlinArgumentCaptor<T>.() -> Unit): List<T> =
kotlinArgumentCaptor<T>().apply{ block() }.allValues