8000 GitHub - Qlifyw/mionik
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Qlifyw/mionik

Repository files navigation

License: MIT

Mionik

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.

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed the java Runtime Environment(JRE)

Build with

Usage

DSL

    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)

Processing result

    // '.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 { /* */ } 

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
&n 3158 bsp;
 

Languages

0