Skip to content

Commit 57f4d0a

Browse files
authored
Follow-up on #508: add tests and remove unnecessary methods (#516)
Found via: > Task :mockito-kotlin:compileKotlin w: AdditionalMatchers.kt:153:48 Elvis operator (?:) always returns the left operand of non-nullable type Double w: AdditionalMatchers.kt:161:48 Elvis operator (?:) always returns the left operand of non-nullable type Float
1 parent 44cada2 commit 57f4d0a

File tree

3 files changed

+73
-20
lines changed

3 files changed

+73
-20
lines changed

Diff for: mockito-kotlin/src/main/kotlin/org/mockito/kotlin/AdditionalMatchers.kt

-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ package org.mockito.kotlin
2626

2727
import org.mockito.AdditionalMatchers
2828
import org.mockito.kotlin.internal.createInstance
29-
import kotlin.reflect.KClass
3029

3130
/** comparable argument greater than or equal the given value. */
3231
inline fun <reified T : Comparable<T>> geq(value: T): T {
@@ -144,19 +143,3 @@ inline fun <reified T : Any> or(left: T, right: T): T {
144143
inline fun <reified T : Any> not(matcher: T): T {
145144
return AdditionalMatchers.not(matcher) ?: createInstance()
146145
}
147-
148-
/**
149-
* float argument that has an absolute difference to the given value that is
150-
* less than the given delta details.
151-
*/
152-
fun eq(value: Double, delta: Double): Double {
153-
return AdditionalMatchers.eq(value, delta) ?: 0.0
154-
}
155-
156-
/**
157-
* double argument that has an absolute difference to the given value that
158-
* is less than the given delta details.
159-
*/
160-
fun eq(value: Float, delta: Float): Float {
161-
return AdditionalMatchers.eq(value, delta) ?: 0.0f
162-
}

Diff for: tests/src/test/kotlin/test/AdditionalMatchersTest.kt

+65-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,77 @@ class AdditionalCaptorsTest : TestBase() {
5353
}
5454

5555
@Test
56-
fun testAryEqPrimitive() {
56+
fun testAryEqBoolean() {
57+
mock<Methods>().apply {
58+
booleanArray(booleanArrayOf(true, false, true))
59+
verify(this).booleanArray(aryEq(booleanArrayOf(true, false, true)))
60+
verify(this, never()).booleanArray(aryEq(booleanArrayOf(true, false)))
61+
}
62+
}
63+
64+
@Test
65+
fun testAryEqByte() {
66+
mock<Methods>().apply {
67+
byteArray(byteArrayOf(1, 2, 3))
68+
verify(this).byteArray(aryEq(byteArrayOf(1, 2, 3)))
69+
verify(this, never()).byteArray(aryEq(byteArrayOf(1, 2)))
70+
}
71+
}
72+
73+
@Test
74+
fun testAryEqShort() {
75+
mock<Methods>().apply {
76+
shortArray(shortArrayOf(1, 2, 3))
77+
verify(this).shortArray(aryEq(shortArrayOf(1, 2, 3)))
78+
verify(this, never()).shortArray(aryEq(shortArrayOf(1, 2)))
79+
}
80+
}
81+
82+
@Test
83+
fun testAryEqInt() {
5784
mock<Methods>().apply {
5885
intArray(intArrayOf(1, 2, 3))
5986
verify(this).intArray(aryEq(intArrayOf(1, 2, 3)))
6087
verify(this, never()).intArray(aryEq(intArrayOf(1, 2)))
6188
}
6289
}
6390

91+
@Test
92+
fun testAryEqLong() {
93+
mock<Methods>().apply {
94+
longArray(longArrayOf(1, 2, 3))
95+
verify(this).longArray(aryEq(longArrayOf(1, 2, 3)))
96+
verify(this, never()).longArray(aryEq(longArrayOf(1, 2)))
97+
}
98+
}
99+
100+
@Test
101+
fun testAryEqChar() {
102+
mock<Methods>().apply {
103+
charArray(charArrayOf('1', '2', '3'))
104+
verify(this).charArray(aryEq(charArrayOf('1', '2', '3')))
105+
verify(this, never()).charArray(aryEq(charArrayOf('1', '2')))
106+
}
107+
}
108+
109+
@Test
110+
fun testAryEqFloat() {
111+
mock<Methods>().apply {
112+
floatArray(floatArrayOf(1f, 2f, 3.4f))
113+
verify(this).floatArray(aryEq(floatArrayOf(1f, 2f, 3.4f)))
114+
verify(this, never()).floatArray(aryEq(floatArrayOf(1f, 2f)))
115+
}
116+
}
117+
118+
@Test
119+
fun testAryEqDouble() {
120+
mock<Methods>().apply {
121+
doubleArray(doubleArrayOf(1.0, 2.0, 3.4))
122+
verify(this).doubleArray(aryEq(doubleArrayOf(1.0, 2.0, 3.4)))
123+
verify(this, never()).doubleArray(aryEq(doubleArrayOf(1.0, 2.0)))
124+
}
125+
}
126+
64127
@Test
65128
fun testAryEq() {
66129
mock<Methods>().apply {
@@ -71,7 +134,7 @@ class AdditionalCaptorsTest : TestBase() {
71134
}
72135

73136
@Test
74-
fun testfind() {
137+
fun testFind() {
75138
mock<Methods>().apply {
76139
string("Hello")
77140
verify(this).string(find("l+o$".toRegex()))

Diff for: tests/src/test/kotlin/test/Classes.kt

+8-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class Closed
4444

4545
interface Methods {
4646

47-
fun intArray(i: IntArray)
4847
fun closed(c: Closed)
4948
fun closedArray(a: Array<Closed>)
5049
fun closedNullableArray(a: Array<Closed?>)
@@ -54,13 +53,21 @@ interface Methods {
5453
fun closedSet(s: Set<Closed>)
5554
fun string(s: String)
5655
fun boolean(b: Boolean)
56+
fun booleanArray(d: BooleanArray)
5757
fun byte(b: Byte)
58+
fun byteArray(b: ByteArray)
5859
fun char(c: Char)
60+
fun charArray(c: CharArray)
5961
fun short(s: Short)
62+
fun shortArray(s: ShortArray)
6063
fun int(i: Int)
64+
fun intArray(i: IntArray)
6165
fun long(l: Long)
66+
fun longArray(l: LongArray)
6267
fun float(f: Float)
68+
fun floatArray(f: FloatArray)
6369
fun double(d: Double)
70+
fun doubleArray(d: DoubleArray)
6471
fun closedVararg(vararg c: Closed)
6572
fun throwableClass(t: ThrowableClass)
6673
fun nullableString(s: String?)

0 commit comments

Comments
 (0)