Best Kotest code snippet using io.kotest.inspectors.Inspectors.CharSequence.forAll
JavaClassUtilsTests.kt
Source:JavaClassUtilsTests.kt
1/*2 * Copyright (c) 2022. The Meowool Organization Open Source Project3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 *16 * In addition, if you modified the project, you must include the Meowool17 * organization URL in your code file: https://github.com/meowool18 *19 * å¦ææ¨ä¿®æ¹äºæ¤é¡¹ç®ï¼åå¿
须确ä¿æºæ件ä¸å
å« Meowool ç»ç» URL: https://github.com/meowool20 */21package com.meowool.cloak22import io.kotest.assertions.withClue23import io.kotest.inspectors.forAll24import io.kotest.matchers.booleans.shouldBeFalse25import io.kotest.matchers.booleans.shouldBeTrue26import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder27import org.junit.jupiter.api.Test28import java.util.AbstractList29import java.util.AbstractMap30/**31 * Test for 'com/meowool/cloak/JavaClassUtilsTests.kt'.32 *33 * @author å (RinOrz)34 */35class JavaClassUtilsTests {36 private val primitiveTypes = arrayOfPrimitives()37 @Test fun `class is object`() {38 fun Class<*>.shouldBeObject() = withClue("Expected ${this.name} is an object class") {39 this.isObject.shouldBeTrue()40 }41 fun Class<*>.shouldNotBeObject() = withClue("Expected ${this.name} is not an object class") {42 this.isObject.shouldBeFalse()43 }44 Int::class.javaObjectType.shouldBeObject()45 Int::class.javaPrimitiveType!!.shouldNotBeObject()46 Integer::class.java.shouldBeObject()47 Integer.TYPE.shouldNotBeObject()48 Array<Int>::class.java.shouldBeObject()49 IntArray::class.java.shouldNotBeObject()50 Byte::class.javaObjectType.shouldBeObject()51 Byte::class.javaPrimitiveType!!.shouldNotBeObject()52 java.lang.Byte::class.java.shouldBeObject()53 java.lang.Byte.TYPE.shouldNotBeObject()54 Array<Byte>::class.java.shouldBeObject()55 ByteArray::class.java.shouldNotBeObject()56 Short::class.javaObjectType.shouldBeObject()57 Short::class.javaPrimitiveType!!.shouldNotBeObject()58 java.lang.Short::class.java.shouldBeObject()59 java.lang.Short.TYPE.shouldNotBeObject()60 Array<Short>::class.java.shouldBeObject()61 ShortArray::class.java.shouldNotBeObject()62 Long::class.javaObjectType.shouldBeObject()63 Long::class.javaPrimitiveType!!.shouldNotBeObject()64 java.lang.Long::class.java.shouldBeObject()65 java.lang.Long.TYPE.shouldNotBeObject()66 Array<Long>::class.java.shouldBeObject()67 LongArray::class.java.shouldNotBeObject()68 Float::class.javaObjectType.shouldBeObject()69 Float::class.javaPrimitiveType!!.shouldNotBeObject()70 java.lang.Float::class.java.shouldBeObject()71 java.lang.Float.TYPE.shouldNotBeObject()72 Array<Float>::class.java.shouldBeObject()73 FloatArray::class.java.shouldNotBeObject()74 Double::class.javaObjectType.shouldBeObject()75 Double::class.javaPrimitiveType!!.shouldNotBeObject()76 java.lang.Double::class.java.shouldBeObject()77 java.lang.Double.TYPE.shouldNotBeObject()78 Array<Double>::class.java.shouldBeObject()79 DoubleArray::class.java.shouldNotBeObject()80 Boolean::class.javaObjectType.shouldBeObject()81 Boolean::class.javaPrimitiveType!!.shouldNotBeObject()82 java.lang.Boolean::class.java.shouldBeObject()83 java.lang.Boolean.TYPE.shouldNotBeObject()84 Array<Boolean>::class.java.shouldBeObject()85 BooleanArray::class.java.shouldNotBeObject()86 Char::class.javaObjectType.shouldBeObject()87 Char::class.javaPrimitiveType!!.shouldNotBeObject()88 Character::class.java.shouldBeObject()89 Character.TYPE.shouldNotBeObject()90 Array<Char>::class.java.shouldBeObject()91 CharArray::class.java.shouldNotBeObject()92 Void::class.javaObjectType.shouldBeObject()93 Void.TYPE.shouldNotBeObject()94 Array<Void>::class.java.shouldBeObject()95 }96 @Test fun `class is primitive wrapper`() {97 fun Class<*>.shouldBePrimitiveWrapper() = withClue("Expected ${this.name} is a primitive wrapper class") {98 this.isPrimitiveWrapper.shouldBeTrue()99 }100 fun Class<*>.shouldNotBePrimitiveWrapper() = withClue("Expected ${this.name} is not a primitive wrapper class") {101 this.isPrimitiveWrapper.shouldBeFalse()102 }103 Int::class.javaObjectType.shouldBePrimitiveWrapper()104 Int::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()105 Integer::class.java.shouldBePrimitiveWrapper()106 Integer.TYPE.shouldNotBePrimitiveWrapper()107 Array<Int>::class.java.shouldBePrimitiveWrapper()108 IntArray::class.java.shouldNotBePrimitiveWrapper()109 Byte::class.javaObjectType.shouldBePrimitiveWrapper()110 Byte::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()111 java.lang.Byte::class.java.shouldBePrimitiveWrapper()112 java.lang.Byte.TYPE.shouldNotBePrimitiveWrapper()113 Array<Byte>::class.java.shouldBePrimitiveWrapper()114 ByteArray::class.java.shouldNotBePrimitiveWrapper()115 Short::class.javaObjectType.shouldBePrimitiveWrapper()116 Short::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()117 java.lang.Short::class.java.shouldBePrimitiveWrapper()118 java.lang.Short.TYPE.shouldNotBePrimitiveWrapper()119 Array<Short>::class.java.shouldBePrimitiveWrapper()120 ShortArray::class.java.shouldNotBePrimitiveWrapper()121 Long::class.javaObjectType.shouldBePrimitiveWrapper()122 Long::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()123 java.lang.Long::class.java.shouldBePrimitiveWrapper()124 java.lang.Long.TYPE.shouldNotBePrimitiveWrapper()125 Array<Long>::class.java.shouldBePrimitiveWrapper()126 LongArray::class.java.shouldNotBePrimitiveWrapper()127 Float::class.javaObjectType.shouldBePrimitiveWrapper()128 Float::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()129 java.lang.Float::class.java.shouldBePrimitiveWrapper()130 java.lang.Float.TYPE.shouldNotBePrimitiveWrapper()131 Array<Float>::class.java.shouldBePrimitiveWrapper()132 FloatArray::class.java.shouldNotBePrimitiveWrapper()133 Double::class.javaObjectType.shouldBePrimitiveWrapper()134 Double::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()135 java.lang.Double::class.java.shouldBePrimitiveWrapper()136 java.lang.Double.TYPE.shouldNotBePrimitiveWrapper()137 Array<Double>::class.java.shouldBePrimitiveWrapper()138 DoubleArray::class.java.shouldNotBePrimitiveWrapper()139 Boolean::class.javaObjectType.shouldBePrimitiveWrapper()140 Boolean::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()141 java.lang.Boolean::class.java.shouldBePrimitiveWrapper()142 java.lang.Boolean.TYPE.shouldNotBePrimitiveWrapper()143 Array<Boolean>::class.java.shouldBePrimitiveWrapper()144 BooleanArray::class.java.shouldNotBePrimitiveWrapper()145 Char::class.javaObjectType.shouldBePrimitiveWrapper()146 Char::class.javaPrimitiveType!!.shouldNotBePrimitiveWrapper()147 Character::class.java.shouldBePrimitiveWrapper()148 Character.TYPE.shouldNotBePrimitiveWrapper()149 Array<Char>::class.java.shouldBePrimitiveWrapper()150 CharArray::class.java.shouldNotBePrimitiveWrapper()151 Void::class.javaObjectType.shouldBePrimitiveWrapper()152 Void.TYPE.shouldNotBePrimitiveWrapper()153 Array<Void>::class.java.shouldBePrimitiveWrapper()154 Any::class.java.shouldNotBePrimitiveWrapper()155 List::class.java.shouldNotBePrimitiveWrapper()156 String::class.java.shouldNotBePrimitiveWrapper()157 }158 @Test fun `class is primitive or primitive wrapper`() {159 fun Class<*>.shouldBePrimitiveOrWrapper() =160 withClue("Expected ${this.name} is a primitive or primitive wrapper class") {161 this.isPrimitiveOrWrapper.shouldBeTrue()162 }163 fun Class<*>.shouldNotBePrimitiveOrWrapper() =164 withClue("Expected ${this.name} is not a primitive or primitive wrapper class") {165 this.isPrimitiveOrWrapper.shouldBeFalse()166 }167 Int::class.javaObjectType.shouldBePrimitiveOrWrapper()168 Int::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()169 Integer::class.java.shouldBePrimitiveOrWrapper()170 Integer.TYPE.shouldBePrimitiveOrWrapper()171 Array<Int>::class.java.shouldBePrimitiveOrWrapper()172 IntArray::class.java.shouldBePrimitiveOrWrapper()173 Byte::class.javaObjectType.shouldBePrimitiveOrWrapper()174 Byte::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()175 java.lang.Byte::class.java.shouldBePrimitiveOrWrapper()176 java.lang.Byte.TYPE.shouldBePrimitiveOrWrapper()177 Array<Byte>::class.java.shouldBePrimitiveOrWrapper()178 ByteArray::class.java.shouldBePrimitiveOrWrapper()179 Short::class.javaObjectType.shouldBePrimitiveOrWrapper()180 Short::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()181 java.lang.Short::class.java.shouldBePrimitiveOrWrapper()182 java.lang.Short.TYPE.shouldBePrimitiveOrWrapper()183 Array<Short>::class.java.shouldBePrimitiveOrWrapper()184 ShortArray::class.java.shouldBePrimitiveOrWrapper()185 Long::class.javaObjectType.shouldBePrimitiveOrWrapper()186 Long::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()187 java.lang.Long::class.java.shouldBePrimitiveOrWrapper()188 java.lang.Long.TYPE.shouldBePrimitiveOrWrapper()189 Array<Long>::class.java.shouldBePrimitiveOrWrapper()190 LongArray::class.java.shouldBePrimitiveOrWrapper()191 Float::class.javaObjectType.shouldBePrimitiveOrWrapper()192 Float::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()193 java.lang.Float::class.java.shouldBePrimitiveOrWrapper()194 java.lang.Float.TYPE.shouldBePrimitiveOrWrapper()195 Array<Float>::class.java.shouldBePrimitiveOrWrapper()196 FloatArray::class.java.shouldBePrimitiveOrWrapper()197 Double::class.javaObjectType.shouldBePrimitiveOrWrapper()198 Double::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()199 java.lang.Double::class.java.shouldBePrimitiveOrWrapper()200 java.lang.Double.TYPE.shouldBePrimitiveOrWrapper()201 Array<Double>::class.java.shouldBePrimitiveOrWrapper()202 DoubleArray::class.java.shouldBePrimitiveOrWrapper()203 Boolean::class.javaObjectType.shouldBePrimitiveOrWrapper()204 Boolean::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()205 java.lang.Boolean::class.java.shouldBePrimitiveOrWrapper()206 java.lang.Boolean.TYPE.shouldBePrimitiveOrWrapper()207 Array<Boolean>::class.java.shouldBePrimitiveOrWrapper()208 BooleanArray::class.java.shouldBePrimitiveOrWrapper()209 Char::class.javaObjectType.shouldBePrimitiveOrWrapper()210 Char::class.javaPrimitiveType!!.shouldBePrimitiveOrWrapper()211 Character::class.java.shouldBePrimitiveOrWrapper()212 Character.TYPE.shouldBePrimitiveOrWrapper()213 Array<Char>::class.java.shouldBePrimitiveOrWrapper()214 CharArray::class.java.shouldBePrimitiveOrWrapper()215 Void::class.javaObjectType.shouldBePrimitiveOrWrapper()216 Void.TYPE.shouldBePrimitiveOrWrapper()217 Array<Void>::class.java.shouldBePrimitiveOrWrapper()218 Any::class.java.shouldNotBePrimitiveOrWrapper()219 List::class.java.shouldNotBePrimitiveOrWrapper()220 String::class.java.shouldNotBePrimitiveOrWrapper()221 }222 @Test fun `class is primitive number`() {223 fun Class<*>.shouldBePrimitiveNumber() = withClue("Expected ${this.name} is a primitive number class") {224 this.isPrimitiveNumber.shouldBeTrue()225 this.isNumber.shouldBeTrue()226 }227 fun Class<*>.shouldNotBePrimitiveNumber() = withClue("Expected ${this.name} is not a primitive number class") {228 this.isPrimitiveNumber.shouldBeFalse()229 }230 Int::class.java.shouldBePrimitiveNumber()231 Int::class.javaPrimitiveType!!.shouldBePrimitiveNumber()232 Int::class.javaObjectType.shouldNotBePrimitiveNumber()233 Integer::class.java.shouldNotBePrimitiveNumber()234 Integer.TYPE.shouldBePrimitiveNumber()235 Array<Int>::class.java.shouldNotBePrimitiveNumber()236 IntArray::class.java.shouldNotBePrimitiveNumber()237 Byte::class.java.shouldBePrimitiveNumber()238 Byte::class.javaPrimitiveType!!.shouldBePrimitiveNumber()239 Byte::class.javaObjectType.shouldNotBePrimitiveNumber()240 java.lang.Byte::class.java.shouldNotBePrimitiveNumber()241 java.lang.Byte.TYPE.shouldBePrimitiveNumber()242 Array<Byte>::class.java.shouldNotBePrimitiveNumber()243 ByteArray::class.java.shouldNotBePrimitiveNumber()244 Short::class.java.shouldBePrimitiveNumber()245 Short::class.javaPrimitiveType!!.shouldBePrimitiveNumber()246 Short::class.javaObjectType.shouldNotBePrimitiveNumber()247 java.lang.Short::class.java.shouldNotBePrimitiveNumber()248 java.lang.Short.TYPE.shouldBePrimitiveNumber()249 Array<Short>::class.java.shouldNotBePrimitiveNumber()250 ShortArray::class.java.shouldNotBePrimitiveNumber()251 Long::class.java.shouldBePrimitiveNumber()252 Long::class.javaPrimitiveType!!.shouldBePrimitiveNumber()253 Long::class.javaObjectType.shouldNotBePrimitiveNumber()254 java.lang.Long::class.java.shouldNotBePrimitiveNumber()255 java.lang.Long.TYPE.shouldBePrimitiveNumber()256 Array<Long>::class.java.shouldNotBePrimitiveNumber()257 LongArray::class.java.shouldNotBePrimitiveNumber()258 Float::class.java.shouldBePrimitiveNumber()259 Float::class.javaPrimitiveType!!.shouldBePrimitiveNumber()260 Float::class.javaObjectType.shouldNotBePrimitiveNumber()261 java.lang.Float::class.java.shouldNotBePrimitiveNumber()262 java.lang.Float.TYPE.shouldBePrimitiveNumber()263 Array<Float>::class.java.shouldNotBePrimitiveNumber()264 FloatArray::class.java.shouldNotBePrimitiveNumber()265 Double::class.java.shouldBePrimitiveNumber()266 Double::class.javaPrimitiveType!!.shouldBePrimitiveNumber()267 Double::class.javaObjectType.shouldNotBePrimitiveNumber()268 java.lang.Double::class.java.shouldNotBePrimitiveNumber()269 java.lang.Double.TYPE.shouldBePrimitiveNumber()270 Array<Double>::class.java.shouldNotBePrimitiveNumber()271 DoubleArray::class.java.shouldNotBePrimitiveNumber()272 Boolean::class.java.shouldNotBePrimitiveNumber()273 Boolean::class.javaPrimitiveType!!.shouldNotBePrimitiveNumber()274 Boolean::class.javaObjectType.shouldNotBePrimitiveNumber()275 java.lang.Boolean::class.java.shouldNotBePrimitiveNumber()276 java.lang.Boolean.TYPE.shouldNotBePrimitiveNumber()277 Array<Boolean>::class.java.shouldNotBePrimitiveNumber()278 BooleanArray::class.java.shouldNotBePrimitiveNumber()279 Char::class.java.shouldNotBePrimitiveNumber()280 Char::class.javaPrimitiveType!!.shouldNotBePrimitiveNumber()281 Char::class.javaObjectType.shouldNotBePrimitiveNumber()282 Character::class.java.shouldNotBePrimitiveNumber()283 Character.TYPE.shouldNotBePrimitiveNumber()284 Array<Char>::class.java.shouldNotBePrimitiveNumber()285 CharArray::class.java.shouldNotBePrimitiveNumber()286 Void::class.javaObjectType.shouldNotBePrimitiveNumber()287 Void.TYPE.shouldNotBePrimitiveNumber()288 Array<Void>::class.java.shouldNotBePrimitiveNumber()289 Any::class.java.shouldNotBePrimitiveNumber()290 List::class.java.shouldNotBePrimitiveNumber()291 String::class.java.shouldNotBePrimitiveNumber()292 }293 @Test fun `class is boxed number`() {294 fun Class<*>.shouldBeBoxedNumber() = withClue("Expected ${this.name} is a boxed number class") {295 this.isBoxedNumber.shouldBeTrue()296 this.isNumber.shouldBeTrue()297 }298 fun Class<*>.shouldNotBeBoxedNumber() = withClue("Expected ${this.name} is not a boxed number class") {299 this.isBoxedNumber.shouldBeFalse()300 }301 Int::class.java.shouldNotBeBoxedNumber()302 Int::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()303 Int::class.javaObjectType.shouldBeBoxedNumber()304 Integer::class.java.shouldBeBoxedNumber()305 Integer.TYPE.shouldNotBeBoxedNumber()306 Array<Int>::class.java.shouldNotBeBoxedNumber()307 IntArray::class.java.shouldNotBeBoxedNumber()308 Byte::class.java.shouldNotBeBoxedNumber()309 Byte::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()310 Byte::class.javaObjectType.shouldBeBoxedNumber()311 java.lang.Byte::class.java.shouldBeBoxedNumber()312 java.lang.Byte.TYPE.shouldNotBeBoxedNumber()313 Array<Byte>::class.java.shouldNotBeBoxedNumber()314 ByteArray::class.java.shouldNotBeBoxedNumber()315 Short::class.java.shouldNotBeBoxedNumber()316 Short::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()317 Short::class.javaObjectType.shouldBeBoxedNumber()318 java.lang.Short::class.java.shouldBeBoxedNumber()319 java.lang.Short.TYPE.shouldNotBeBoxedNumber()320 Array<Short>::class.java.shouldNotBeBoxedNumber()321 ShortArray::class.java.shouldNotBeBoxedNumber()322 Long::class.java.shouldNotBeBoxedNumber()323 Long::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()324 Long::class.javaObjectType.shouldBeBoxedNumber()325 java.lang.Long::class.java.shouldBeBoxedNumber()326 java.lang.Long.TYPE.shouldNotBeBoxedNumber()327 Array<Long>::class.java.shouldNotBeBoxedNumber()328 LongArray::class.java.shouldNotBeBoxedNumber()329 Float::class.java.shouldNotBeBoxedNumber()330 Float::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()331 Float::class.javaObjectType.shouldBeBoxedNumber()332 java.lang.Float::class.java.shouldBeBoxedNumber()333 java.lang.Float.TYPE.shouldNotBeBoxedNumber()334 Array<Float>::class.java.shouldNotBeBoxedNumber()335 FloatArray::class.java.shouldNotBeBoxedNumber()336 Double::class.java.shouldNotBeBoxedNumber()337 Double::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()338 Double::class.javaObjectType.shouldBeBoxedNumber()339 java.lang.Double::class.java.shouldBeBoxedNumber()340 java.lang.Double.TYPE.shouldNotBeBoxedNumber()341 Array<Double>::class.java.shouldNotBeBoxedNumber()342 DoubleArray::class.java.shouldNotBeBoxedNumber()343 Boolean::class.java.shouldNotBeBoxedNumber()344 Boolean::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()345 Boolean::class.javaObjectType.shouldNotBeBoxedNumber()346 java.lang.Boolean::class.java.shouldNotBeBoxedNumber()347 java.lang.Boolean.TYPE.shouldNotBeBoxedNumber()348 Array<Boolean>::class.java.shouldNotBeBoxedNumber()349 BooleanArray::class.java.shouldNotBeBoxedNumber()350 Char::class.java.shouldNotBeBoxedNumber()351 Char::class.javaPrimitiveType!!.shouldNotBeBoxedNumber()352 Char::class.javaObjectType.shouldNotBeBoxedNumber()353 Character::class.java.shouldNotBeBoxedNumber()354 Character.TYPE.shouldNotBeBoxedNumber()355 Array<Char>::class.java.shouldNotBeBoxedNumber()356 CharArray::class.java.shouldNotBeBoxedNumber()357 Void::class.javaObjectType.shouldNotBeBoxedNumber()358 Void.TYPE.shouldNotBeBoxedNumber()359 Array<Void>::class.java.shouldNotBeBoxedNumber()360 Any::class.java.shouldNotBeBoxedNumber()361 List::class.java.shouldNotBeBoxedNumber()362 String::class.java.shouldNotBeBoxedNumber()363 }364 @Test fun `whether instance can cast to specified class`() {365 infix fun Any?.shouldCanCastTo(base: Class<*>) = withClue("Expected `$this` can cast to ${base.name} class.") {366 (this canCastTo base).shouldBeTrue()367 }368 infix fun Any?.shouldCannotCastTo(base: Class<*>) =369 withClue("Expected `$this` can not cast to ${base.name} class.") {370 (this canCastTo base).shouldBeFalse()371 }372 fun Number.test() {373 shouldCanCastTo(javaClass)374 shouldCanCastTo(javaClass.boxing())375 shouldCanCastTo(javaClass.unboxing())376 shouldCannotCastTo(Void.TYPE)377 shouldCannotCastTo(Void::class.java)378 if (javaClass.isPrimitive) primitiveTypes.forAll {379 if (it != javaClass) {380 shouldCanCastTo(it.unboxing())381 shouldCannotCastTo(it.boxing())382 }383 }384 }385 10.toByte().test()386 10.toShort().test()387 10.test()388 10L.test()389 10F.test()390 10.0.test()391 primitiveTypes.forAll {392 // `null` value can be any object393 null.shouldCanCastTo(it.boxing())394 // but `null` value never be primitive type395 null.shouldCannotCastTo(it.unboxing())396 }397 arrayListOf(1, 2, 3).apply {398 shouldCanCastTo(ArrayList::class.java)399 shouldCanCastTo(AbstractList::class.java)400 shouldCanCastTo(List::class.java)401 shouldCanCastTo(Any::class.java)402 }403 hashMapOf("a" to 1, "b" to 2).apply {404 shouldCanCastTo(AbstractMap::class.java)405 shouldCanCastTo(Map::class.java)406 shouldCanCastTo(Any::class.java)407 }408 StringBuilder::class.java.shouldCanCastTo(CharSequence::class.java)409 CharSequence::class.java.shouldCannotCastTo(StringBuilder::class.java)410 Appendable::class.java.shouldCanCastTo(Any::class.java)411 Any::class.java.shouldCannotCastTo(Appendable::class.java)412 Any::class.java.shouldCanCastTo(Any::class.java)413 Array<Int>::class.java.shouldCanCastTo(IntArray::class.java)414 FloatArray::class.java.shouldCanCastTo(Array<Float>::class.java)415 }416 @Test fun `class boxing and unboxing`() {417 arrayOfPrimitiveWrappers(true).map { it.boxing() } shouldContainExactlyInAnyOrder arrayOfPrimitiveWrappers(true).toList()418 arrayOfPrimitiveWrappers(true).map { it.unboxing() } shouldContainExactlyInAnyOrder arrayOfPrimitives(true).toList()419 arrayOfPrimitives(true).map { it.boxing() } shouldContainExactlyInAnyOrder arrayOfPrimitiveWrappers(true).toList()420 arrayOfPrimitives(true).map { it.unboxing() } shouldContainExactlyInAnyOrder arrayOfPrimitives(true).toList()421 }422}...
Inspectors.kt
Source:Inspectors.kt
1package io.kotest.inspectors2import io.kotest.assertions.failure3inline fun <K, V, C : Map<K, V>> C.forAllValues(fn: (V) -> Unit): C = apply { values.forAll(fn) }4inline fun <K, V, C : Map<K, V>> C.forAllKeys(fn: (K) -> Unit): C = apply { keys.forAll(fn) }5inline fun <K, V, C : Map<K, V>> C.forAll(fn: (Map.Entry<K, V>) -> Unit): C = apply {6 val results = runTests(this, fn)7 val passed = results.filterIsInstance<ElementPass<Map.Entry<K, V>>>()8 if (passed.size < this.size) {9 val msg = "${passed.size} elements passed but expected ${this.size}"10 buildAssertionError(msg, results)11 }12}13inline fun CharSequence.forAll(fn: (Char) -> Unit): CharSequence = apply { toList().forAll(fn) }14inline fun <T> Sequence<T>.forAll(fn: (T) -> Unit): Sequence<T> = apply { toList().forAll(fn) }15inline fun <T> Array<T>.forAll(fn: (T) -> Unit): Array<T> = apply { asList().forAll(fn) }16inline fun <T, C : Collection<T>> C.forAll(fn: (T) -> Unit): C = apply {17 val results = runTests(this, fn)18 val passed = results.filterIsInstance<ElementPass<T>>()19 if (passed.size < this.size) {20 val msg = "${passed.size} elements passed but expected ${this.size}"21 buildAssertionError(msg, results)22 }23}24inline fun <K, V, C : Map<K, V>> C.forOneValue(fn: (V) -> Unit): C = apply { values.forExactly(1, fn) }25inline fun <K, V, C : Map<K, V>> C.forOneKey(fn: (K) -> Unit): C = apply { keys.forExactly(1, fn) }26inline fun <K, V, C : Map<K, V>> C.forOne(fn: (Map.Entry<K, V>) -> Unit): C = apply { forExactly(1, fn) }27inline fun CharSequence.forOne(fn: (Char) -> Unit): CharSequence = apply { toList().forOne(fn) }28inline fun <T> Sequence<T>.forOne(fn: (T) -> Unit): Sequence<T> = apply { toList().forOne(fn) }29inline fun <T> Array<T>.forOne(fn: (T) -> Unit): Array<T> = apply { asList().forOne(fn) }30inline fun <T, C : Collection<T>> C.forOne(fn: (T) -> Unit): C = forExactly(1, fn)31inline fun <K, V, C : Map<K, V>> C.forValuesExactly(k: Int, fn: (V) -> Unit): C = apply { values.forExactly(k, fn) }32inline fun <K, V, C : Map<K, V>> C.forKeysExactly(k: Int, fn: (K) -> Unit): C = apply { keys.forExactly(k, fn) }33inline fun <K, V, C : Map<K, V>> C.forExactly(k: Int, fn: (Map.Entry<K, V>) -> Unit): C = apply {34 val results = runTests(this, fn)35 val passed = results.filterIsInstance<ElementPass<Map.Entry<K, V>>>()36 if (passed.size != k) {37 val msg = "${passed.size} elements passed but expected $k"38 buildAssertionError(msg, results)39 }40}41inline fun CharSequence.forExactly(k: Int, fn: (Char) -> Unit): CharSequence = apply { toList().forExactly(k, fn) }42inline fun <T> Sequence<T>.forExactly(k: Int, fn: (T) -> Unit): Sequence<T> = apply { toList().forExactly(k, fn) }43inline fun <T> Array<T>.forExactly(k: Int, fn: (T) -> Unit): Array<T> = apply { toList().forExactly(k, fn) }44inline fun <T, C : Collection<T>> C.forExactly(k: Int, fn: (T) -> Unit): C = apply {45 val results = runTests(this, fn)46 val passed = results.filterIsInstance<ElementPass<T>>()47 if (passed.size != k) {48 val msg = "${passed.size} elements passed but expected $k"49 buildAssertionError(msg, results)50 }51}52inline fun <K, V, C : Map<K, V>> C.forSomeValues(fn: (V) -> Unit): C = apply { values.forSome(fn) }53inline fun <K, V, C : Map<K, V>> C.forSomeKeys(fn: (K) -> Unit): C = apply { keys.forSome(fn) }54inline fun <K, V, C : Map<K, V>> C.forSome(fn: (Map.Entry<K, V>) -> Unit): C = apply {55 val results = runTests(this, fn)56 val passed = results.filterIsInstance<ElementPass<Map.Entry<K, V>>>()57 if (passed.isEmpty()) {58 buildAssertionError("No elements passed but expected at least one", results)59 } else if (passed.size == size) {60 buildAssertionError("All elements passed but expected < $size", results)61 }62}63inline fun CharSequence.forSome(fn: (Char) -> Unit): CharSequence = apply { toList().forSome(fn) }64inline fun <T> Sequence<T>.forSome(fn: (T) -> Unit): Sequence<T> = apply { toList().forSome(fn) }65inline fun <T> Array<T>.forSome(fn: (T) -> Unit): Array<T> = apply { toList().forSome(fn) }66inline fun <T, C : Collection<T>> C.forSome(fn: (T) -> Unit): C = apply {67 val results = runTests(this, fn)68 val passed = results.filterIsInstance<ElementPass<T>>()69 if (passed.isEmpty()) {70 buildAssertionError("No elements passed but expected at least one", results)71 } else if (passed.size == size) {72 buildAssertionError("All elements passed but expected < $size", results)73 }74}75inline fun <K, V, C : Map<K, V>> C.forAnyValue(fn: (V) -> Unit): C = apply { values.forAny(fn) }76inline fun <K, V, C : Map<K, V>> C.forAnyKey(fn: (K) -> Unit): C = apply { keys.forAny(fn) }77inline fun <K, V, C : Map<K, V>> C.forAny(fn: (Map.Entry<K, V>) -> Unit): C = apply { forAtLeastOne(fn) }78inline fun <T> Sequence<T>.forAny(fn: (T) -> Unit): Sequence<T> = apply { toList().forAny(fn) }79inline fun CharSequence.forAny(fn: (Char) -> Unit): CharSequence = apply { toList().forAny(fn) }80inline fun <T> Array<T>.forAny(fn: (T) -> Unit): Array<T> = apply { toList().forAny(fn) }81inline fun <T, C : Collection<T>> C.forAny(fn: (T) -> Unit): C = apply { forAtLeastOne(fn) }82inline fun <K, V, C : Map<K, V>> C.forAtLeastOneValue(fn: (V) -> Unit): C = apply { values.forAtLeastOne(fn) }83inline fun <K, V, C : Map<K, V>> C.forAtLeastOneKey(fn: (K) -> Unit): C = apply { keys.forAtLeastOne(fn) }84inline fun <K, V, C : Map<K, V>> C.forAtLeastOne(fn: (Map.Entry<K, V>) -> Unit): C = apply { forAtLeast(1, fn) }85inline fun CharSequence.forAtLeastOne(fn: (Char) -> Unit): CharSequence = apply { toList().forAtLeast(1, fn) }86inline fun <T> Sequence<T>.forAtLeastOne(fn: (T) -> Unit): Sequence<T> = apply { toList().forAtLeastOne(fn) }87inline fun <T> Array<T>.forAtLeastOne(fn: (T) -> Unit): Array<T> = apply { toList().forAtLeastOne(fn) }88inline fun <T, C : Collection<T>> C.forAtLeastOne(f: (T) -> Unit) = forAtLeast(1, f)89inline fun <K, V, C : Map<K, V>> C.forValuesAtLeast(k: Int, fn: (V) -> Unit): C = apply { values.forAtLeast(k, fn) }90inline fun <K, V, C : Map<K, V>> C.forKeysAtLeast(k: Int, fn: (K) -> Unit): C = apply { keys.forAtLeast(k, fn) }91inline fun <K, V, C : Map<K, V>> C.forAtLeast(k: Int, fn: (Map.Entry<K, V>) -> Unit): C = apply {92 val results = runTests(this, fn)93 val passed = results.filterIsInstance<ElementPass<Map.Entry<K, V>>>()94 if (passed.size < k) {95 val msg = "${passed.size} elements passed but expected at least $k"96 buildAssertionError(msg, results)97 }98}99inline fun CharSequence.forAtLeast(k: Int, fn: (Char) -> Unit): CharSequence = apply { toList().forAtLeast(k, fn) }100inline fun <T> Sequence<T>.forAtLeast(k: Int, fn: (T) -> Unit): Sequence<T> = apply { toList().forAtLeast(k, fn) }101inline fun <T> Array<T>.forAtLeast(k: Int, fn: (T) -> Unit): Array<T> = apply { toList().forAtLeast(k, fn) }102inline fun <T, C : Collection<T>> C.forAtLeast(k: Int, fn: (T) -> Unit): C = apply {103 val results = runTests(this, fn)104 val passed = results.filterIsInstance<ElementPass<T>>()105 if (passed.size < k) {106 val msg = "${passed.size} elements passed but expected at least $k"107 buildAssertionError(msg, results)108 }109}110inline fun <K, V, C : Map<K, V>> C.forAtMostOneValue(fn: (V) -> Unit): C = apply { values.forAtMostOne(fn) }111inline fun <K, V, C : Map<K, V>> C.forAtMostOneKey(fn: (K) -> Unit): C = apply { keys.forAtMostOne(fn) }112inline fun <K, V, C : Map<K, V>> C.forAtMostOne(fn: (Map.Entry<K, V>) -> Unit): C = apply { forAtMost(1, fn) }113inline fun CharSequence.forAtMostOne(fn: (Char) -> Unit): CharSequence = apply { toList().forAtMost(1, fn) }114inline fun <T> Sequence<T>.forAtMostOne(fn: (T) -> Unit): Sequence<T> = apply { toList().forAtMostOne(fn) }115inline fun <T> Array<T>.forAtMostOne(fn: (T) -> Unit): Array<T> = apply { toList().forAtMostOne(fn) }116inline fun <T, C : Collection<T>> C.forAtMostOne(fn: (T) -> Unit) = forAtMost(1, fn)117inline fun <K, V, C : Map<K, V>> C.forValuesAtMost(k: Int, fn: (V) -> Unit): C = apply { values.forAtMost(k, fn) }118inline fun <K, V, C : Map<K, V>> C.forKeysAtMost(k: Int, fn: (K) -> Unit): C = apply { keys.forAtMost(k, fn) }119inline fun <K, V, C : Map<K, V>> C.forAtMost(k: Int, fn: (Map.Entry<K, V>) -> Unit): C = apply {120 val results = runTests(this, fn)121 val passed = results.filterIsInstance<ElementPass<Map.Entry<K, V>>>()122 if (passed.size > k) {123 val msg = "${passed.size} elements passed but expected at most $k"124 buildAssertionError(msg, results)125 }126}127inline fun CharSequence.forAtMost(k: Int, fn: (Char) -> Unit): CharSequence = apply { toList().forAtMost(k, fn) }128inline fun <T> Sequence<T>.forAtMost(k: Int, fn: (T) -> Unit): Sequence<T> = apply { toList().forAtMost(k, fn) }129inline fun <T> Array<T>.forAtMost(k: Int, fn: (T) -> Unit): Array<T> = apply { toList().forAtMost(k, fn) }130inline fun <T, C : Collection<T>> C.forAtMost(k: Int, fn: (T) -> Unit): C = apply {131 val results = runTests(this, fn)132 val passed = results.filterIsInstance<ElementPass<T>>()133 if (passed.size > k) {134 val msg = "${passed.size} elements passed but expected at most $k"135 buildAssertionError(msg, results)136 }137}138inline fun <K, V, C : Map<K, V>> C.forNoneValue(fn: (V) -> Unit): C = apply { values.forNone(fn) }139inline fun <K, V, C : Map<K, V>> C.forNoneKey(fn: (K) -> Unit): C = apply { keys.forNone(fn) }140inline fun <K, V, C : Map<K, V>> C.forNone(fn: (Map.Entry<K, V>) -> Unit): C = apply {141 val results = runTests(this, fn)142 val passed = results.filterIsInstance<ElementPass<Map.Entry<K, V>>>()143 if (passed.isNotEmpty()) {144 val msg = "${passed.size} elements passed but expected ${0}"145 buildAssertionError(msg, results)146 }147}148inline fun CharSequence.forNone(fn: (Char) -> Unit): CharSequence = apply { toList().forNone(fn) }149inline fun <T> Sequence<T>.forNone(fn: (T) -> Unit): Sequence<T> = apply { toList().forNone(fn) }150inline fun <T> Array<T>.forNone(fn: (T) -> Unit): Array<T> = apply { toList().forNone(fn) }151inline fun <T, C : Collection<T>> C.forNone(f: (T) -> Unit): C = apply {152 val results = runTests(this, f)153 val passed = results.filterIsInstance<ElementPass<T>>()154 if (passed.isNotEmpty()) {155 val msg = "${passed.size} elements passed but expected ${0}"156 buildAssertionError(msg, results)157 }158}159/**160 * Checks that [Sequence] consists of a single element, which passes the given assertion block [fn]161 * and returns the element162 * */163fun <T> Sequence<T>.forSingle(fn: (T) -> Unit): T = toList().forSingle(fn)164/**165 * Checks that [Array] consists of a single element, which passes the given assertion block [fn]166 * and returns the element167 * */168fun <T> Array<T>.forSingle(fn: (T) -> Unit): T = toList().forSingle(fn)169/**170 * Checks that [Collection] consists of a single element, which passes the given assertion block [fn]171 * and returns the element172 * */173fun <T, C : Collection<T>> C.forSingle(f: (T) -> Unit): T = run {174 val results = runTests(this, f)175 when (results.size) {176 1 -> when (results[0]) {177 is ElementPass<T> -> results[0].value()178 else -> buildAssertionError("Expected a single element to pass, but it failed.", results)179 }180 0 -> throw failure("Expected a single element in the collection, but it was empty.")181 else -> buildAssertionError("Expected a single element in the collection, but found ${results.size}.", results)182 }183}...
JavaMemberUtilsTests.kt
Source:JavaMemberUtilsTests.kt
1/*2 * Copyright (c) 2022. The Meowool Organization Open Source Project3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 *16 * In addition, if you modified the project, you must include the Meowool17 * organization URL in your code file: https://github.com/meowool18 *19 * å¦ææ¨ä¿®æ¹äºæ¤é¡¹ç®ï¼åå¿
须确ä¿æºæ件ä¸å
å« Meowool ç»ç» URL: https://github.com/meowool20 */21@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")22package com.meowool.cloak23import com.meowool.cloak.case.Animal24import com.meowool.cloak.case.Cat25import com.meowool.cloak.case.Dog26import com.meowool.cloak.case.FieldsContainer27import com.meowool.cloak.case.FieldsParent28import com.meowool.cloak.case.Grass29import com.meowool.cloak.case.Organism30import com.meowool.cloak.case.Rabbit31import com.meowool.cloak.case.Zoo32import io.kotest.inspectors.forAll33import io.kotest.matchers.collections.shouldBeIn34import io.kotest.matchers.collections.shouldNotBeIn35import io.kotest.matchers.nulls.shouldBeNull36import io.kotest.matchers.nulls.shouldNotBeNull37import io.kotest.matchers.shouldBe38import io.kotest.matchers.shouldNotBe39import org.junit.jupiter.api.Test40/**41 * @author å (RinOrz)42 */43class JavaMemberUtilsTests {44 @Test fun `match the best constructor`() {45 Zoo::class.java.matchBestConstructor().shouldBeNull()46 // case of primitive or wrapper of the same type: `true` or `java.lang.Boolean.valueOf(true)`47 // result: `constructor(open: Boolean)`48 arrayOf(49 Zoo::class.java.matchBestConstructor(Boolean::class.javaPrimitiveType),50 Zoo::class.java.matchBestConstructor(Boolean::class.javaObjectType),51 ).forEach {52 it shouldBe Zoo.BOOLEAN53 it shouldNotBe Zoo.INT54 }55 // case of passed some primitive numbers: `10.0`, `10f`, etc...56 // result: `constructor(id: Int)`57 arrayOf(58 Byte::class.java,59 Short::class.java,60 Int::class.java,61 Long::class.java,62 Float::class.java,63 Double::class.java,64 ).map { Zoo::class.java.matchBestConstructor(it) }.forAll {65 it shouldBe Zoo.INT66 it shouldNotBeIn arrayOf(67 Zoo.BOOLEAN,68 Zoo.INT_OBJ_VARARG_ANIMAL,69 )70 }71 // case of when there are primitive and wrapper of the same kind and one of them has varargs:72 // no vararg passed: `Integer.valueOf(10)`73 // result: `constructor(id: Int? /* Integer */, vararg animals: Animal)`74 Zoo::class.java.matchBestConstructor(Int::class.javaObjectType) shouldBeIn arrayOf(75 Zoo.INT_OBJ_VARARG_ANIMAL,76 Zoo.INT_OBJ_VARARG_Int,77 )78 // case of when there are primitive and wrapper of the same kind and one of them has varargs:79 // no vararg passed: `Integer.valueOf(10)`80 // result: `constructor(id: Int? /* Integer */, vararg animals: Animal)`81 Zoo::class.java.matchBestConstructor(CharSequence::class.javaObjectType) shouldNotBeIn arrayOf(82 Zoo.STRING,83 Zoo.STRING_VARARG_ANIMAL,84 Zoo.STRING_VARARG_CAT85 )86 // constructor(name: String, vararg cats: Cat)87 Zoo::class.java.matchBestConstructor(null, Cat::class.java) shouldBe Zoo.STRING_VARARG_CAT88 // constructor(cat: Cat)89 Zoo::class.java.matchBestConstructor(Cat::class.java) shouldBe Zoo.CAT90 // constructor(dog: Dog)91 Zoo::class.java.matchBestConstructor(Dog::class.java) shouldBe Zoo.DOG92 // constructor(organism: Organism)93 Zoo::class.java.matchBestConstructor(Grass::class.java) shouldBe Zoo.ORGANISM94 // closer interface has higher priority95 // result: `constructor(animal: Animal)`96 Zoo::class.java.matchBestConstructor(Rabbit::class.java).also {97 it shouldBe Zoo.ANIMAL98 it shouldNotBe Zoo.ORGANISM99 }100 // case of multiple matches, determined by bytecode order101 Zoo::class.java.matchBestConstructor(null) shouldBe Zoo::class.java.declaredConstructors.first {102 it.parameterTypes.size == 1 && it.parameterTypes.first().isObject103 }104 // constructor(name: String, vararg animals: Animal)105 Zoo::class.java.matchBestConstructor(null, Animal::class.java) shouldBe Zoo::class.java.declaredConstructors.first {106 it.parameterTypes.size == 2 && it.parameterTypes.first().isObject && it.parameterTypes.last() == Array<Animal>::class.java107 }108 Zoo::class.java.matchBestConstructor(null, null) shouldBe Zoo::class.java.declaredConstructors.first {109 it.parameterTypes.size == 2 && it.parameterTypes.first().isObject && it.parameterTypes.last().isObject110 }111 }112 @Test fun `match the best field`() {113 // int114 FieldsContainer::class.java.matchBestField("intField", null).shouldNotBeNull().shouldBeIn(115 FieldsContainer::class.java.matchBestField("intField", Int::class.javaObjectType),116 FieldsContainer::class.java.matchBestField(null, Int::class.javaPrimitiveType),117 FieldsContainer::class.java.getDeclaredField("intField"),118 )119 // boolean120 FieldsContainer::class.java.matchBestField(null, Boolean::class.javaPrimitiveType).shouldNotBeNull().shouldBeIn(121 FieldsParent::class.java.matchBestField("booleanField", Boolean::class.javaPrimitiveType),122 FieldsContainer::class.java.getDeclaredField("booleanField"),123 )124 FieldsContainer::class.java.matchBestField("baseBooleanField", null).shouldNotBeNull().shouldBeIn(125 FieldsParent::class.java.matchBestField(null, Boolean::class.javaPrimitiveType),126 FieldsParent::class.java.getDeclaredField("baseBooleanField")127 )128 FieldsContainer::class.java.matchBestField(null, Boolean::class.javaObjectType).shouldNotBeNull().apply {129 // For performance reasons, if the class is found, the super class will not be traversed,130 shouldNotBe(FieldsParent::class.java.getDeclaredField("baseBooleanObjectField"))131 // therefore, the result is the earliest matched field that type is boolean132 shouldBe(FieldsContainer::class.java.getDeclaredField("booleanField"))133 }134 // string135 FieldsContainer::class.java.matchBestField(null, String::class.java).shouldNotBeNull().shouldBe(136 FieldsParent::class.java.getDeclaredField("baseStringField"),137 )138 // interface139 FieldsContainer::class.java.matchBestField(null, Organism::class.java).shouldNotBeNull().shouldBe(140 FieldsContainer::class.java.getDeclaredField("interfaceLowField")141 )142 FieldsContainer::class.java.matchBestField(null, Cat::class.java).shouldNotBeNull().shouldBeIn(143 FieldsContainer::class.java.matchBestField(null, Animal::class.java),144 FieldsContainer::class.java.getDeclaredField("interfaceField"),145 )146 // non147 FieldsContainer::class.java.matchBestField(null, Object::class.java).shouldBeNull()148 }149}...
CharSequence.forAll
Using AI Code Generation
1fun testAllStrings() {2 val strings = listOf("abc", "def", "ghi")3 strings.forAll { it should haveLength(3) }4}5fun testAtLeastStrings() {6 val strings = listOf("abc", "def", "ghi")7 strings.forAtLeast(2) { it should haveLength(3) }8}9fun testAtMostStrings() {10 val strings = listOf("abc", "def", "ghi")11 strings.forAtMost(1) { it should haveLength(3) }12}13fun testExactlyStrings() {14 val strings = listOf("abc", "def", "ghi")15 strings.forExactly(1) { it should haveLength(3) }16}17fun testNoneStrings() {18 val strings = listOf("abc", "def", "ghi")19 strings.forNone { it should haveLength(4) }20}21fun testOneStrings() {22 val strings = listOf("abc", "def", "ghi")23 strings.forOne { it should haveLength(3) }24}25fun testSomeStrings() {26 val strings = listOf("abc", "def", "ghi")27 strings.forSome { it should haveLength(3) }28}29fun testSomeStrings() {30 val strings = listOf("abc", "def", "ghi")31 strings.forSome { it should haveLength(3) }32}33fun testAtLeastOneStrings() {34 val strings = listOf("abc", "def", "ghi")35 strings.forAtLeastOne { it should
CharSequence.forAll
Using AI Code Generation
1 "CharSequence.forAll" {2 val list = listOf("a", "b", "c")3 list.forAll { it.shouldNotBeNullOrBlank() }4 }5 "CharSequence.forNone" {6 val list = listOf("a", "b", "c")7 list.forNone { it.shouldBeNull() }8 }9 "CharSequence.forOne" {10 val list = listOf("a", "b", "c")11 list.forOne { it.shouldBeNull() }12 }13 "CharSequence.forAtLeastOne" {14 val list = listOf("a", "b", "c")15 list.forAtLeastOne { it.shouldBeNull() }16 }17 "CharSequence.forAtLeast" {18 val list = listOf("a", "b", "c")19 list.forAtLeast(2) { it.shouldBeNull() }20 }21 "CharSequence.forAtMostOne" {22 val list = listOf("a", "b", "c")23 list.forAtMostOne { it.shouldBeNull() }24 }
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!