diff --git a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MockitoKotlin.kt b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MockitoKotlin.kt index 2158d7a9..6c07cf62 100644 --- a/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MockitoKotlin.kt +++ b/mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/MockitoKotlin.kt @@ -78,6 +78,8 @@ class MockitoKotlin { ?.second } - private fun StackTraceElement.toFileIdentifier() = "$fileName$className" + private fun StackTraceElement.toFileIdentifier() = "$fileName$className".let { + if (it.contains("$")) it.substring(0..it.indexOf("$") - 1) else it + } } } diff --git a/mockito-kotlin/src/test/kotlin/MockitoKotlinTest.kt b/mockito-kotlin/src/test/kotlin/MockitoKotlinTest.kt index 3b5774f6..b0465d1c 100644 --- a/mockito-kotlin/src/test/kotlin/MockitoKotlinTest.kt +++ b/mockito-kotlin/src/test/kotlin/MockitoKotlinTest.kt @@ -24,12 +24,17 @@ */ import com.nhaarman.expect.expect -import com.nhaarman.mockito_kotlin.MockitoKotlin -import com.nhaarman.mockito_kotlin.createInstance +import com.nhaarman.mockito_kotlin.* +import org.junit.After import org.junit.Test class MockitoKotlinTest { + @After + fun teardown() { + MockitoKotlin.resetInstanceCreators() + } + @Test fun register() { /* Given */ @@ -56,4 +61,18 @@ class MockitoKotlinTest { /* Then */ expect(result).toNotBeTheSameAs(closed) } + + @Test + fun usingInstanceCreatorInsideLambda() { + MockitoKotlin.registerInstanceCreator { CreateInstanceTest.ForbiddenConstructor(2) } + + mock { + on { doSomething(any()) } doReturn "" + } + } + + interface TestClass { + + fun doSomething(c: CreateInstanceTest.ForbiddenConstructor): String + } }