diff --git a/packages/SystemUI/tests/src/com/android/systemui/util/mockito/KotlinMockitoHelpers.kt b/packages/SystemUI/tests/src/com/android/systemui/util/mockito/KotlinMockitoHelpers.kt index bff99bf340d61..483dc9fc42b29 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/util/mockito/KotlinMockitoHelpers.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/util/mockito/KotlinMockitoHelpers.kt @@ -58,3 +58,24 @@ fun capture(argumentCaptor: ArgumentCaptor): T = argumentCaptor.capture() */ inline fun argumentCaptor(): ArgumentCaptor = ArgumentCaptor.forClass(T::class.java) + +/** + * Helper function for creating new mocks, without the need to pass in a [Class] instance. + * + * Generic T is nullable because implicitly bounded by Any?. + */ +inline fun mock(): T = Mockito.mock(T::class.java) + +/** + * Helper function for creating and using a single-use ArgumentCaptor in kotlin. + * + * val captor = argumentCaptor() + * verify(...).someMethod(captor.capture()) + * val captured = captor.value + * + * becomes: + * + * val captured = withArgCaptor { verify(...).someMethod(capture()) } + */ +inline fun withArgCaptor(block: ArgumentCaptor.() -> Unit): T = + argumentCaptor().apply { block() }.value \ No newline at end of file