Add captureMany { } mockito test utility

Bug: 241121499
Test: atest SystemUITests
Change-Id: I5cea416923549d433dd4e58183a45a0f60223b6a
This commit is contained in:
Steve Elliott
2022-09-03 22:13:03 -04:00
parent 494fbd29d2
commit 6597c29a89

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 =
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