mockito / mockito-kotlin

Using Mockito with Kotlin
MIT License
3.11k stars 201 forks source link

cant mock/spy internal classes #337

Closed macsystems closed 5 years ago

macsystems commented 5 years ago

Hello,

it looks like its impossible to mock internal kotlin classes

 internal class UnderTest{

      fun methodToTest(){}

}
import com.nhaarman.mockito_kotlin.mock

internal class SimpleTest{
    val mock = mock<UnderTest>()

    @Test
    fun test(){

    } 
}

Running the Test results in a well known exception:

Cannot mock/spy class com.name.UnderTest
Mockito cannot mock/spy because :
- final class

Note: The Test itself need to be internal so that the compiler likes it

nhaarman commented 5 years ago

The exception complains about final classes, not internal. open your class.