Skip to content

Commit acd5fbb

Browse files
authored
Merge pull request #176 from nhaarman/same
Make `same` return non-null type
2 parents e0c1475 + 76872e8 commit acd5fbb

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ fun <T> refEq(value: T, vararg excludeFields: String): T? = Mockito.refEq(value,
236236

237237
fun <T> reset(vararg mocks: T) = Mockito.reset(*mocks)
238238

239-
fun <T> same(value: T): T? = Mockito.same(value) ?: value
239+
fun <T> same(value: T): T = Mockito.same(value) ?: value
240240

241241
inline fun <reified T : Any> spy(): T = Mockito.spy(T::class.java)!!
242242
fun <T> spy(value: T): T = Mockito.spy(value)!!

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,4 +983,28 @@ class MockitoTest : TestBase() {
983983
verify(this).nullableString(isA<String>())
984984
}
985985
}
986+
987+
@Test
988+
fun same_withNonNullArgument() {
989+
mock<Methods>().apply {
990+
string("")
991+
verify(this).string(same(""))
992+
}
993+
}
994+
995+
@Test
996+
fun same_withNullableNonNullArgument() {
997+
mock<Methods>().apply {
998+
nullableString("")
999+
verify(this).nullableString(same(""))
1000+
}
1001+
}
1002+
1003+
@Test
1004+
fun same_withNullArgument() {
1005+
mock<Methods>().apply {
1006+
nullableString(null)
1007+
verify(this).nullableString(same(null))
1008+
}
1009+
}
9861010
}

0 commit comments

Comments
 (0)