All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.mockk.impl.instantiation.AnyValueGenerator.kt Maven / Gradle / Ivy

There is a newer version: 1.13.12
Show newest version
package io.mockk.impl.instantiation

import kotlin.reflect.KClass

open class AnyValueGenerator {
    open fun anyValue(cls: KClass<*>, isNullable: Boolean, orInstantiateVia: () -> Any?): Any? =
        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(0) {}
            Map::class -> HashMap()
            Set::class -> HashSet()
            ArrayList::class -> ArrayList()
            HashMap::class -> HashMap()
            HashSet::class -> HashSet()

            else -> orInstantiateVia()
        }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy