Skip to content

Commit

Permalink
Strip methods from file identifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaarman committed Oct 3, 2016
1 parent 1025568 commit 1d65fc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
23 changes: 21 additions & 2 deletions mockito-kotlin/src/test/kotlin/MockitoKotlinTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -56,4 +61,18 @@ class MockitoKotlinTest {
/* Then */
expect(result).toNotBeTheSameAs(closed)
}

@Test
fun usingInstanceCreatorInsideLambda() {
MockitoKotlin.registerInstanceCreator { CreateInstanceTest.ForbiddenConstructor(2) }

mock<TestClass> {
on { doSomething(any()) } doReturn ""
}
}

interface TestClass {

fun doSomething(c: CreateInstanceTest.ForbiddenConstructor): String
}
}

0 comments on commit 1d65fc0

Please sign in to comment.