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

Follow-up on #508: add tests and remove unnecessary methods #516

Merged
merged 4 commits into from
Apr 9, 2024
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 @@ -26,7 +26,6 @@ package org.mockito.kotlin

import org.mockito.AdditionalMatchers
import org.mockito.kotlin.internal.createInstance
import kotlin.reflect.KClass

/** comparable argument greater than or equal the given value. */
inline fun <reified T : Comparable<T>> geq(value: T): T {
Expand Down Expand Up @@ -144,19 +143,3 @@ inline fun <reified T : Any> or(left: T, right: T): T {
inline fun <reified T : Any> not(matcher: T): T {
return AdditionalMatchers.not(matcher) ?: createInstance()
}

/**
* float argument that has an absolute difference to the given value that is
* less than the given delta details.
*/
fun eq(value: Double, delta: Double): Double {
return AdditionalMatchers.eq(value, delta) ?: 0.0
}

/**
* double argument that has an absolute difference to the given value that
* is less than the given delta details.
*/
fun eq(value: Float, delta: Float): Float {
return AdditionalMatchers.eq(value, delta) ?: 0.0f
}
67 changes: 65 additions & 2 deletions tests/src/test/kotlin/test/AdditionalMatchersTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,77 @@ class AdditionalCaptorsTest : TestBase() {
}

@Test
fun testAryEqPrimitive() {
fun testAryEqBoolean() {
mock<Methods>().apply {
booleanArray(booleanArrayOf(true, false, true))
verify(this).booleanArray(aryEq(booleanArrayOf(true, false, true)))
verify(this, never()).booleanArray(aryEq(booleanArrayOf(true, false)))
}
}

@Test
fun testAryEqByte() {
mock<Methods>().apply {
byteArray(byteArrayOf(1, 2, 3))
verify(this).byteArray(aryEq(byteArrayOf(1, 2, 3)))
verify(this, never()).byteArray(aryEq(byteArrayOf(1, 2)))
}
}

@Test
fun testAryEqShort() {
mock<Methods>().apply {
shortArray(shortArrayOf(1, 2, 3))
verify(this).shortArray(aryEq(shortArrayOf(1, 2, 3)))
verify(this, never()).shortArray(aryEq(shortArrayOf(1, 2)))
}
}

@Test
fun testAryEqInt() {
mock<Methods>().apply {
intArray(intArrayOf(1, 2, 3))
verify(this).intArray(aryEq(intArrayOf(1, 2, 3)))
verify(this, never()).intArray(aryEq(intArrayOf(1, 2)))
}
}

@Test
fun testAryEqLong() {
mock<Methods>().apply {
longArray(longArrayOf(1, 2, 3))
verify(this).longArray(aryEq(longArrayOf(1, 2, 3)))
verify(this, never()).longArray(aryEq(longArrayOf(1, 2)))
}
}

@Test
fun testAryEqChar() {
mock<Methods>().apply {
charArray(charArrayOf('1', '2', '3'))
verify(this).charArray(aryEq(charArrayOf('1', '2', '3')))
verify(this, never()).charArray(aryEq(charArrayOf('1', '2')))
}
}

@Test
fun testAryEqFloat() {
mock<Methods>().apply {
floatArray(floatArrayOf(1f, 2f, 3.4f))
verify(this).floatArray(aryEq(floatArrayOf(1f, 2f, 3.4f)))
verify(this, never()).floatArray(aryEq(floatArrayOf(1f, 2f)))
}
}

@Test
fun testAryEqDouble() {
mock<Methods>().apply {
doubleArray(doubleArrayOf(1.0, 2.0, 3.4))
verify(this).doubleArray(aryEq(doubleArrayOf(1.0, 2.0, 3.4)))
verify(this, never()).doubleArray(aryEq(doubleArrayOf(1.0, 2.0)))
}
}

@Test
fun testAryEq() {
mock<Methods>().apply {
Expand All @@ -71,7 +134,7 @@ class AdditionalCaptorsTest : TestBase() {
}

@Test
fun testfind() {
fun testFind() {
mock<Methods>().apply {
string("Hello")
verify(this).string(find("l+o$".toRegex()))
Expand Down
9 changes: 8 additions & 1 deletion tests/src/test/kotlin/test/Classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Closed

interface Methods {

fun intArray(i: IntArray)
fun closed(c: Closed)
fun closedArray(a: Array<Closed>)
fun closedNullableArray(a: Array<Closed?>)
Expand All @@ -54,13 +53,21 @@ interface Methods {
fun closedSet(s: Set<Closed>)
fun string(s: String)
fun boolean(b: Boolean)
fun booleanArray(d: BooleanArray)
fun byte(b: Byte)
fun byteArray(b: ByteArray)
fun char(c: Char)
fun charArray(c: CharArray)
fun short(s: Short)
fun shortArray(s: ShortArray)
fun int(i: Int)
fun intArray(i: IntArray)
fun long(l: Long)
fun longArray(l: LongArray)
fun float(f: Float)
fun floatArray(f: FloatArray)
fun double(d: Double)
fun doubleArray(d: DoubleArray)
fun closedVararg(vararg c: Closed)
fun throwableClass(t: ThrowableClass)
fun nullableString(s: String?)
Expand Down
Loading