Mionik
is an tool that allows your to create an instance of kotlin class on the fly. It creates an object and fills its properties with random values, but imposing restrictions as specified by the user.
Before you begin, ensure you have met the following requirements:
- You have installed the
java Runtime Environment(JRE)
val config = configuration {
properties {
isNullableGenerated = false // property marked as nullable will not be generated
itemsInCollection = 2 // will be generated 2 items in each collection
}
restriction {
// Set value by property data type
// For property with type UUID with be generated random uuid
bound(UUID::class) { UUID.randomUUID() }
// Set value by property name
// For property 'name' set value "John"
bound(Person::name) { "John" }
}
}
val person = morph(Person::class, config)
// '.get' may throw exception if something gone wrong
val person: Result<Person, ReflectionError> = morph(Person::class, config).get
// handle fail
val person: Result<Person, ReflectionError> = morph(Person::class, config)
.doOnError { /* do something */ }
// or
val person: Result<Person, ReflectionError> = morph(Person::class, config)
.orThrow { error -> throw CustomException(error.description) }
// See also
val person: Result<Person, ReflectionError> = morph(Person::class, config)
.map { /* map value if success */ }
val person: Result<Person, ReflectionError> = morph(Person::class, config)
.mapError { /* convert error */ }
val person: Result<Person, ReflectionError> = morph(Person::class, config)
.bind { /* */ }