
name.remal.mockito.strictMock.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common Show documentation
Show all versions of common Show documentation
Java & Kotlin tools: test: common
The newest version!
package name.remal.mockito
import com.nhaarman.mockito_kotlin.KStubbing
import com.nhaarman.mockito_kotlin.mock
import org.mockito.Incubating
import org.mockito.Mockito.`when`
import org.mockito.listeners.InvocationListener
import org.mockito.mock.SerializableMode
import java.lang.System.identityHashCode
import kotlin.reflect.KClass
inline fun strictMock(
extraInterfaces: Array>? = null,
name: String? = null,
spiedInstance: Any? = null,
serializable: Boolean = false,
serializableMode: SerializableMode? = null,
verboseLogging: Boolean = false,
invocationListeners: Array? = null,
stubOnly: Boolean = false,
@Incubating useConstructor: Boolean = false,
@Incubating outerInstance: Any? = null,
stubbing: KStubbing.(T) -> Unit
): T {
val defaultAnswer = StrictMockAnswer()
val mock = mock(
extraInterfaces = extraInterfaces,
name = name,
spiedInstance = spiedInstance,
defaultAnswer = defaultAnswer,
serializable = serializable,
serializableMode = serializableMode,
verboseLogging = verboseLogging,
invocationListeners = invocationListeners,
stubOnly = stubOnly,
useConstructor = useConstructor,
outerInstance = outerInstance,
stubbing = stubbing
)
// We want toString() to be stubbed be default:
`when`(mock.toString()).thenReturn(T::class.java.simpleName + "@" + identityHashCode(mock))
defaultAnswer.isEnabled = true
return mock
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy