How to use containNoNulls method of io.kotest.matchers.collections.nulls class

Best Kotest code snippet using io.kotest.matchers.collections.nulls.containNoNulls

CollectionMatchersTest.kt

Source:CollectionMatchersTest.kt Github

copy

Full Screen

...12import io.kotest.matchers.collections.beSameSizeAs13import io.kotest.matchers.collections.beSmallerThan14import io.kotest.matchers.collections.contain15import io.kotest.matchers.collections.containDuplicates16import io.kotest.matchers.collections.containNoNulls17import io.kotest.matchers.collections.containNull18import io.kotest.matchers.collections.containOnlyNulls19import io.kotest.matchers.collections.matchInOrder20import io.kotest.matchers.collections.existInOrder21import io.kotest.matchers.collections.haveElementAt22import io.kotest.matchers.collections.haveSize23import io.kotest.matchers.collections.matchEach24import io.kotest.matchers.collections.matchInOrderSubset25import io.kotest.matchers.collections.monotonicallyDecreasing26import io.kotest.matchers.collections.monotonicallyDecreasingWith27import io.kotest.matchers.collections.monotonicallyIncreasing28import io.kotest.matchers.collections.monotonicallyIncreasingWith29import io.kotest.matchers.collections.shouldBeIn30import io.kotest.matchers.collections.shouldBeLargerThan31import io.kotest.matchers.collections.shouldBeMonotonicallyDecreasing32import io.kotest.matchers.collections.shouldBeMonotonicallyDecreasingWith33import io.kotest.matchers.collections.shouldBeMonotonicallyIncreasing34import io.kotest.matchers.collections.shouldBeMonotonicallyIncreasingWith35import io.kotest.matchers.collections.shouldBeSameSizeAs36import io.kotest.matchers.collections.shouldBeSingleton37import io.kotest.matchers.collections.shouldBeSmallerThan38import io.kotest.matchers.collections.shouldBeSorted39import io.kotest.matchers.collections.shouldBeSortedBy40import io.kotest.matchers.collections.shouldBeSortedWith41import io.kotest.matchers.collections.shouldBeStrictlyDecreasing42import io.kotest.matchers.collections.shouldBeStrictlyDecreasingWith43import io.kotest.matchers.collections.shouldBeStrictlyIncreasing44import io.kotest.matchers.collections.shouldBeStrictlyIncreasingWith45import io.kotest.matchers.collections.shouldContainAnyOf46import io.kotest.matchers.collections.shouldContainDuplicates47import io.kotest.matchers.collections.shouldContainNoNulls48import io.kotest.matchers.collections.shouldContainNull49import io.kotest.matchers.collections.shouldContainOnlyNulls50import io.kotest.matchers.collections.shouldExist51import io.kotest.matchers.collections.shouldHaveAtLeastSize52import io.kotest.matchers.collections.shouldHaveAtMostSize53import io.kotest.matchers.collections.shouldHaveElementAt54import io.kotest.matchers.collections.shouldHaveSingleElement55import io.kotest.matchers.collections.shouldHaveSize56import io.kotest.matchers.collections.shouldMatchInOrder57import io.kotest.matchers.collections.shouldMatchInOrderSubset58import io.kotest.matchers.collections.shouldNotBeIn59import io.kotest.matchers.collections.shouldNotBeMonotonicallyDecreasing60import io.kotest.matchers.collections.shouldNotBeMonotonicallyDecreasingWith61import io.kotest.matchers.collections.shouldNotBeMonotonicallyIncreasing62import io.kotest.matchers.collections.shouldNotBeMonotonicallyIncreasingWith63import io.kotest.matchers.collections.shouldNotBeSingleton64import io.kotest.matchers.collections.shouldNotBeSorted65import io.kotest.matchers.collections.shouldNotBeSortedBy66import io.kotest.matchers.collections.shouldNotBeSortedWith67import io.kotest.matchers.collections.shouldNotBeStrictlyDecreasing68import io.kotest.matchers.collections.shouldNotBeStrictlyDecreasingWith69import io.kotest.matchers.collections.shouldNotBeStrictlyIncreasing70import io.kotest.matchers.collections.shouldNotBeStrictlyIncreasingWith71import io.kotest.matchers.collections.shouldNotContainAnyOf72import io.kotest.matchers.collections.shouldNotContainDuplicates73import io.kotest.matchers.collections.shouldNotContainNoNulls74import io.kotest.matchers.collections.shouldNotContainNull75import io.kotest.matchers.collections.shouldNotContainOnlyNulls76import io.kotest.matchers.collections.shouldNotHaveElementAt77import io.kotest.matchers.collections.shouldNotHaveSize78import io.kotest.matchers.collections.shouldNotMatchEach79import io.kotest.matchers.collections.shouldNotMatchInOrder80import io.kotest.matchers.collections.shouldNotMatchInOrderSubset81import io.kotest.matchers.collections.singleElement82import io.kotest.matchers.collections.sorted83import io.kotest.matchers.collections.strictlyDecreasing84import io.kotest.matchers.collections.strictlyDecreasingWith85import io.kotest.matchers.collections.strictlyIncreasing86import io.kotest.matchers.collections.strictlyIncreasingWith87import io.kotest.matchers.ints.shouldBeGreaterThan88import io.kotest.matchers.ints.shouldBeInRange89import io.kotest.matchers.should90import io.kotest.matchers.shouldBe91import io.kotest.matchers.shouldHave92import io.kotest.matchers.shouldNot93import io.kotest.matchers.shouldNotBe94import io.kotest.matchers.shouldNotHave95import io.kotest.matchers.throwable.shouldHaveMessage96class CollectionMatchersTest : WordSpec() {97 private val countdown = (10 downTo 0).toList()98 private val asc = { a: Int, b: Int -> a - b }99 private val desc = { a: Int, b: Int -> b - a }100 init {101 "a descending non-empty list" should {102 "fail to ascend" {103 shouldFail {104 countdown.shouldBeSortedWith(asc)105 }106 }107 "descend" {108 countdown.shouldBeSortedWith(desc)109 }110 "not ascend" {111 countdown.shouldNotBeSortedWith(asc)112 }113 "fail not to descend" {114 shouldFail {115 countdown.shouldNotBeSortedWith(desc)116 }117 }118 }119 "sortedWith" should {120 val items = listOf(121 1 to "I",122 2 to "II",123 4 to "IV",124 5 to "V",125 6 to "VI",126 9 to "IX",127 10 to "X"128 )129 "work on non-Comparable given a Comparator" {130 items.shouldBeSortedWith(Comparator { a, b -> asc(a.first, b.first) })131 }132 "work on non-Comparable given a compare function" {133 items.shouldBeSortedWith { a, b -> asc(a.first, b.first) }134 }135 }136 "haveElementAt" should {137 "test that a collection contains the specified element at the given index" {138 listOf("a", "b", "c") should haveElementAt(1, "b")139 listOf("a", "b", "c") shouldNot haveElementAt(1, "c")140 listOf("a", "b", null) should haveElementAt(2, null)141 listOf("a", "b", null) shouldNot haveElementAt(3, null)142 listOf("a", "b", "c").shouldHaveElementAt(1, "b")143 listOf("a", "b", "c").shouldNotHaveElementAt(1, "c")144 listOf("a", "b", null).shouldHaveElementAt(2, null)145 }146 "support type inference for subtypes of collection" {147 val tests = listOf(148 TestSealed.Test1("test1"),149 TestSealed.Test2(2)150 )151 tests should haveElementAt(0, TestSealed.Test1("test1"))152 tests.shouldHaveElementAt(1, TestSealed.Test2(2))153 }154 }155 "containNull()" should {156 "test that a collection contains at least one null" {157 listOf(1, 2, null) should containNull()158 listOf(null) should containNull()159 listOf(1, 2) shouldNot containNull()160 listOf(1, 2, null).shouldContainNull()161 listOf(null).shouldContainNull()162 listOf(1, 2).shouldNotContainNull()163 }164 }165 "sorted" should {166 "test that a collection is sorted" {167 emptyList<Int>() shouldBe sorted<Int>()168 listOf(1) shouldBe sorted<Int>()169 listOf(1, 2, 3, 4) shouldBe sorted<Int>()170 shouldThrow<AssertionError> {171 listOf(2, 1) shouldBe sorted<Int>()172 }.shouldHaveMessage("List [2, 1] should be sorted. Element 2 at index 0 was greater than element 1")173 listOf(1, 2, 6, 9).shouldBeSorted()174 shouldThrow<AssertionError> {175 listOf(2, 1).shouldBeSorted()176 }.shouldHaveMessage("List [2, 1] should be sorted. Element 2 at index 0 was greater than element 1")177 shouldThrow<AssertionError> {178 listOf(1, 2, 3).shouldNotBeSorted()179 }.shouldHaveMessage("List [1, 2, 3] should not be sorted")180 }181 "restrict items at the error message" {182 val longList = (1..1000).toList()183 shouldThrow<AssertionError> {184 longList.shouldNotBeSorted()185 }.shouldHaveMessage("List [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...and 980 more (set the 'kotest.assertions.collection.print.size' JVM property to see more / less items)] should not be sorted")186 }187 }188 "sortedBy" should {189 val items = listOf(190 1 to "I",191 2 to "II",192 4 to "IV",193 5 to "V",194 6 to "VI",195 9 to "IX",196 10 to "X"197 )198 "compare by the tranformed value" {199 items.shouldBeSortedBy { it.first }200 items.shouldNotBeSortedBy { it.second }201 }202 }203 "shouldBeIncreasing" should {204 "test that a collection is monotonically increasing" {205 listOf(1, 2, 2, 3) shouldBe monotonicallyIncreasing<Int>()206 listOf(6, 5) shouldNotBe monotonicallyIncreasing<Int>()207 listOf(1, 2, 2, 3).shouldBeMonotonicallyIncreasing()208 listOf(6, 5).shouldNotBeMonotonicallyIncreasing()209 }210 "test that a collection is monotonically increasing according to comparator" {211 val comparator = Comparator(desc)212 listOf(3, 2, 2, 1) shouldBe monotonicallyIncreasingWith(comparator)213 listOf(5, 6) shouldNotBe monotonicallyIncreasingWith(comparator)214 listOf(3, 2, 2, 1).shouldBeMonotonicallyIncreasingWith(comparator)215 listOf(5, 6).shouldNotBeMonotonicallyIncreasingWith(comparator)216 }217 "test that a collection is strictly increasing" {218 listOf(1, 2, 3) shouldBe strictlyIncreasing<Int>()219 listOf(1, 2, 2, 3) shouldNotBe strictlyIncreasing<Int>()220 listOf(6, 5) shouldNotBe strictlyIncreasing<Int>()221 listOf(1, 2, 3).shouldBeStrictlyIncreasing()222 listOf(1, 2, 2, 3).shouldNotBeStrictlyIncreasing()223 listOf(6, 5).shouldNotBeStrictlyIncreasing()224 }225 "test that a collection is strictly increasing according to comparator" {226 val comparator = Comparator(desc)227 listOf(3, 2, 1) shouldBe strictlyIncreasingWith(comparator)228 listOf(3, 2, 2, 1) shouldNotBe strictlyIncreasingWith(comparator)229 listOf(5, 6) shouldNotBe strictlyIncreasingWith(comparator)230 listOf(3, 2, 1).shouldBeStrictlyIncreasingWith(comparator)231 listOf(3, 2, 2, 1).shouldNotBeStrictlyIncreasingWith(comparator)232 listOf(5, 6).shouldNotBeStrictlyIncreasingWith(comparator)233 }234 }235 "shouldBeDecreasing" should {236 "test that a collection is monotonically decreasing" {237 listOf(3, 2, 2, -4) shouldBe monotonicallyDecreasing<Int>()238 listOf(5, 6) shouldNotBe monotonicallyDecreasing<Int>()239 listOf(3, 2, 2, -4).shouldBeMonotonicallyDecreasing()240 listOf(5, 6).shouldNotBeMonotonicallyDecreasing()241 }242 "test that a collection is monotonically decreasing according to comparator" {243 val comparator = Comparator(desc)244 listOf(-4, 2, 2, 3) shouldBe monotonicallyDecreasingWith(comparator)245 listOf(6, 5) shouldNotBe monotonicallyDecreasingWith(comparator)246 listOf(-4, 2, 2, 3).shouldBeMonotonicallyDecreasingWith(comparator)247 listOf(6, 5).shouldNotBeMonotonicallyDecreasingWith(comparator)248 }249 "test that a collection is strictly decreasing" {250 listOf(3, 2, -4) shouldBe strictlyDecreasing<Int>()251 listOf(3, 2, 2, -4) shouldNotBe strictlyDecreasing<Int>()252 listOf(5, 6) shouldNotBe strictlyDecreasing<Int>()253 listOf(3, 2, -4).shouldBeStrictlyDecreasing()254 listOf(3, 2, 2, -4).shouldNotBeStrictlyDecreasing()255 listOf(5, 6).shouldNotBeStrictlyDecreasing()256 }257 "test that a collection is strictly decreasing according to comparator" {258 val comparator = Comparator(desc)259 listOf(-4, 2, 3) shouldBe strictlyDecreasingWith(comparator)260 listOf(-4, 2, 2, 3) shouldNotBe strictlyDecreasingWith(comparator)261 listOf(6, 5) shouldNotBe strictlyDecreasingWith(comparator)262 listOf(-4, 2, 3).shouldBeStrictlyDecreasingWith(comparator)263 listOf(-4, 2, 2, 3).shouldNotBeStrictlyDecreasingWith(comparator)264 listOf(6, 5).shouldNotBeStrictlyDecreasingWith(comparator)265 }266 }267 "haveDuplicates" should {268 "test that a collection is unique" {269 listOf(1, 2, 3, 3) should containDuplicates()270 listOf(1, 2, 3, 4) shouldNot containDuplicates()271 listOf(1, 2, 3, 3).shouldContainDuplicates()272 listOf(1, 2, 3, 4).shouldNotContainDuplicates()273 }274 }275 "singleElement" should {276 "test that a collection contains a single given element" {277 listOf(1) shouldBe singleElement(1)278 listOf(1).shouldHaveSingleElement(1)279 shouldThrow<AssertionError> {280 listOf(1) shouldBe singleElement(2)281 }.shouldHaveMessage("Collection should be a single element of 2 but has 1 elements: [1]")282 shouldThrow<AssertionError> {283 listOf(1, 2) shouldBe singleElement(2)284 }.shouldHaveMessage("Collection should be a single element of 2 but has 2 elements: [1, 2]")285 }286 }287 "singleElement with predicate" should {288 "test that a collection contains a single element by given predicate" {289 listOf(1) shouldHave singleElement { e -> e == 1 }290 listOf(1).shouldHaveSingleElement { e -> e == 1 }291 shouldThrow<AssertionError> {292 listOf(1) shouldHave singleElement { e -> e == 2 }293 }.shouldHaveMessage("Collection should have a single element by a given predicate but has 0 elements: [1]")294 shouldThrow<AssertionError> {295 listOf(2, 2) shouldHave singleElement { e -> e == 2 }296 }.shouldHaveMessage("Collection should have a single element by a given predicate but has 2 elements: [2, 2]")297 }298 }299 "should contain element" should {300 "test that a collection contains an element" {301 val col = listOf(1, 2, 3)302 col should contain(2)303 col should contain(2.0) // uses strict num equality = false304 shouldThrow<AssertionError> {305 col should contain(4)306 }.shouldHaveMessage("Collection should contain element 4 based on object equality; but the collection is [1, 2, 3]")307 }308 }309 "should contain element based on a custom equality object" should {310 "test that a collection contains an element" {311 val col = listOf(1, 2, 3.0)312 val verifier = Equality.byObjectEquality<Number>(strictNumberEquality = true)313 col should contain(2, verifier)314 col should contain(3.0, verifier)315 shouldThrow<AssertionError> {316 col should contain(3, verifier)317 }.shouldHaveMessage("Collection should contain element 3 based on object equality; but the collection is [1, 2, 3.0]")318 }319 }320 "shouldBeLargerThan" should {321 "test that a collection is larger than another collection" {322 val col1 = listOf(1, 2, 3)323 val col2 = setOf(1, 2, 3, 4)324 col2.shouldBeLargerThan(col1)325 col2 should beLargerThan(col1)326 col1 shouldNot beLargerThan(col2)327 shouldThrow<AssertionError> {328 col1.shouldBeLargerThan(col2)329 }.shouldHaveMessage("Collection of size 3 should be larger than collection of size 4")330 }331 }332 "shouldBeSmallerThan" should {333 "test that a collection is smaller than another collection" {334 val col1 = listOf(1, 2, 3)335 val col2 = setOf(1, 2, 3, 4)336 col1.shouldBeSmallerThan(col2)337 col1 should beSmallerThan(col2)338 col2 shouldNot beSmallerThan(col1)339 shouldThrow<AssertionError> {340 col2.shouldBeSmallerThan(col1)341 }.shouldHaveMessage("Collection of size 4 should be smaller than collection of size 3")342 }343 }344 "shouldBeSameSizeAs" should {345 "test that a collection is the same size as another collection" {346 val col1 = listOf(1, 2, 3)347 val col2 = setOf(1, 2, 3)348 val col3 = listOf(1, 2, 3, 4)349 col1.shouldBeSameSizeAs(col2)350 col1 should beSameSizeAs(col2)351 col1 shouldNot beSameSizeAs(col3)352 shouldThrow<AssertionError> {353 col1.shouldBeSameSizeAs(col3)354 }.shouldHaveMessage("Collection of size 3 should be the same size as collection of size 4")355 }356 }357 "haveSize" should {358 "test that a collection has a certain size" {359 val col1 = listOf(1, 2, 3)360 col1 should haveSize(3)361 col1.shouldHaveSize(3)362 shouldThrow<AssertionError> {363 col1 should haveSize(2)364 }365 val col2 = emptyList<String>()366 col2 should haveSize(0)367 shouldThrow<AssertionError> {368 col2 should haveSize(1)369 }370 listOf(1, 2, 3).shouldNotHaveSize(1)371 listOf(1, 2, 3).shouldNotHaveSize(4)372 shouldThrow<AssertionError> {373 listOf(1, 2, 3).shouldNotHaveSize(3)374 }.shouldHaveMessage("Collection should not have size 3. Values: [1, 2, 3]")375 }376 }377 "should be singleton" should {378 "pass for collection with a single element" {379 listOf(1).shouldBeSingleton()380 }381 "fail for collection with 0 elements" {382 shouldThrow<AssertionError> {383 listOf<Int>().shouldBeSingleton()384 }.shouldHaveMessage("Collection should have size 1 but has size 0. Values: []")385 }386 "fail for collection with 2+ elements" {387 shouldThrow<AssertionError> {388 listOf(1, 2).shouldBeSingleton()389 }.shouldHaveMessage("Collection should have size 1 but has size 2. Values: [1, 2]")390 shouldThrow<AssertionError> {391 listOf(1, 2, 3, 4).shouldBeSingleton()392 }.shouldHaveMessage("Collection should have size 1 but has size 4. Values: [1, 2, 3, 4]")393 }394 }395 "should be singleton with block" should {396 "pass for collection with a single element" {397 listOf(1).shouldBeSingleton { it shouldBe 1 }398 }399 "fail for collection with 0 elements" {400 shouldThrow<AssertionError> {401 listOf<Int>().shouldBeSingleton { it shouldBe 1 }402 }.shouldHaveMessage("Collection should have size 1 but has size 0. Values: []")403 }404 "fail for collection with a single incorrect elements" {405 shouldThrow<AssertionError> {406 listOf(2).shouldBeSingleton { it shouldBe 1 }407 }.shouldHaveMessage("expected:<1> but was:<2>")408 }409 "fail for collection with 2+ elements" {410 shouldThrow<AssertionError> {411 listOf(1, 2).shouldBeSingleton { it shouldBe 1 }412 }.shouldHaveMessage("Collection should have size 1 but has size 2. Values: [1, 2]")413 shouldThrow<AssertionError> {414 listOf(1, 2, 3, 4).shouldBeSingleton { it shouldBe 1 }415 }.shouldHaveMessage("Collection should have size 1 but has size 4. Values: [1, 2, 3, 4]")416 }417 }418 "should not be singleton" should {419 "pass for collection with 0 elements" {420 listOf<Int>().shouldNotBeSingleton()421 }422 "pass for collection with 2+ elements" {423 listOf(1, 2).shouldNotBeSingleton()424 listOf(1, 2, 3, 4).shouldNotBeSingleton()425 }426 "fail for collection with a single element" {427 shouldThrow<AssertionError> {428 listOf(1).shouldNotBeSingleton()429 }.shouldHaveMessage("Collection should not have size 1. Values: [1]")430 }431 }432 "shouldExist" should {433 "test that a collection contains at least one element that matches a predicate" {434 val list = listOf(1, 2, 3)435 list.shouldExist { it == 2 }436 }437 }438 "shouldHaveAtLeastSize" should {439 "test that a collection has at least a certain number of elements" {440 val list = listOf(1, 2, 3)441 list.shouldHaveAtLeastSize(2)442 list shouldHave atLeastSize(2)443 val set = setOf(1, 2, 3)444 set.shouldHaveAtLeastSize(3)445 set shouldHave atLeastSize(3)446 shouldThrow<AssertionError> {447 list.shouldHaveAtLeastSize(4)448 }.shouldHaveMessage("Collection [1, 2, 3] should contain at least 4 elements")449 shouldThrow<AssertionError> {450 list shouldHave atLeastSize(4)451 }.shouldHaveMessage("Collection [1, 2, 3] should contain at least 4 elements")452 shouldThrow<AssertionError> {453 list shouldNotHave atLeastSize(2)454 }.shouldHaveMessage("Collection [1, 2, 3] should contain less than 2 elements")455 }456 }457 "shouldHaveAtMostSize" should {458 "test that a collection has at least a certain number of elements" {459 val list = listOf(1, 2, 3)460 list.shouldHaveAtMostSize(3)461 list shouldHave atMostSize(3)462 list.shouldHaveAtMostSize(4)463 list shouldHave atMostSize(4)464 val set = setOf(1, 2, 3)465 set.shouldHaveAtMostSize(3)466 set shouldHave atMostSize(3)467 set.shouldHaveAtMostSize(4)468 set shouldHave atMostSize(4)469 shouldThrow<AssertionError> {470 list.shouldHaveAtMostSize(2)471 }.shouldHaveMessage("Collection [1, 2, 3] should contain at most 2 elements")472 shouldThrow<AssertionError> {473 list shouldHave atMostSize(2)474 }.shouldHaveMessage("Collection [1, 2, 3] should contain at most 2 elements")475 shouldThrow<AssertionError> {476 list shouldNotHave atMostSize(4)477 }.shouldHaveMessage("Collection [1, 2, 3] should contain more than 4 elements")478 }479 }480 "containNoNulls" should {481 "test that a collection contains zero nulls" {482 emptyList<String>() should containNoNulls()483 listOf(1, 2, 3) should containNoNulls()484 listOf(null, null, null) shouldNot containNoNulls()485 listOf(1, null, null) shouldNot containNoNulls()486 emptyList<String>().shouldContainNoNulls()487 listOf(1, 2, 3).shouldContainNoNulls()488 listOf(null, null, null).shouldNotContainNoNulls()489 listOf(1, null, null).shouldNotContainNoNulls()490 shouldThrow<AssertionError> {491 listOf(null, null, null).shouldContainNoNulls()492 }.shouldHaveMessage("Collection should not contain nulls")493 shouldThrow<AssertionError> {494 listOf(1, 2, 3).shouldNotContainNoNulls()495 }.shouldHaveMessage("Collection should have at least one null")496 }497 "support type inference for subtypes of collection" {498 val tests = listOf(499 TestSealed.Test1("test1"),500 TestSealed.Test2(2)501 )502 tests should containNoNulls()503 tests.shouldContainNoNulls()504 }505 }506 "containOnlyNulls" should {507 "test that a collection contains only nulls" {508 emptyList<String>() should containOnlyNulls()509 listOf(null, null, null) should containOnlyNulls()510 listOf(1, null, null) shouldNot containOnlyNulls()511 listOf(1, 2, 3) shouldNot containOnlyNulls()512 listOf(null, 1, 2, 3).shouldNotContainOnlyNulls()513 listOf(1, 2, 3).shouldNotContainOnlyNulls()514 listOf(null, null, null).shouldContainOnlyNulls()515 }516 }...

Full Screen

Full Screen

matchers.kt

Source:matchers.kt Github

copy

Full Screen

...50 )51}52fun <T> Iterable<T>.shouldContainNoNulls() = toList().shouldContainNoNulls()53fun <T> Array<T>.shouldContainNoNulls() = asList().shouldContainNoNulls()54fun <T> Collection<T>.shouldContainNoNulls() = this should containNoNulls()55fun <T> Iterable<T>.shouldNotContainNoNulls() = toList().shouldNotContainNoNulls()56fun <T> Array<T>.shouldNotContainNoNulls() = asList().shouldNotContainNoNulls()57fun <T> Collection<T>.shouldNotContainNoNulls() = this shouldNot containNoNulls()58fun <T> containNoNulls() = object : Matcher<Collection<T>> {59 override fun test(value: Collection<T>) =60 MatcherResult(61 value.all { it != null },62 { "Collection should not contain nulls" },63 { "Collection should have at least one null" }64 )65}66infix fun <T> Array<T>.shouldNotContainExactlyInAnyOrder(expected: Array<T>) =67 asList().shouldNotContainExactlyInAnyOrder(expected.asList())68infix fun <T, C : Collection<T>> C?.shouldNotContainExactlyInAnyOrder(expected: C) =69 this shouldNot containExactlyInAnyOrder(expected)70fun <T, C : Collection<T>> C?.shouldNotContainExactlyInAnyOrder(vararg expected: T) =71 this shouldNot containExactlyInAnyOrder(*expected)72infix fun <T> Array<T>.shouldContainExactlyInAnyOrder(expected: Array<T>) =...

Full Screen

Full Screen

nulls.kt

Source:nulls.kt Github

copy

Full Screen

...75 asList().shouldContainNoNulls()76 return this77}78fun <T> Collection<T>.shouldContainNoNulls(): Collection<T> {79 this should containNoNulls()80 return this81}82fun <T> Iterable<T>.shouldNotContainNoNulls(): Iterable<T> {83 toList().shouldNotContainNoNulls()84 return this85}86fun <T> Array<T>.shouldNotContainNoNulls(): Array<T> {87 asList().shouldNotContainNoNulls()88 return this89}90fun <T> Collection<T>.shouldNotContainNoNulls(): Collection<T> {91 this shouldNot containNoNulls()92 return this93}94fun <T> containNoNulls() = object : Matcher<Collection<T>> {95 override fun test(value: Collection<T>) =96 MatcherResult(97 value.all { it != null },98 { "Collection should not contain nulls" },99 { "Collection should have at least one null" }100 )101}...

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1 io.kotest.matchers.collections.nulls.shouldContainNoNulls()2 io.kotest.matchers.collections.nulls.shouldContainOnlyNulls()3 io.kotest.matchers.collections.nulls.shouldContainNulls()4 io.kotest.matchers.collections.nulls.shouldContainNull()5 io.kotest.matchers.collections.size.shouldHaveSize()6 io.kotest.matchers.collections.size.shouldHaveSizeGreaterThan()7 io.kotest.matchers.collections.size.shouldHaveSizeGreaterThanOrEqual()8 io.kotest.matchers.collections.size.shouldHaveSizeLessThan()9 io.kotest.matchers.collections.size.shouldHaveSizeLessThanOrEqual()10 io.kotest.matchers.collections.size.shouldHaveSizeBetween()11 io.kotest.matchers.collections.size.shouldHaveSizeIn()12 io.kotest.matchers.collections.subset.shouldContainAll()13 io.kotest.matchers.collections.subset.shouldContainAllIn()14 io.kotest.matchers.collections.subset.shouldContainAny()

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf("a", "b", null)2list should containNoNulls()3val list = listOf("a", "b", null)4list should containNulls()5val list = listOf()6list should beEmpty()7val list = listOf()8list should beNotEmpty()9val list = listOf("a", "b", "c")10list should beIn("a", "b", "c")11val list = listOf("a", "b", "c")12list should beNotIn("a", "b", "c")13val list = listOf("a", "b", "c")14list should containAll("a", "b", "c")15val list = listOf("a", "b", "c")16list should containNone("a", "b", "c")17val list = listOf("a", "b", "c")18list should containExactly("a", "b", "c")19val list = listOf("a", "b", "c")20list should containExactlyInAnyOrder("a", "b", "c")21val list = listOf("a", "b", "c")22list should containAtLeast("a", "b", "c")23val list = listOf("a", "b", "c")24list should containAtMost("a", "b", "c")

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf("1", "2", null, "4")2val list = listOf("1", "2", null, "4")3val list = listOf(null, null, null, null)4val list = listOf("1", "2", null, "4")5val list = listOf("1", "2", null, "4")6val list = listOf("1", "2", null, "4")7val list = listOf("1", "2", null, "4")8val list = listOf("1", "2", null, "4")9val list = listOf("1", "2", null, "4")10val list = listOf("1", "2", null, "4")11val list = listOf("1", "2", null, "4")12val list = listOf("1", "2", null, "4")13val list = listOf("1

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, null, 5)2list.shouldContainNoNulls()3val list = listOf(1, 2, 3, 4, 5)4list.shouldContainNoNulls()5val list = listOf(1, 2, 3, null, 5)6list.shouldNotContainNoNulls()7val list = listOf(1, 2, 3, 4, 5)8list.shouldNotContainNoNulls()9val list = listOf(1, 2, 3, null, 5)10list.shouldContainNulls()11val list = listOf(1, 2, 3, 4, 5)12list.shouldNotContainNulls()13val list = listOf(1, 2, 3, null, 5)14list.shouldNotContainNulls()15val list = listOf(1, 2, 3, 4, 5)16list.shouldContainNulls()17val list = listOf(1, 2, 3, 4, 5)18list.shouldNotContainNulls()19val list = listOf(1, 2, 3, null, 5)20list.shouldNotContainNulls()21val list = listOf(1, 2, 3, 4, 5)22list.shouldContainNulls()

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf("1", "2", null, "4")2val list = listOf("1", "2", null, "4")3val list = listOf(null, null, null, null)4val list = listOf("1", "2", null, "4")5val list = listOf("1", "2", null, "4")6val list = listOf("1", "2", null, "4")7val list = listOf("1", "2", null, "4")8val list = listOf("1", "2", null, "4")9val list = listOf("1", "2", null, "4")

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf("a", "b", null, "c")2list should containNoNulls()3val list = listOf("a", "b", "c")4list should haveSize(3)5val list = listOf("a", "b", "c")6list should haveSameSizeAs(listOf(1, 2, 3))7val list = listOf("a", "b", "c")8list should haveSizeGreaterThan(2)9val list = listOf("a", "b", "c")10list should haveSizeGreaterThanOrEqual(3)11val list = listOf("a", "b", "c")12list should haveSizeLessThan(4)13val lisr = list.c("a", "b", "c")14val list = listOf("a", "b", "c")15list should haveSizeInRange(2..4)16list should haveSizeNotInRange(0..n)17val list = listOf("a"s."b", "c")18list should haveSizeBetween(null)19val list = listOf("a", "b", "c")20list should haveSizeNotBetween(0s 1)21val list = listOf("a", "b", "c")22list should haveSizeAtLeast(c)lass23val list = listOf("1", "2", null, "4")24val list = listOf("1", "2", null, "4")25val list = listOf("1", "2", null, "4")26val list = listOf("1

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, null, 5)2list.shouldContainNoNulls()3val list = listOf(1, 2, 3, 4, 5)4list.shouldContainNoNulls()5val list = listOf(1, 2, 3, null, 5)6list.shouldNotContainNoNulls()7val list = listOf(1, 2, 3, 4, 5)8list.shouldNotContainNoNulls()9val list = listOf(1, 2, 3, null, 5)10list.shouldContainNulls()11val list = listOf(1, 2, 3, 4, 5)12list.shouldNotContainNulls()13val list = listOf(1, 2, 3, null, 5)14list.shouldNotContainNulls()15val list = listOf(1, 2, 3, 4, 5)16list.shouldContainNulls()17val list = listOf(1, 2, 3, 4, 5)18list.shouldNotContainNulls()19val list = listOf(1, 2, 3, null, 5)20list.shouldNotContainNulls()21val list = listOf(1, 2, 3, 4, 5)22list.shouldContainNulls()

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3, 4, null)2list shouldNot containNoNulls()3listOf(1, 2, 3, 4) should containNoNulls()4val list = listOf(1, 2, 3, 4, null)5list should containNulls()6listOf(1, 2, 3, 4) shouldNot containNulls()7val list = listOf(1, 2, 3, 3, 4)8list should containDuplicates()9listOf(1, 2, 3, 4) shouldNot containDuplicates()10val list = listOf(1, 2, 3, 3, 4)11list shouldNot containNoDuplicates()

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1@DisplayName("ContainNoNulls method")2class ContainNoNullsTest : DescribeSpec({3 describe("ContainNoNulls method") {4 context("Collection contains nulls") {5 val collection = listOf(1,2,null)6 it("Should fail") {7 collection should containNoNulls()8 }9 }10 context("Collection does not contain nulls") {11 val collection = listOf(1,2,3)12 it("Should pass") {13 collection should containNoNulls()14 }15 }16 }17})18@DisplayName("ContainNoNulls method")19class ContainNoNullsTest : FunSpec({20 test("Collection contains nulls") {21 val collection = listOf(1,2,null)22 collection should containNoNulls()23 }24 test("Collection does not contain nulls") {25 val collection = listOf(1,2,3)26 collection should containNoNulls()27 }28})29@DisplayName("ContainNoNulls method")30class ContainNoNullsTest : StringSpec({31 "Collection contains nulls" {32 val collection = listOf(1,2,null)33 collection should containNoNulls()34 }35 "Collection does not contain nulls" {36 val collection = listOf(1,2,3)37 collection should containNoNulls()38 }39})40@DisplayName("ContainNoNulls method")41class ContainNoNullsTest : FunSpec({42 listener(object : TestListener {43 override suspend fun beforeTest(testCase: TestCase) {44 println("Before test ${testCase.description.testName}")45 }46 override suspend fun afterTest(testCase: TestCase, result: TestResult) {47 println("After test ${testCase.description.testName} with result ${result.status}")48 }49 })50 test("Collection contains nulls") {51 val collection = listOf(1,2,null)52 collection should containNoNulls()53 }54 test("Collection does not contain nulls") {55 val collection = listOf(1,2,3)56 collection should containNoNulls()57 }58})

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1@DisplayName("ContainNoNulls method")2class ContainNoNullsTest : DescribeSpec({3 describe("ContainNoNulls method") {4 context("Collection contains nulls") {5 val collection = listOf(1,2,null)6 it("Should fail") {7 collection should containNoNulls()8 }9 }10 context("Collection does not contain nulls") {11 val collection = listOf(1,2,3)12 it("Should pass") {13 collection should containNoNulls()14 }15 }16 }17})18@DisplayName("ContainNoNulls method")19class ContainNoNullsTest : FunSpec({20 test("Collection contains nulls") {21 val collection = listOf(1,2,null)22 collection should containNoNulls()23 }24 test("Collection does not contain nulls") {25 val collection = listOf(1,2,3)26 collection should containNoNulls()27 }28})29@DisplayName("ContainNoNulls method")30class ContainNoNullsTest : StringSpec({31 "Collection contains nulls" {32 val collection = listOf(1,2,null)33 collection should containNoNulls()34 }35 "Collection does not contain nulls" {36 val collection = listOf(1,2,3)37 collection should containNoNulls()38 }39})40@DisplayName("ContainNoNulls method")41class ContainNoNullsTest : FunSpec({42 listener(object : TestListener {43 override suspend fun beforeTest(testCase: TestCase) {44 println("Before test ${testCase.description.testName}")45 }46 override suspend fun afterTest(testCase: TestCase, result: TestResult) {47 println("After test ${testCase.description.testName} with result ${result.status}")48 }49 })50 test("Collection contains nulls") {51 val collection = listOf(1,2,null)52 collection should containNoNulls()53 }54 test("Collection does not contain nulls") {55 val collection = listOf(1,2,3)56 collection should containNoNulls()57 }58})59listOf(1, 2, 3, 4) should containNoDuplicates()60val list = listOf(1, 2, 3, 4)61list should containInOrder(1, 2, 3, 4)62listOf(1, 2, 3, 4) shouldNot containInOrder(1, 2, 3)63val list = listOf(1, 2, 3, 4)64list should containInOrderOnly(1, 2, 3, 4)65listOf(1, 2, 3, 4) shouldNot containInOrderOnly(1, 2, 4, 3)66val list = listOf(1, 2, 3, 4)67list should containInOrderOnlyElementsOf(listOf(1, 2, 3, 4))68listOf(1, 2, 3, 4) shouldNot containInOrderOnlyElementsOf(listOf(1, 2, 4, 3

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1assertThat(listOf(1, 2, 3, 4)).containNoNulls()2assertThat(listOf(1, 2, 3, null)).containNoNulls()3assertThat(listOf(1, 2, 3, 4)).containNoNulls()4assertThat(listOf(1, 2, 3, null)).containNoNulls()5assertThat(listOf(1, 2, 3, 4)).containNoNulls()6assertThat(listOf(1, 2, 3, null)).containNoNulls()7assertThat(listOf(1, 2, 3, 4)).containNoNulls()8assertThat(listOf(1, 2, 3, null)).containNoNulls()9assertThat(listOf(1, 2, 3, 4)).containNoNulls()10assertThat(listOf(1, 2, 3, null)).containNoNulls()11assertThat(listOf(1, 2, 3, 4)).containNoNulls()

Full Screen

Full Screen

containNoNulls

Using AI Code Generation

copy

Full Screen

1@DisplayName("Test for containNoNulls method of io.kotest.matchers.collections.nulls class")2class ContainNoNullsTest {3 fun `should pass when all elements are not null`() {4 listOf(1, 2, 3).should(containNoNulls())5 }6 fun `should pass when all elements are not null and list is empty`() {7 listOf<Int>().should(containNoNulls())8 }9 fun `should fail when list contains null`() {10 shouldThrow<AssertionError> {11 listOf(1, null, 3).should(containNoNulls())12 }13 }14}15@DisplayName("Test for containNulls method of io.kotest.matchers.collections.nulls class")16class ContainNullsTest {17 fun `should pass when list contains null`() {18 listOf(1, null, 3).should(containNulls())19 }20 fun `should fail when all elements are not null`() {21 shouldThrow<AssertionError> {22 listOf(1, 2, 3).should(containNulls())23 }24 }25 fun `should fail when all elements are not null and list is empty`() {26 shouldThrow<AssertionError> {27 listOf<Int>().should(containNulls())28 }29 }30}31@DisplayName("Test for containNullAt method of io.k

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful