Best Kluent code snippet using org.amshove.kluent.VerifyKeyword.ensureMock
Mocking.kt
Source:Mocking.kt
...14infix fun <T> OngoingVerification.on(mock: T) = verify(mock, times(numInvocations))15infix fun <T> VerifyKeyword.on(mock: T) = verify(mock)16infix fun <T> VerifyNotCalledKeyword.on(mock: T) = verify(mock, never())17infix fun <T> T.that(mock: T): T {18 ensureMock(this)19 return this.apply { mock.run { Unit } }20}21infix fun <T : Any> VerifyNoInteractionsKeyword.on(mock: T) = verifyZeroInteractions(mock)22infix fun <T> VerifyNoFurtherInteractionsKeyword.on(mock: T) = verifyNoMoreInteractions(mock)23infix fun <T> T.was(n: CalledKeyword) = n24@Suppress("UNUSED_PARAMETER") // Backward compatibility25inline fun <reified T : Any> any(kClass: KClass<T>): T = any()26inline fun <reified T : Any> any(): T = com.nhaarman.mockitokotlin2.any()27infix fun <T> WhenKeyword.calling(methodCall: T): OngoingStubbing<T> = `when`(methodCall)28infix fun <T> OngoingStubbing<T>.itReturns(value: T): OngoingStubbing<T> = this.thenReturn(value)29infix fun <T> OngoingStubbing<T>.itThrows(value: Throwable): OngoingStubbing<T> = this.thenThrow(value)30infix fun <T> OngoingStubbing<T>.itAnswers(value: (InvocationOnMock) -> T): OngoingStubbing<T> = this.thenAnswer(value)31infix fun <T> OngoingStubbing<T>.itAnswers(value: Answer<T>): OngoingStubbing<T> = this.thenAnswer(value)32/**33 * Returns the parameter of an invocation at the given position.34 * @param position Location of the parameter to return, zero based.35 * @see [returnsArgAt]36 */37fun <T> withArgAt(position: Int): Answer<T> = returnsArgAt(position)38fun <T> withFirstArg(): Answer<T> = returnsFirstArg()39fun <T> withSecondArg(): Answer<T> = returnsSecondArg()40fun <T> withThirdArg(): Answer<T> = withArgAt(2)41fun <T> withFourthArg(): Answer<T> = withArgAt(3)42fun <T> withLastArg(): Answer<T> = returnsLastArg()43private fun <T> ensureMock(obj: T) {44 if (!MockUtil.isMock(obj)) {45 throw Exception(46 """47 $obj is no mock.48 Ensure to always determine the mock with the `on` method.49 Example:50 Verify on myMock that myMock.getPerson() was called51 /\52 --------53 """54 )55 }56}57val When = WhenKeyword()...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!