View on GitHub

Kluent

Fluent Assertion-Library for Kotlin

CharSequence assertions

The following assertions work with every subtype of CharSequence (e.g. String)

"name" shouldBeEqualTo "name"
"name" shouldNotBeEqualTo "abc"

"name" shouldStartWith "n"
"age" shouldNotStartWith "n"

"name" shouldEndWith "me"
"name" shouldNotEndWith "ee"

"name" shouldContain "am"
"name" shouldNotContain "abc"

"I like fluent assertions" shouldContainSome listOf("fluent", "not", "test")
"I like fluent assertions" shouldContainNone listOf("test, "compile")

"name" shouldMatch "\\w+"
"name" shouldNotMatch "\\d+"

"name" shouldMatch Regex("\\w+")
"name" shouldNotMatch Regex("\\d+")

"".shouldBeEmpty()
"name".shouldNotBeEmpty()
"" `should be` Empty
"name" `should not be` Empty

"".shouldBeNullOrEmpty()
"name".shouldNotBeNullOrEmpty()
"" `should be` NullOrEmpty
"name" `should not be` NullOrEmpty

" ".shouldBeBlank()
"name".shouldNotBeBlank()
" " `should be` Blank
"name" `should not be` Blank

" ".shouldBeNullOrBlank()
"".shouldNotBeNullOrBlank()
" " `should be` NullOrBlank
"" `should not be` NullOrBlank

In case if you need to assert Char or CharSequence ignoring the characters case, you can use the following assertions:

"name" shouldBeEqualToIgnoringCase "nAmE"
"name" shouldNotBeEqualToIgnoringCase "abc"

"name" shouldStartWithIgnoringCase "N"
"age" shouldNotStartWithIgnoringCase "n"

"name" shouldEndWithIgnoringCase "ME"
"name" shouldNotEndWithIgnoringCase "ee"

"name" shouldContainIgnoringCase "Am"
"name" shouldNotContainIgnoringCase "abc"

"I like fluent assertions" shouldContainSomeIgnoringCase listOf("Fluent", "NOT", "tesT")
"I like fluent assertions" shouldContainNoneIgnoringCase listOf("test, "compile")