Skip to content

Commit

Permalink
Merge pull request #73 from nhaarman/release-0.6.2
Browse files Browse the repository at this point in the history
Release 0.6.2
  • Loading branch information
nhaarman authored Sep 21, 2016
2 parents f18d86e + cf06555 commit 9c4234e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mockito-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.mockito:mockito-core:2.1.0-beta.125"
compile "org.mockito:mockito-core:2.1.0-RC.1"

/* Tests */
testCompile "junit:junit:4.12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ import kotlin.reflect.KClass

fun after(millis: Long) = Mockito.after(millis)

/** Matches any object, excluding nulls. */
inline fun <reified T : Any> any() = Mockito.any(T::class.java) ?: createInstance<T>()
inline fun <reified T : Any?> anyArray(): Array<T> = Mockito.any(Array<T>::class.java) ?: arrayOf()
/** Matches anything, including nulls. */
inline fun <reified T : Any> anyOrNull(): T = Mockito.any<T>() ?: createInstance<T>()
/** Matches any vararg object, including nulls. */
inline fun <reified T : Any> anyVararg(): T = Mockito.any<T>() ?: createInstance<T>()
/** Matches any array of type T. */
inline fun <reified T : Any?> anyArray(): Array<T> = Mockito.any(Array<T>::class.java) ?: arrayOf()
inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean) = Mockito.argThat<T> { it -> (it as T).predicate() } ?: createInstance(T::class)
inline fun <reified T : Any> argForWhich(noinline predicate: T.() -> Boolean) = argThat(predicate)

fun atLeast(numInvocations: Int): VerificationMode = Mockito.atLeast(numInvocations)!!
fun atLeastOnce(): VerificationMode = Mockito.atLeastOnce()!!
Expand Down
1 change: 1 addition & 0 deletions mockito-kotlin/src/test/kotlin/Classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface Methods {
fun string(s: String)
fun closedVararg(vararg c: Closed)
fun throwableClass(t: ThrowableClass)
fun nullableString(s: String?)

fun stringResult(): String
}
Expand Down
26 changes: 26 additions & 0 deletions mockito-kotlin/src/test/kotlin/MockitoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ class MockitoTest {
}
}

@Test
fun anyNull_neverVerifiesAny() {
mock<Methods>().apply {
nullableString(null)
verify(this, never()).nullableString(any())
}
}

@Test
fun anyNull_verifiesAnyOrNull() {
mock<Methods>().apply {
nullableString(null)
verify(this).nullableString(anyOrNull())
}
}

@Test
fun anyThrowableWithSingleThrowableConstructor() {
mock<Methods>().apply {
Expand All @@ -134,6 +150,16 @@ class MockitoTest {
}
}

@Test
fun listArgForWhich() {
mock<Methods>().apply {
closedList(listOf(Closed(), Closed()))
verify(this).closedList(argForWhich {
size == 2
})
}
}

@Test
fun atLeastXInvocations() {
mock<Methods>().apply {
Expand Down

0 comments on commit 9c4234e

Please sign in to comment.