-
-
Notifications
You must be signed in to change notification settings - Fork 331
/
AnyValueGenerator.kt
38 lines (32 loc) · 1.19 KB
/
AnyValueGenerator.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package io.mockk.impl.instantiation
import kotlin.reflect.KClass
open class AnyValueGenerator {
open fun anyValue(cls: KClass<*>, orInstantiateVia: () -> Any?): Any? {
return when (cls) {
Boolean::class -> false
Byte::class -> 0.toByte()
Short::class -> 0.toShort()
Char::class -> 0.toChar()
Int::class -> 0
Long::class -> 0L
Float::class -> 0.0F
Double::class -> 0.0
String::class -> ""
BooleanArray::class -> BooleanArray(0)
ByteArray::class -> ByteArray(0)
CharArray::class -> CharArray(0)
ShortArray::class -> ShortArray(0)
IntArray::class -> IntArray(0)
LongArray::class -> LongArray(0)
FloatArray::class -> FloatArray(0)
DoubleArray::class -> DoubleArray(0)
List::class -> List<Any>(0) {}
Map::class -> HashMap<Any, Any>()
Set::class -> HashSet<Any>()
ArrayList::class -> ArrayList<Any>()
HashMap::class -> HashMap<Any, Any>()
HashSet::class -> HashSet<Any>()
else -> orInstantiateVia()
}
}
}