Logo

0x3d.Site

is designed for aggregating information.
Welcome
check repository here

Kiwi: Fluent assertions for Kotlin projects

License Build Status Awesome Kotlin Badge

Kiwi is multiplatform projects written in pure Kotlin. Except testing it does not use external dependencies

Release

Kiwi is available in SNAPSHOT repository for now

repositories {
    maven {
        url "https://oss.sonatype.org/content/repositories/snapshots"
    }
}

dependencies {
    testImplementation 'org.fromsource:kiwi-core-jvm:0.0.2-SNAPSHOT'
}

Kiwi, Hello World!

Below snippet demonstrates usage of Kiwi assertions for standard type like String

    @Test
    fun `should say hallo to kiwi()` {
        "Kiwi, Hello World!".should startWith "Kiwi" contain "Hello" endWith "!"
    }

Collections

Kiwi supports List, Set and Map

    @Test
    fun `should combine operator in infix chain`() {
        val animals = listOf("kiwi", "hedgehog", "flamingo", "humpback")

        animals.should haveSize 4 contain "humpback" have1st "kiwi"
    }

Numbers

as well as Byte, Short, Int, Long, Float, Double and JVM based numbers like BigDecimal, BigNumber

    @Test
    fun `should check if numer is prime`() {
        val number = 7

        number.should
                .bePositive()
                .beGreaterThan(1)
                .match { number -> (2 until number).all { number % it != 0} }
    }

Dates

LocalDate and LocalDateTime

    @Test
    fun `should check if date meets some conditions`() {
        val date = LocalDate.of(2020, 11, 14)

        date.should
               .beInLeapYear()
               .beInQ4()
               .beBefore(date.plusDays(1))
    }

Custom type

... even custom types are supported

    data class Animal(val name: String, val weight: Int, val mammal: Boolean) {
       fun heavy(): Boolean = weight > 10
    }

    val kiwi     = Animal(name = "kiwi", weight = 1, mammal = true)
    val hedgehog = Animal(name = "hedgehog", weight = 2, mammal = true)
    val flamingo = Animal(name = "flamingo", weight = 5, mammal = false)
    val humpback = Animal(name = "humpback", weight = 5000, mammal = true)


    @Test
    fun `should apply collection operators for list of custom object`() {

        val animals = listOf(kiwi, hedgehog, flamingo, humpback)

        animals.should
                .haveSize(4)
                .contain(flamingo)
                .beSorted { it.weight }
                .filtered { animal -> animal.mammal }
                .matchAny { animal -> animal.heavy() }

    }

JsonPath

