Mockito: Difference between doThrow() and thenThrow()

Almost nothing: in simple cases they behave exactly the same. The when syntax reads more like a grammatical sentence in English. Why “almost”? Note that the when style actually contains a call to authenticationService.login. That’s the first expression evaluated in that line, so whatever behavior you have stubbed will happen during the call to when. … Read more

Mockito ArgumentCaptor for Kotlin function

I recommend nhaarman/mockito-kotlin: Using Mockito with Kotlin It solves this through an inline function with a reified type parameter: inline fun <reified T : Any> argumentCaptor() = ArgumentCaptor.forClass(T::class.java) Source: mockito-kotlin/ArgumentCaptor.kt at a6f860461233ba92c7730dd42b0faf9ba2ce9281 ยท nhaarman/mockito-kotlin e.g.: val captor = argumentCaptor<() -> Unit>() verify(someClass).doSomeThing(captor.capture()) or val captor: () -> Unit = argumentCaptor() verify(someClass).doSomeThing(captor.capture())

How to match a possible null parameter in Mockito

From the javadocs of any() Since Mockito 2.1.0, only allow non-null String. As this is a nullable reference, the suggested API to match null wrapper would be isNull(). We felt this change would make tests harness much safer that it was with Mockito 1.x. So, the way to match nullable string arguments is explicit declaration: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)