Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip methods from file identifiers. #84

Merged
merged 1 commit into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}