1 package net.pterodactylus.sone.test
3 import com.google.inject.Module
4 import org.mockito.ArgumentCaptor
5 import org.mockito.Mockito
6 import org.mockito.invocation.InvocationOnMock
7 import org.mockito.stubbing.OngoingStubbing
9 inline fun <reified T : Any> mock(): T = Mockito.mock<T>(T::class.java)!!
10 inline fun <reified T : Any> mockBuilder(): T = Mockito.mock<T>(T::class.java, Mockito.RETURNS_SELF)!!
11 inline fun <reified T : Any> deepMock(): T = Mockito.mock<T>(T::class.java, Mockito.RETURNS_DEEP_STUBS)!!
12 inline fun <reified T : Any> selfMock(): T = Mockito.mock<T>(T::class.java, Mockito.RETURNS_SELF)!!
13 inline fun <reified T : Any> capture(): ArgumentCaptor<T> = ArgumentCaptor.forClass(T::class.java)
15 inline fun <reified E: Throwable> OngoingStubbing<*>.doThrow(): OngoingStubbing<*> = thenThrow(E::class.java)
17 inline fun <reified T : Any> bind(implementation: T): Module =
18 Module { it!!.bind(T::class.java).toInstance(implementation) }
20 inline fun <reified T : Any> bindMock(): Module =
21 Module { it!!.bind(T::class.java).toInstance(mock<T>()) }
23 inline fun <reified T: Any?> whenever(methodCall: T) = Mockito.`when`(methodCall)!!
25 inline fun <reified T : Any> OngoingStubbing<T>.thenReturnMock(): OngoingStubbing<T> = this.thenReturn(mock<T>())
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)!!