All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.spoptchev.kotlin.preconditions.matcher.CollectionMatcher.kt Maven / Gradle / Ivy

There is a newer version: 6.1.0
Show newest version
package com.github.spoptchev.kotlin.preconditions.matcher

import com.github.spoptchev.kotlin.preconditions.Condition
import com.github.spoptchev.kotlin.preconditions.Matcher


interface CollectionMatcher {

    fun  hasSize(size: Int) = object : Matcher>() {
        override fun test(condition: Condition>) = condition.test {
            withResult(value.size == size) { "$expectedTo have size $size but has size ${value.size}"}
        }
    }

    fun  contains(element: T) = object : Matcher>() {
        override fun test(condition: Condition>) = condition.test {
            withResult(value.contains(element)) { "$expectedTo contain element $element" }
        }
    }

    fun  isEmpty() = object : Matcher>() {
        override fun test(condition: Condition>) = condition.test {
            withResult(value.isEmpty()) { "$expectedTo be empty" }
        }
    }

    fun  containsAll(vararg values: T) = containsAll(values.asList())
    fun  containsAll(values: Collection) = object : Matcher>() {
        override fun test(condition: Condition>) = condition.test {
            withResult(values.all(value::contains)) { "$expectedTo contain all values of $values" }
        }
    }

    fun > isSorted() = object : Matcher>() {
        override fun test(condition: Condition>) = condition.test {
            withResult(value.sorted() == value) { "$expectedTo be sorted" }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy