Skip to content

argThat() causes TypeCastException #133

@StepanOvsyankin

Description

@StepanOvsyankin
interface HelloSrv {
    fun sayHello(to: String): String
}

class AnyTest {
    @Test fun `should create non-null values`() {
        mock<HelloSrv> {
            on { sayHello(argThat { this == "A" }) } doReturn "A"
            on { sayHello(argThat { this == "B" }) } doReturn "B" // <--- fails here
        }
    }
}

fails with

kotlin.TypeCastException: null cannot be cast to non-null type kotlin.String

	at kkk.command.AnyTest$should create non-null values$mock$1$1$$special$$inlined$argThat$1.matches(Mockito.kt:55)
	at org.mockito.internal.invocation.TypeSafeMatching.apply(TypeSafeMatching.java:24)
	at org.mockito.internal.invocation.MatcherApplicationStrategy.forEachMatcherAndArgument(MatcherApplicationStrategy.java:82)
	at org.mockito.internal.invocation.InvocationMatcher.argumentsMatch(InvocationMatcher.java:152)
	at org.mockito.internal.invocation.InvocationMatcher.matches(InvocationMatcher.java:81)
	at org.mockito.internal.stubbing.InvocationContainerImpl.findAnswerFor(InvocationContainerImpl.java:82)
	at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:88)
	at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:32)
	at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:36)
	at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:41)
	at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptAbstract(MockMethodInterceptor.java:120)
	at kkk.command.HelloSrv$MockitoMock$934695312.sayHello(Unknown Source)
	at kkk.command.AnyTest$should create non-null values$mock$1$2.invoke(AnyTest.kt:16)
	at kkk.command.AnyTest$should create non-null values$mock$1$2.invoke(AnyTest.kt:12)
	at com.nhaarman.mockito_kotlin.KStubbing.on(Mockito.kt:119)
	at kkk.command.AnyTest.should create non-null values(AnyTest.kt:16)

mockito-kotlin: 1.0.0
mockito: 2.2.28

Metadata

Metadata

Assignees

Labels

type:bugBehavior not according to spec

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions