ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - from-source/kiwi: Fluent assertions for Kotlin
Fluent assertions for Kotlin. Contribute to from-source/kiwi development by creating an account on GitHub.
Visit Site

GitHub - from-source/kiwi: Fluent assertions for Kotlin

GitHub - from-source/kiwi: Fluent assertions for Kotlin

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

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory