Skip to content

Commit

Permalink
Add default collection size
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinwong11 committed Jun 25, 2024
1 parent b4b2298 commit abf7095
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import kotlin.reflect.KClass
import kotlin.reflect.full.primaryConstructor
import kotlin.reflect.javaType

private const val DEFAULT_COLLECTION_SIZE = 3

/**
* Generates a test object for the given data class, where each field is given an actual,
* unique value (as opposed to just some default value like empty string or null).
Expand Down Expand Up @@ -66,22 +68,24 @@ import kotlin.reflect.javaType
* specify a consistent value for this field.
* @param useNullForNullableFields If true, then all fields that are nullable will be set to null,
* unless specified in the overrides map.
* @param collectionSize If specified, supported collection types will be set to that size rather
* than
* @return The generated object.
*/
fun <T : Any> KClass<T>.generateTestObject(
prefix: String = "",
overrides: Map<Regex, Any?>? = null,
referenceDate: Date? = null,
useNullForNullableFields: Boolean = false,
collectionSize: Int = 3,
collectionSize: Int = DEFAULT_COLLECTION_SIZE,
): T {
return generateTestObject(
prefix,
Parameters(
overrides,
referenceDate,
useNullForNullableFields,
collectionSize, // TODO enforce size >= 1
collectionSize.takeIf { it > 0 } ?: DEFAULT_COLLECTION_SIZE,
)
)
}
Expand Down

0 comments on commit abf7095

Please sign in to comment.