If you need json path Kiwi will work too. See Roadmap & Future for more details

    @Test
    fun `should select json paths for json string`() {
        val json = """{
            "kiwi": "kotlin assertion library",
            "github": {
                "developers": ["john", "ben"]
            }
        }"""

        json.should
                .haveJsonPath("$.kiwi")
                .haveJsonPath("$.kiwi", """"kotlin assertion library"""")
                .haveJsonPath("$..developers", """["john", "ben"]""")
                .haveJsonPath("$..developers[0]", """"john"""")
    }

Mix of the operators

Last but not least you can mix all together Different types of operators e.g. Collection, String, Numbers can be used fluently

    @Test
    fun `should mix different types of operators`() {

        val animals = listOf(kiwi, hedgehog, flamingo, humpback)

        animals.should
                .contain(hedgehog)                              // Collection operator
                .last().name                                    // extract
                .should                             
                .match(Regex("[a-z]+"))                         // String operator
    }

Build

Run command below

$ git clone [email protected]/from-source/kiwi.git
$ cd kiwi/
$ ./gradlew clean build

Roadmap & Future

JsonPath evaluation - in progress

Take a look at the JsonPathAcceptanceTest to see which json path selectors are available

    @Test
    fun `should select first book in the store`() {
        val json =  """{ 
            "store": {
                "details": {
                    "name": "Books & Books"
                },
                "books": [
                { 
                    "category": "science",
                    "author": "Douglas Hofstadter",
                    "title": "I Am a Strange Loop",
                    "price": 8.95
                },
                { 
                    "category": "science fiction",
                    "author": "Stanislaw Lem",
                    "title": "Solaris",
                    "isbn": "978-0156027601",
                    "price": 10.99,
                    "details": "Published in 1961"
                }]
            }
        }"""

        json.should
                .haveJsonPath("$.store.details")                                // check if path exists
                .haveJsonPath("$..books[1].category", "science fiction")        // check value of path
                .haveJsonPath("$..books[0]", """{                              
                    "category": "science",
                    "author": "Douglas Hofstadter",
                    "title": "I Am a Strange Loop",
                    "price": 8.95
                }""")
                

    }

Support for more Kotlin types

Sponsored by JetBrains

Kotlin
Kotlin
Kotlin is a modern programming language interoperable with Java, designed for Android development. It offers a concise syntax and powerful features like null safety and coroutines, streamlining app development.
Kotlin | The Kotlin Blog
Kotlin | The Kotlin Blog
Build software better, together
Build software better, together
Build software better, together
Build software better, together
GitHub - z-huang/InnerTune: A Material 3 YouTube Music client for Android
GitHub - z-huang/InnerTune: A Material 3 YouTube Music client for Android
Build software better, together
Build software better, together
quasar/quasar-kotlin at master · puniverse/quasar
quasar/quasar-kotlin at master · puniverse/quasar
Kotlin Programming Language
Kotlin Programming Language
GitHub - KotatsuApp/Kotatsu: Manga reader for Android
GitHub - KotatsuApp/Kotatsu: Manga reader for Android
GitHub - iamr0s/Dhizuku: A Android Application for share DeviceOwner
GitHub - iamr0s/Dhizuku: A Android Application for share DeviceOwner
Kotlin: An Illustrated Guide
Kotlin: An Illustrated Guide
GitHub - cansik/kotlin-latex-listing: A syntax highlighting template for the Kotlin language in LaTeX listings.
GitHub - cansik/kotlin-latex-listing: A syntax highlighting template for the Kotlin language in LaTeX listings.
GitHub - qwertukg/xml-builder: Simplest XML builder for Kotlin
GitHub - qwertukg/xml-builder: Simplest XML builder for Kotlin
GitHub - cesarferreira/kotlin-pluralizer: :sunny: Kotlin extension to pluralize and singularize strings
GitHub - cesarferreira/kotlin-pluralizer: :sunny: Kotlin extension to pluralize and singularize strings
Kotlin Cheat Sheet
Kotlin Cheat Sheet
GitHub - vert-x3/vertx-lang-kotlin: Vert.x for Kotlin
GitHub - vert-x3/vertx-lang-kotlin: Vert.x for Kotlin
GitHub - hotchemi/khronos: An intuitive Date extensions in Kotlin.
GitHub - hotchemi/khronos: An intuitive Date extensions in Kotlin.
GitHub - icela/FriceEngine: :video_game: JVM game engine based on Swing/JavaFX.
GitHub - icela/FriceEngine: :video_game: JVM game engine based on Swing/JavaFX.
GitHub - holgerbrandl/jsonbuilder: A small artefact to build json with kotlin
GitHub - holgerbrandl/jsonbuilder: A small artefact to build json with kotlin
Kotlin Standard Functions cheat-sheet
Kotlin Standard Functions cheat-sheet
GitHub - MarkusAmshove/Kluent: Fluent Assertion-Library for Kotlin
GitHub - MarkusAmshove/Kluent: Fluent Assertion-Library for Kotlin
GitHub - jershell/kbson: Mongo BSON support for kotlinx.serialization.
GitHub - jershell/kbson: Mongo BSON support for kotlinx.serialization.
GitHub - sepatel/tekniq: A framework designed around Kotlin providing Restful HTTP Client, JDBC DSL, Loading Cache, Configurations, Validations, and more
GitHub - sepatel/tekniq: A framework designed around Kotlin providing Restful HTTP Client, JDBC DSL, Loading Cache, Configurations, Validations, and more
GitHub - Ahoo-Wang/Simba: Distributed lock service | 分布式锁服务
GitHub - Ahoo-Wang/Simba: Distributed lock service | 分布式锁服务
GitHub - JetBrains/intellij-community: IntelliJ IDEA Community Edition & IntelliJ Platform
GitHub - JetBrains/intellij-community: IntelliJ IDEA Community Edition & IntelliJ Platform
GitHub - seniorjoinu/reliable-udp: Multiplexed, coroutine-powered reliable UDP for Kotlin using fountain codes
GitHub - seniorjoinu/reliable-udp: Multiplexed, coroutine-powered reliable UDP for Kotlin using fountain codes
GitHub - hypercube1024/firefly: Firefly is an asynchronous web framework for rapid development of high-performance web application.
GitHub - hypercube1024/firefly: Firefly is an asynchronous web framework for rapid development of high-performance web application.
GitHub - davidepianca98/KMQTT: Kotlin Multiplatform MQTT client & embeddable and standalone broker
GitHub - davidepianca98/KMQTT: Kotlin Multiplatform MQTT client & embeddable and standalone broker
GitHub - L-Briand/KTM: Mustache template engine in kotlin multiplatform
GitHub - L-Briand/KTM: Mustache template engine in kotlin multiplatform
GitHub - sergeshustoff/dikt: Simple and powerful DI for kotlin multiplatform
GitHub - sergeshustoff/dikt: Simple and powerful DI for kotlin multiplatform
GitHub - ParserKt/ParserKt: Naive one-pass recursive descent, scannerless parser framework for Kotlin
GitHub - ParserKt/ParserKt: Naive one-pass recursive descent, scannerless parser framework for Kotlin
Kotlin
More on Kotlin

Programming Tips & Tricks

Code smarter, not harder—insider tips and tricks for developers.

Error Solutions

Turn frustration into progress—fix errors faster than ever.

Shortcuts

The art of speed—shortcuts to supercharge your workflow.
  1. Collections 😎
  2. Frequently Asked Question's 🤯

Tools

available to use.

Made with ❤️

to provide resources in various ares.