|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2024 Mockito contributors |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package org.mockito.kotlin |
| 26 | + |
| 27 | +import org.mockito.AdditionalMatchers |
| 28 | +import org.mockito.kotlin.internal.createInstance |
| 29 | +import kotlin.reflect.KClass |
| 30 | + |
| 31 | +/** comparable argument greater than or equal the given value. */ |
| 32 | +inline fun <reified T : Comparable<T>> geq(value: T): T { |
| 33 | + return AdditionalMatchers.geq(value) ?: createInstance() |
| 34 | +} |
| 35 | + |
| 36 | +/** comparable argument greater than or equal to the given value. */ |
| 37 | +inline fun <reified T : Comparable<T>> leq(value: T): T { |
| 38 | + return AdditionalMatchers.leq(value) ?: createInstance() |
| 39 | +} |
| 40 | + |
| 41 | +/** comparable argument greater than the given value. */ |
| 42 | +inline fun <reified T : Comparable<T>> gt(value: T): T { |
| 43 | + return AdditionalMatchers.gt(value) ?: createInstance() |
| 44 | +} |
| 45 | + |
| 46 | +/** comparable argument less than the given value. */ |
| 47 | +inline fun <reified T : Comparable<T>> lt(value: T): T { |
| 48 | + return AdditionalMatchers.lt(value) ?: createInstance() |
| 49 | +} |
| 50 | + |
| 51 | +/** comparable argument equals to the given value according to their compareTo method. */ |
| 52 | +inline fun <reified T : Comparable<T>> cmpEq(value: T): T { |
| 53 | + return AdditionalMatchers.cmpEq(value) ?: createInstance() |
| 54 | +} |
| 55 | + |
| 56 | +/** |
| 57 | + * Any array argument that is equal to the given array, i.e. it has to have the same type, length, |
| 58 | + * and each element has to be equal. |
| 59 | + */ |
| 60 | +inline fun <reified T> aryEq(value: Array<T>): Array<T> { |
| 61 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 62 | +} |
| 63 | + |
| 64 | +/** |
| 65 | + * short array argument that is equal to the given array, i.e. it has to have the same length, and |
| 66 | + * each element has to be equal. |
| 67 | + */ |
| 68 | +fun aryEq(value: ShortArray): ShortArray { |
| 69 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * long array argument that is equal to the given array, i.e. it has to have the same length, and |
| 74 | + * each element has to be equal. |
| 75 | + */ |
| 76 | +fun aryEq(value: LongArray): LongArray { |
| 77 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 78 | +} |
| 79 | + |
| 80 | +/** |
| 81 | + * int array argument that is equal to the given array, i.e. it has to have the same length, and |
| 82 | + * each element has to be equal. |
| 83 | + */ |
| 84 | +fun aryEq(value: IntArray): IntArray { |
| 85 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 86 | +} |
| 87 | + |
| 88 | +/** |
| 89 | + * float array argument that is equal to the given array, i.e. it has to have the same length, and |
| 90 | + * each element has to be equal. |
| 91 | + */ |
| 92 | +fun aryEq(value: FloatArray): FloatArray { |
| 93 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 94 | +} |
| 95 | + |
| 96 | +/** |
| 97 | + * double array argument that is equal to the given array, i.e. it has to have the same length, and |
| 98 | + * each element has to be equal. |
| 99 | + */ |
| 100 | +fun aryEq(value: DoubleArray): DoubleArray { |
| 101 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 102 | +} |
| 103 | + |
| 104 | +/** |
| 105 | + * char array argument that is equal to the given array, i.e. it has to have the same length, and |
| 106 | + * each element has to be equal. |
| 107 | + */ |
| 108 | +fun aryEq(value: CharArray): CharArray { |
| 109 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 110 | +} |
| 111 | + |
| 112 | +/** |
| 113 | + * byte array argument that is equal to the given array, i.e. it has to have the same length, and |
| 114 | + * each element has to be equal. |
| 115 | + */ |
| 116 | +fun aryEq(value: ByteArray): ByteArray { |
| 117 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 118 | +} |
| 119 | + |
| 120 | +/** |
| 121 | + * boolean array argument that is equal to the given array, i.e. it has to have the same length, and |
| 122 | + * each element has to be equal. |
| 123 | + */ |
| 124 | +fun aryEq(value: BooleanArray): BooleanArray { |
| 125 | + return AdditionalMatchers.aryEq(value) ?: createInstance() |
| 126 | +} |
| 127 | + |
| 128 | +/** String argument that contains a substring that matches the given regular expression. */ |
| 129 | +fun find(regex: Regex): String { |
| 130 | + return AdditionalMatchers.find(regex.pattern) ?: "" |
| 131 | +} |
| 132 | + |
| 133 | +/** argument that matches both given argument matchers. */ |
| 134 | +inline fun <reified T : Any> and(left: T, right: T): T { |
| 135 | + return AdditionalMatchers.and(left, right) ?: createInstance() |
| 136 | +} |
| 137 | + |
| 138 | +/** argument that matches both given argument matchers. */ |
| 139 | +inline fun <reified T : Any> or(left: T, right: T): T { |
| 140 | + return AdditionalMatchers.or(left, right) ?: createInstance() |
| 141 | +} |
| 142 | + |
| 143 | +/** argument that does not match the given argument matcher. */ |
| 144 | +inline fun <reified T : Any> not(matcher: T): T { |
| 145 | + return AdditionalMatchers.not(matcher) ?: createInstance() |
| 146 | +} |
| 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 | +} |
0 commit comments