mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.09k stars 198 forks source link

Mock Android Secure static method #452

Open ruazakharo opened 2 years ago

ruazakharo commented 2 years ago

My code:

Settings.Secure.getString(context.contentResolver, Settings.Secure.ANDROID_ID).toLowerCase()

and I'm trying to mock it

Mockito.mockStatic(Settings.Secure::class.java).use { utilities ->
      utilities.`when`<Any> { Settings.Secure.getString(anyVararg(), anyVararg()) }.thenReturn("test")
}

Error :

getString must not be null
java.lang.NullPointerException: getString must not be null

mockito vesrion - 4.0.0