1 package net.pterodactylus.sone.test
3 import com.google.inject.Module
5 import org.mockito.invocation.InvocationOnMock
6 import org.mockito.stubbing.*
8 inline fun <reified T : Any> mock(): T = Mockito.mock<T>(T::class.java)!!
9 inline fun <reified T : Any> mockBuilder(): T = Mockito.mock<T>(T::class.java, Mockito.RETURNS_SELF)!!
10 inline fun <reified T : Any> deepMock(): T = Mockito.mock<T>(T::class.java, Mockito.RETURNS_DEEP_STUBS)!!
11 inline fun <reified T : Any> selfMock(): T = Mockito.mock<T>(T::class.java, Mockito.RETURNS_SELF)!!
12 inline fun <reified T : Any> capture(): ArgumentCaptor<T> = ArgumentCaptor.forClass(T::class.java)
14 inline fun <reified E: Throwable> OngoingStubbing<*>.doThrow(): OngoingStubbing<*> = thenThrow(E::class.java)
16 inline fun <reified T : Any> bind(implementation: T): Module =
17 Module { it!!.bind(T::class.java).toInstance(implementation) }
19 inline fun <reified T : Any> bindMock(): Module =
20 Module { it!!.bind(T::class.java).toInstance(mock()) }
22 inline fun <reified T: Any?> whenever(methodCall: T) = Mockito.`when`(methodCall)!!
23 inline fun <reified T: Any?> Stubber.whenever(mock: T) = `when`(mock)!!
25 inline fun <reified T : Any> OngoingStubbing<T>.thenReturnMock(): OngoingStubbing<T> = this.thenReturn(mock())
27 operator fun <T> InvocationOnMock.get(index: Int): T = getArgument(index)
29 inline fun <reified T> argumentCaptor(): ArgumentCaptor<T> = ArgumentCaptor.forClass<T, T>(T::class.java)!!
32 ArgumentMatchers.eq(t)