Skip to content

Commit 9c4234e

Browse files
authored
Merge pull request #73 from nhaarman/release-0.6.2
Release 0.6.2
2 parents f18d86e + cf06555 commit 9c4234e

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

mockito-kotlin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repositories {
2020
dependencies {
2121
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
2222
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
23-
compile "org.mockito:mockito-core:2.1.0-beta.125"
23+
compile "org.mockito:mockito-core:2.1.0-RC.1"
2424

2525
/* Tests */
2626
testCompile "junit:junit:4.12"

mockito-kotlin/src/main/kotlin/com/nhaarman/mockito_kotlin/Mockito.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ import kotlin.reflect.KClass
3939

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

42+
/** Matches any object, excluding nulls. */
4243
inline fun <reified T : Any> any() = Mockito.any(T::class.java) ?: createInstance<T>()
43-
inline fun <reified T : Any?> anyArray(): Array<T> = Mockito.any(Array<T>::class.java) ?: arrayOf()
44+
/** Matches anything, including nulls. */
45+
inline fun <reified T : Any> anyOrNull(): T = Mockito.any<T>() ?: createInstance<T>()
46+
/** Matches any vararg object, including nulls. */
4447
inline fun <reified T : Any> anyVararg(): T = Mockito.any<T>() ?: createInstance<T>()
48+
/** Matches any array of type T. */
49+
inline fun <reified T : Any?> anyArray(): Array<T> = Mockito.any(Array<T>::class.java) ?: arrayOf()
4550
inline fun <reified T : Any> argThat(noinline predicate: T.() -> Boolean) = Mockito.argThat<T> { it -> (it as T).predicate() } ?: createInstance(T::class)
51+
inline fun <reified T : Any> argForWhich(noinline predicate: T.() -> Boolean) = argThat(predicate)
4652

4753
fun atLeast(numInvocations: Int): VerificationMode = Mockito.atLeast(numInvocations)!!
4854
fun atLeastOnce(): VerificationMode = Mockito.atLeastOnce()!!

mockito-kotlin/src/test/kotlin/Classes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface Methods {
5151
fun string(s: String)
5252
fun closedVararg(vararg c: Closed)
5353
fun throwableClass(t: ThrowableClass)
54+
fun nullableString(s: String?)
5455

5556
fun stringResult(): String
5657
}

mockito-kotlin/src/test/kotlin/MockitoTest.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ class MockitoTest {
116116
}
117117
}
118118

119+
@Test
120+
fun anyNull_neverVerifiesAny() {
121+
mock<Methods>().apply {
122+
nullableString(null)
123+
verify(this, never()).nullableString(any())
124+
}
125+
}
126+
127+
@Test
128+
fun anyNull_verifiesAnyOrNull() {
129+
mock<Methods>().apply {
130+
nullableString(null)
131+
verify(this).nullableString(anyOrNull())
132+
}
133+
}
134+
119135
@Test
120136
fun anyThrowableWithSingleThrowableConstructor() {
121137
mock<Methods>().apply {
@@ -134,6 +150,16 @@ class MockitoTest {
134150
}
135151
}
136152

153+
@Test
154+
fun listArgForWhich() {
155+
mock<Methods>().apply {
156+
closedList(listOf(Closed(), Closed()))
157+
verify(this).closedList(argForWhich {
158+
size == 2
159+
})
160+
}
161+
}
162+
137163
@Test
138164
fun atLeastXInvocations() {
139165
mock<Methods>().apply {

0 commit comments

Comments
 (0)