How to use Map.shouldContain method of io.kotest.matchers.maps.matchers class

Best Kotest code snippet using io.kotest.matchers.maps.matchers.Map.shouldContain

matchers.kt

Source:matchers.kt Github

copy

Full Screen

1package tutorial.kotest2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.assertions.throwables.shouldThrowAny4import io.kotest.assertions.throwables.shouldThrowExactly5import io.kotest.core.spec.style.DescribeSpec6import io.kotest.core.test.AssertionMode7import io.kotest.matchers.booleans.shouldBeTrue8import io.kotest.matchers.collections.shouldBeIn9import io.kotest.matchers.collections.shouldBeOneOf10import io.kotest.matchers.collections.shouldBeSameSizeAs11import io.kotest.matchers.collections.shouldBeSingleton12import io.kotest.matchers.collections.shouldBeSmallerThan13import io.kotest.matchers.collections.shouldBeSorted14import io.kotest.matchers.collections.shouldBeUnique15import io.kotest.matchers.collections.shouldContain16import io.kotest.matchers.collections.shouldContainAll17import io.kotest.matchers.collections.shouldContainAnyOf18import io.kotest.matchers.collections.shouldContainDuplicates19import io.kotest.matchers.collections.shouldContainExactly20import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder21import io.kotest.matchers.collections.shouldContainInOrder22import io.kotest.matchers.collections.shouldContainNull23import io.kotest.matchers.collections.shouldEndWith24import io.kotest.matchers.collections.shouldHaveAtLeastSize25import io.kotest.matchers.collections.shouldHaveLowerBound26import io.kotest.matchers.collections.shouldHaveSingleElement27import io.kotest.matchers.collections.shouldHaveSize28import io.kotest.matchers.collections.shouldHaveUpperBound29import io.kotest.matchers.collections.shouldNotContainAnyOf30import io.kotest.matchers.collections.shouldNotHaveElementAt31import io.kotest.matchers.collections.shouldStartWith32import io.kotest.matchers.comparables.shouldBeEqualComparingTo33import io.kotest.matchers.comparables.shouldBeLessThanOrEqualTo34import io.kotest.matchers.date.shouldBeToday35import io.kotest.matchers.date.shouldHaveSameHoursAs36import io.kotest.matchers.doubles.Percentage37import io.kotest.matchers.doubles.beNaN38import io.kotest.matchers.doubles.plusOrMinus39import io.kotest.matchers.doubles.shouldBeNaN40import io.kotest.matchers.doubles.shouldNotBeNaN41import io.kotest.matchers.equality.shouldBeEqualToComparingFields42import io.kotest.matchers.equality.shouldBeEqualToComparingFieldsExcept43import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields44import io.kotest.matchers.equality.shouldBeEqualToUsingFields45import io.kotest.matchers.file.shouldBeADirectory46import io.kotest.matchers.file.shouldBeAbsolute47import io.kotest.matchers.file.shouldExist48import io.kotest.matchers.file.shouldNotBeEmpty49import io.kotest.matchers.ints.beOdd50import io.kotest.matchers.ints.shouldBeBetween51import io.kotest.matchers.ints.shouldBeInRange52import io.kotest.matchers.ints.shouldBeLessThan53import io.kotest.matchers.ints.shouldBeLessThanOrEqual54import io.kotest.matchers.ints.shouldBeOdd55import io.kotest.matchers.ints.shouldBePositive56import io.kotest.matchers.ints.shouldBeZero57import io.kotest.matchers.iterator.shouldBeEmpty58import io.kotest.matchers.iterator.shouldHaveNext59import io.kotest.matchers.maps.shouldBeEmpty60import io.kotest.matchers.maps.shouldContain61import io.kotest.matchers.maps.shouldContainAll62import io.kotest.matchers.maps.shouldContainExactly63import io.kotest.matchers.maps.shouldContainKey64import io.kotest.matchers.nulls.shouldBeNull65import io.kotest.matchers.nulls.shouldNotBeNull66import io.kotest.matchers.shouldBe67import io.kotest.matchers.shouldNot68import io.kotest.matchers.shouldNotBe69import io.kotest.matchers.string.beEmpty70import io.kotest.matchers.string.shouldBeBlank71import io.kotest.matchers.string.shouldBeEmpty72import io.kotest.matchers.string.shouldBeEqualIgnoringCase73import io.kotest.matchers.string.shouldBeInteger74import io.kotest.matchers.string.shouldBeLowerCase75import io.kotest.matchers.string.shouldBeUpperCase76import io.kotest.matchers.string.shouldContain77import io.kotest.matchers.string.shouldContainADigit78import io.kotest.matchers.string.shouldContainIgnoringCase79import io.kotest.matchers.string.shouldContainOnlyDigits80import io.kotest.matchers.string.shouldContainOnlyOnce81import io.kotest.matchers.string.shouldEndWith82import io.kotest.matchers.string.shouldHaveLength83import io.kotest.matchers.string.shouldHaveLineCount84import io.kotest.matchers.string.shouldHaveMaxLength85import io.kotest.matchers.string.shouldHaveMinLength86import io.kotest.matchers.string.shouldHaveSameLengthAs87import io.kotest.matchers.string.shouldMatch88import io.kotest.matchers.string.shouldNotBeEmpty89import io.kotest.matchers.string.shouldStartWith90import io.kotest.matchers.throwable.shouldHaveCause91import io.kotest.matchers.throwable.shouldHaveCauseInstanceOf92import io.kotest.matchers.throwable.shouldHaveCauseOfType93import io.kotest.matchers.throwable.shouldHaveMessage94import io.kotest.matchers.types.shouldBeInstanceOf95import io.kotest.matchers.types.shouldBeSameInstanceAs96import io.kotest.matchers.types.shouldBeTypeOf97import io.kotest.matchers.uri.shouldHaveHost98import io.kotest.matchers.uri.shouldHavePort99import io.kotest.matchers.uri.shouldHaveScheme100import java.io.File101import java.net.URI102import java.time.LocalDate103import java.time.LocalTime104// https://kotest.io/docs/assertions/core-matchers.html105class MatchersTest : DescribeSpec({106 describe("general") {107 it("basics") {108 (1 == 1).shouldBeTrue()109 (2 + 2) shouldBe 4110 val foo: Any = "foobar"111 foo.shouldBeTypeOf<String>() shouldContain "fo"112 "".shouldBeEmpty()113 "x".shouldNot(beEmpty()) // manually negate114 "x".shouldNotBeEmpty() // reusable115 URI("https://tba") shouldHaveHost "tba"116 URI("https://tba:81") shouldHavePort 81117 URI("https://tba") shouldHaveScheme "https"118 File("/").apply {119 shouldExist()120 shouldBeADirectory()121 shouldBeAbsolute()122 shouldNotBeEmpty()123 }124 // executable, hidden, readable, smaller, writeable, containFile, extension, path, ...125 LocalDate.now().shouldBeToday()126 // before/after, within, same, between, have year/month/day/hour/...127 LocalTime.now().shouldHaveSameHoursAs(LocalTime.now())128 // before/after/between, sameMinute/Seconds/Nanos129 }130 it("numbers") {131 1 shouldBeLessThan 2132 1 shouldBeLessThanOrEqual 1 // Int-based; returns this133 1 shouldBeLessThanOrEqualTo 1 // Comparble-based; void134 1 shouldBeEqualComparingTo 1 // Comparable-based135 1.shouldBeBetween(0, 2)136 1 shouldBeInRange 0..2137 0.shouldBeZero()138 1.shouldBePositive()139 1.shouldBeOdd()140 (1.2).shouldBe(1.20001.plusOrMinus(Percentage(20.0)))141 (1.2).shouldNotBeNaN()142 }143 it("strings") {144 // generic: "abc" shouldBe "abc"145 "aBc" shouldBeEqualIgnoringCase "abc"146 "".shouldBeEmpty()147 " ".shouldBeBlank() // empty or whitespace148 "abc" shouldContain ("b")149 "aBc" shouldContainIgnoringCase "bc"150 "x-a-x" shouldContain """\-[a-z]\-""".toRegex()151 "-a-" shouldMatch """\-[a-z]\-""".toRegex()152 "abc" shouldStartWith ("a")153 "abc" shouldEndWith ("c")154 "ab aa" shouldContainOnlyOnce "aa"155 "abc".shouldBeLowerCase()156 "ABC".shouldBeUpperCase()157 "abc" shouldHaveLength 3158 "a\nb" shouldHaveLineCount 2159 "ab" shouldHaveMinLength 1 shouldHaveMaxLength 3160 "abc" shouldHaveSameLengthAs "foo"161 "1".shouldBeInteger()162 "12".shouldContainOnlyDigits()163 "abc1".shouldContainADigit() // at least one164 }165 it("types") {166 @Connotation167 open class SuperType()168 class SubType : SuperType()169 val sameRef = SuperType()170 sameRef.shouldBeSameInstanceAs(sameRef)171 val superType: SuperType = SubType()172 superType.shouldBeTypeOf<SubType>() // exact runtime match (SuperType won't work!)173 superType.shouldBeInstanceOf<SuperType>() // T or below174// SubType().shouldHaveAnnotation(Connotation::class)175 val nullable: String? = null176 nullable.shouldBeNull()177 }178 it("collections") {179 emptyList<Int>().iterator().shouldBeEmpty()180 listOf(1).iterator().shouldHaveNext()181 listOf(1, 2) shouldContain 1 // at least182 listOf(1, 2) shouldContainExactly listOf(1, 2) // in-order; not more183 listOf(1, 2) shouldContainExactlyInAnyOrder listOf(2, 1) // out-order; not more184 listOf(0, 3, 0, 4, 0).shouldContainInOrder(3, 4) // possible items in between185 listOf(1) shouldNotContainAnyOf listOf(2, 3) // black list186 listOf(1, 2, 3) shouldContainAll listOf(3, 2) // out-order; more187 listOf(1, 2, 3).shouldBeUnique() // no duplicates188 listOf(1, 2, 2).shouldContainDuplicates() // at least one duplicate189 listOf(1, 2).shouldNotHaveElementAt(1, 3)190 listOf(1, 2) shouldStartWith 1191 listOf(1, 2) shouldEndWith 2192 listOf(1, 2) shouldContainAnyOf listOf(2, 3)193 val x = SomeType(1)194 x shouldBeOneOf listOf(x) // by reference/instance195 x shouldBeIn listOf(SomeType(1)) // by equality/structural196 listOf(1, 2, null).shouldContainNull()197 listOf(1) shouldHaveSize 1198 listOf(1).shouldBeSingleton() // size == 1199 listOf(1).shouldBeSingleton {200 it.shouldBeOdd()201 }202 listOf(1).shouldHaveSingleElement {203 beOdd().test(it).passed() // have to return a boolean here :-/204 }205 listOf(2, 3) shouldHaveLowerBound 1 shouldHaveUpperBound 4206 listOf(1) shouldBeSmallerThan listOf(1, 2)207 listOf(1) shouldBeSameSizeAs listOf(2)208 listOf(1, 2) shouldHaveAtLeastSize 1209 listOf(1, 2).shouldBeSorted()210 mapOf(1 to "a").shouldContain(1, "a") // at least this211 mapOf(1 to "a") shouldContainAll mapOf(1 to "a") // at least those212 mapOf(1 to "a") shouldContainExactly mapOf(1 to "a") // not more213 mapOf(1 to "a") shouldContainKey 1214 emptyMap<Any, Any>().shouldBeEmpty()215 }216 it("exceptions") {217 class SubException() : Exception()218 Exception("a") shouldHaveMessage "a" // same (not contains!)219 Exception("abc").message shouldContain "b"220 Exception("", Exception()).shouldHaveCause()221 Exception("symptom", Exception("cause")).shouldHaveCause {222 it.message shouldBe "cause"223 }224 Exception("", SubException()).shouldHaveCauseInstanceOf<Exception>() // T or subclass225 Exception("", SubException()).shouldHaveCauseOfType<SubException>() // exactly T226 shouldThrow<Exception> { // type or subtype227 throw SubException()228 }229 shouldThrowExactly<Exception> { // exactly that type (no subtype!)230 throw Exception()231 }232 shouldThrowAny { // don't care which233 throw Exception()234 }235 }236 }237 describe("advanced") {238 it("selective matcheres") {239 data class Foo(val p1: Int, val p2: Int)240 val foo1 = Foo(1, 1)241 val foo2 = Foo(1, 2)242 foo1.shouldBeEqualToUsingFields(foo2, Foo::p1)243 foo1.shouldBeEqualToIgnoringFields(foo2, Foo::p2)244 class Bar(val p1: Int, val p2: Int) // not a data class! no equals.245 val bar1a = Bar(1, 1)246 val bar1b = Bar(1, 1)247 bar1a shouldNotBe bar1b248 bar1a shouldBeEqualToComparingFields bar1b // "fake equals" (ignoring private properties)249 bar1a.shouldBeEqualToComparingFields(bar1b, false) // explicitly also check private props250 val bar2 = Bar(1, 2)251 bar1a.shouldBeEqualToComparingFieldsExcept(bar2, Bar::p2)252 }253 }254 // channels255 // concurrent, futures256 // result, optional257 // threads258 // reflection259 // statistic, regex260})261private data class SomeType(val value: Int = 1)262private annotation class Connotation...

Full Screen

Full Screen

ReplVarsTest.kt

Source:ReplVarsTest.kt Github

copy

Full Screen

1package org.jetbrains.kotlinx.jupyter.test.repl2import io.kotest.matchers.collections.shouldBeEmpty3import io.kotest.matchers.collections.shouldContain4import io.kotest.matchers.maps.shouldBeEmpty5import io.kotest.matchers.maps.shouldContainValue6import io.kotest.matchers.maps.shouldHaveSize7import io.kotest.matchers.maps.shouldNotBeEmpty8import io.kotest.matchers.shouldBe9import org.jetbrains.kotlinx.jupyter.api.VariableStateImpl10import org.jetbrains.kotlinx.jupyter.test.getStringValue11import org.jetbrains.kotlinx.jupyter.test.getValue12import org.jetbrains.kotlinx.jupyter.test.mapToStringValues13import org.junit.jupiter.api.Test14class ReplVarsTest : AbstractSingleReplTest() {15 override val repl = makeSimpleRepl()16 private val varState get() = repl.notebook.variablesState17 private val cellVars get() = repl.notebook.cellVariables18 private fun cellVarsAt(i: Int) = cellVars[i]!!19 private val firstCellVars get() = cellVarsAt(0)20 private val secondCellVars get() = cellVarsAt(1)21 @Test22 fun testVarsStateConsistency() {23 varState.shouldBeEmpty()24 eval(25 """26 val x = 1 27 val y = 028 val z = 4729 """.trimIndent()30 )31 varState.mapToStringValues() shouldBe mutableMapOf(32 "x" to "1",33 "y" to "0",34 "z" to "47"35 )36 varState.getStringValue("x") shouldBe "1"37 varState.getStringValue("y") shouldBe "0"38 varState.getValue("z") shouldBe 4739 (varState["z"] as VariableStateImpl).update()40 varState.getValue("z") shouldBe 4741 }42 @Test43 fun testVarsEmptyState() {44 val res = eval("3+2")45 val strState = varState.mapToStringValues()46 varState.shouldBeEmpty()47 res.metadata.evaluatedVariablesState shouldBe strState48 }49 @Test50 fun testVarsCapture() {51 eval(52 """53 val x = 1 54 val y = "abc"55 val z = x56 """.trimIndent()57 )58 varState.mapToStringValues() shouldBe mapOf("x" to "1", "y" to "abc", "z" to "1")59 varState.getValue("x") shouldBe 160 varState.getStringValue("y") shouldBe "abc"61 varState.getStringValue("z") shouldBe "1"62 }63 @Test64 fun testVarsCaptureSeparateCells() {65 eval(66 """67 val x = 1 68 val y = "abc"69 val z = x70 """.trimIndent()71 )72 varState.shouldNotBeEmpty()73 eval(74 """75 val x = "abc" 76 var y = 12377 val z = x78 """.trimIndent(),79 jupyterId = 180 )81 varState shouldHaveSize 382 varState.getStringValue("x") shouldBe "abc"83 varState.getValue("y") shouldBe 12384 varState.getStringValue("z") shouldBe "abc"85 eval(86 """87 val x = 1024 88 y += 12389 """.trimIndent(),90 jupyterId = 291 )92 varState shouldHaveSize 393 varState.getStringValue("x") shouldBe "1024"94 varState.getStringValue("y") shouldBe "${123 * 2}"95 varState.getValue("z") shouldBe "abc"96 }97 @Test98 fun testPrivateVarsCapture() {99 eval(100 """101 private val x = 1 102 private val y = "abc"103 val z = x104 """.trimIndent()105 )106 varState.mapToStringValues() shouldBe mapOf("x" to "1", "y" to "abc", "z" to "1")107 varState.getValue("x") shouldBe 1108 }109 @Test110 fun testPrivateVarsCaptureSeparateCells() {111 eval(112 """113 private val x = 1 114 private val y = "abc"115 private val z = x116 """.trimIndent()117 )118 varState.shouldNotBeEmpty()119 eval(120 """121 private val x = "abc" 122 var y = 123123 private val z = x124 """.trimIndent(),125 jupyterId = 1126 )127 varState shouldHaveSize 3128 varState.getStringValue("x") shouldBe "abc"129 varState.getValue("y") shouldBe 123130 varState.getStringValue("z") shouldBe "abc"131 eval(132 """133 private val x = 1024 134 y += x135 """.trimIndent(),136 jupyterId = 2137 )138 varState shouldHaveSize 3139 varState.getStringValue("x") shouldBe "1024"140 varState.getValue("y") shouldBe 123 + 1024141 varState.getStringValue("z") shouldBe "abc"142 }143 @Test144 fun testVarsUsageConsistency() {145 eval("3+2")146 cellVars shouldHaveSize 1147 cellVars.values.first().shouldBeEmpty()148 }149 @Test150 fun testVarsDefsUsage() {151 eval(152 """153 val x = 1154 val z = "abcd"155 var f = 47156 """.trimIndent()157 )158 cellVars shouldContainValue setOf("z", "f", "x")159 }160 @Test161 fun testVarsDefNRefUsage() {162 eval(163 """164 val x = "abcd"165 var f = 47166 """.trimIndent()167 )168 cellVars.shouldNotBeEmpty()169 eval(170 """171 val z = 1172 f += f173 """.trimIndent()174 )175 cellVars shouldContainValue setOf("z", "f", "x")176 }177 @Test178 fun testPrivateVarsDefNRefUsage() {179 eval(180 """181 val x = 124182 private var f = "abcd"183 """.trimIndent()184 )185 cellVars.shouldNotBeEmpty()186 eval(187 """188 private var z = 1189 z += x190 """.trimIndent()191 )192 cellVars shouldContainValue setOf("z", "f", "x")193 }194 @Test195 fun testSeparateDefsUsage() {196 eval(197 """198 val x = "abcd"199 var f = 47200 """.trimIndent(),201 jupyterId = 1202 )203 firstCellVars shouldContain "x"204 eval(205 """206 val x = 341207 var f = "abcd"208 """.trimIndent(),209 jupyterId = 2210 )211 cellVars.shouldNotBeEmpty()212 firstCellVars.shouldBeEmpty()213 secondCellVars shouldBe setOf("x", "f")214 }215 @Test216 fun testSeparatePrivateDefsUsage() {217 eval(218 """219 private val x = "abcd"220 private var f = 47221 """.trimIndent(),222 jupyterId = 1223 )224 firstCellVars shouldContain "x"225 eval(226 """227 val x = 341228 private var f = "abcd"229 """.trimIndent(),230 jupyterId = 2231 )232 cellVars.shouldNotBeEmpty()233 firstCellVars.shouldBeEmpty()234 secondCellVars shouldBe setOf("x", "f")235 }236 @Test237 fun testRecursiveVarsState() {238 eval(239 """240 val l = mutableListOf<Any>()241 l.add(listOf(l))242 243 val m = mapOf(1 to l)244 245 val z = setOf(1, 2, 4)246 """.trimIndent(),247 jupyterId = 1248 )249 varState.getStringValue("l") shouldBe "ArrayList: [exception thrown: java.lang.StackOverflowError]"250 varState.getStringValue("m") shouldBe "SingletonMap: [exception thrown: java.lang.StackOverflowError]"251 varState.getStringValue("z") shouldBe "[1, 2, 4]"252 }253 @Test254 fun testSeparatePrivateCellsUsage() {255 eval(256 """257 private val x = "abcd"258 var f = 47259 internal val z = 47260 """.trimIndent(),261 jupyterId = 1262 )263 firstCellVars shouldContain "x"264 firstCellVars shouldContain "z"265 eval(266 """267 private val x = 341268 f += x269 protected val z = "abcd"270 """.trimIndent(),271 jupyterId = 2272 )273 cellVars.shouldNotBeEmpty()274 firstCellVars shouldBe setOf("f")275 secondCellVars shouldBe setOf("x", "f", "z")276 }277 @Test278 fun testVariableModification() {279 eval("var x = sqrt(25.0)", jupyterId = 1)280 varState.getStringValue("x") shouldBe "5.0"281 varState.getValue("x") shouldBe 5.0282 eval("x = x * x", jupyterId = 2)283 varState.getStringValue("x") shouldBe "25.0"284 varState.getValue("x") shouldBe 25.0285 }286}...

Full Screen

Full Screen

FailingKotestAsserts.kt

Source:FailingKotestAsserts.kt Github

copy

Full Screen

1package testing.failing2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.assertSoftly13import io.kotest.assertions.json.*14import io.kotest.assertions.throwables.shouldThrowAny15import io.kotest.assertions.throwables.shouldThrowExactly16import io.kotest.assertions.withClue17import io.kotest.matchers.Matcher18import io.kotest.matchers.MatcherResult19import io.kotest.matchers.booleans.shouldBeFalse20import io.kotest.matchers.booleans.shouldBeTrue21import io.kotest.matchers.collections.shouldBeEmpty22import io.kotest.matchers.collections.shouldBeOneOf23import io.kotest.matchers.collections.shouldBeSameSizeAs24import io.kotest.matchers.collections.shouldBeSorted25import io.kotest.matchers.collections.shouldContain26import io.kotest.matchers.date.shouldBeAfter27import io.kotest.matchers.ints.shouldBeEven28import io.kotest.matchers.ints.shouldBeGreaterThan29import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual30import io.kotest.matchers.ints.shouldBeLessThan31import io.kotest.matchers.ints.shouldBeLessThanOrEqual32import io.kotest.matchers.ints.shouldBeZero33import io.kotest.matchers.maps.shouldBeEmpty34import io.kotest.matchers.maps.shouldContain35import io.kotest.matchers.maps.shouldContainKey36import io.kotest.matchers.maps.shouldContainValue37import io.kotest.matchers.nulls.shouldBeNull38import io.kotest.matchers.should39import io.kotest.matchers.shouldBe40import io.kotest.matchers.shouldNot41import io.kotest.matchers.string.shouldBeBlank42import io.kotest.matchers.string.shouldBeEmpty43import io.kotest.matchers.string.shouldBeUpperCase44import io.kotest.matchers.string.shouldContain45import io.kotest.matchers.string.shouldNotBeBlank46import java.time.LocalDate47import org.junit.jupiter.api.Test48/**49 * Kotest assertions50 *51 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)52 * - [Github](https://github.com/kotest/kotest/)53 */54class FailingKotestAsserts {55 @Test56 fun `General assertions`() {57 assertSoftly {58 "text" shouldBe "txet"59 "hi".shouldBeBlank()60 " ".shouldNotBeBlank()61 "hi".shouldBeEmpty()62 "hi".shouldBeUpperCase()63 "hello".shouldContain("hi")64 false.shouldBeTrue()65 true.shouldBeFalse()66 "not null".shouldBeNull()67 10 shouldBeLessThan 1068 10 shouldBeLessThanOrEqual 969 11 shouldBeGreaterThan 1170 11 shouldBeGreaterThanOrEqual 1271 9.shouldBeEven()72 1.shouldBeZero()73 }74 }75 @Test76 fun `Exception assertions`() {77 assertSoftly {78 shouldThrowExactly<IllegalArgumentException> {79 angryFunction()80 }81 shouldThrowAny {82 "I'm not throwing anything"83 }84 }85 }86 @Test87 fun `Collection assertions`() {88 assertSoftly {89 listOf(1, 2, 3).shouldBeEmpty()90 listOf(1, 2, 3) shouldContain 491 listOf(1, 3, 2).shouldBeSorted()92 listOf(1, 2, 3, 4) shouldBeSameSizeAs listOf(4, 5, 6)93 1 shouldBeOneOf listOf(2, 3)94 mapOf(1 to "one", 2 to "two", 3 to "three").shouldBeEmpty()95 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 496 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "five"97 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (6 to "six")98 }99 }100 @Test101 fun `Arrow assertions`() {102 assertSoftly {103 val optionNone = none<String>()104 val optionSome = Some("I am something").toOption()105 optionSome.shouldBeNone()106 optionNone.shouldBeSome()107 val rightEither = Either.Right(1)108 val leftEither = Either.Left("ERROR!!")109 leftEither.shouldBeRight()110 leftEither shouldBeRight 1111 rightEither.shouldBeLeft()112 rightEither shouldBeLeft "ERROR!!"113 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5)114 nonEmptyList shouldContain 6115 nonEmptyList.shouldContainNull()116 val valid = Validated.valid()117 val invalid = Validated.invalid()118 invalid.shouldBeValid()119 valid.shouldBeInvalid()120 }121 }122 @Test123 fun `Json assertions`() {124 val jsonString = "{\"test\": \"property\", \"isTest\": true }"125 assertSoftly {126 jsonString shouldMatchJson "{\"test\": \"otherProperty\"}"127 jsonString shouldContainJsonKey "$.anotherTest"128 jsonString shouldNotContainJsonKey "$.test"129 jsonString.shouldContainJsonKeyValue("$.isTest", false)130 }131 }132 @Test133 fun `Custom assertions`() {134 assertSoftly {135 val sentMail = Mail(136 dateCreated = LocalDate.of(2020, 10, 27),137 sent = true, message = "May you have an amazing day"138 )139 val unsentMail = Mail(140 dateCreated = LocalDate.of(2020, 10, 27),141 sent = false, message = "May you have an amazing day"142 )143 // This is possible144 unsentMail.sent should beSent()145 sentMail.sent shouldNot beSent()146 // This is recommended147 unsentMail.shouldBeSent()148 sentMail.shouldNotBeSent()149 }150 }151 @Test152 fun `withClue usage`() {153 val mail = Mail(154 dateCreated = LocalDate.of(2020, 10, 27),155 sent = false, message = "May you have an amazing day"156 )157 withClue("sent field should be true") {158 mail.sent shouldBe true159 }160 mail.asClue {161 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)162 it.sent shouldBe true163 }164 }165 @Test166 fun `asClue usage`() {167 val mail = Mail(168 dateCreated = LocalDate.of(2020, 10, 27),169 sent = false, message = "May you have an amazing day"170 )171 mail.asClue {172 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)173 it.sent shouldBe true174 }175 }176 fun beSent() = object : Matcher<Boolean> {177 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")178 }179 fun Mail.shouldBeSent() = this.sent should beSent()180 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()181}182data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)183fun angryFunction() {184 throw IllegalStateException("How dare you!")185}...

Full Screen

Full Screen

KotestAsserts.kt

Source:KotestAsserts.kt Github

copy

Full Screen

1package testing.asserts2import arrow.core.*3import io.kotest.assertions.arrow.either.shouldBeLeft4import io.kotest.assertions.arrow.either.shouldBeRight5import io.kotest.assertions.arrow.nel.shouldContain6import io.kotest.assertions.arrow.nel.shouldContainNull7import io.kotest.assertions.arrow.option.shouldBeNone8import io.kotest.assertions.arrow.option.shouldBeSome9import io.kotest.assertions.arrow.validation.shouldBeInvalid10import io.kotest.assertions.arrow.validation.shouldBeValid11import io.kotest.assertions.asClue12import io.kotest.assertions.json.*13import io.kotest.assertions.throwables.shouldThrowAny14import io.kotest.assertions.throwables.shouldThrowExactly15import io.kotest.assertions.withClue16import io.kotest.matchers.Matcher17import io.kotest.matchers.MatcherResult18import io.kotest.matchers.booleans.shouldBeFalse19import io.kotest.matchers.booleans.shouldBeTrue20import io.kotest.matchers.collections.shouldBeEmpty21import io.kotest.matchers.collections.shouldBeOneOf22import io.kotest.matchers.collections.shouldBeSameSizeAs23import io.kotest.matchers.collections.shouldBeSorted24import io.kotest.matchers.collections.shouldContain25import io.kotest.matchers.date.shouldBeAfter26import io.kotest.matchers.ints.shouldBeEven27import io.kotest.matchers.ints.shouldBeGreaterThan28import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual29import io.kotest.matchers.ints.shouldBeLessThan30import io.kotest.matchers.ints.shouldBeLessThanOrEqual31import io.kotest.matchers.ints.shouldBeZero32import io.kotest.matchers.maps.shouldBeEmpty33import io.kotest.matchers.maps.shouldContain34import io.kotest.matchers.maps.shouldContainKey35import io.kotest.matchers.maps.shouldContainValue36import io.kotest.matchers.nulls.shouldBeNull37import io.kotest.matchers.should38import io.kotest.matchers.shouldBe39import io.kotest.matchers.shouldNot40import io.kotest.matchers.string.shouldBeBlank41import io.kotest.matchers.string.shouldBeEmpty42import io.kotest.matchers.string.shouldBeUpperCase43import io.kotest.matchers.string.shouldContain44import io.kotest.matchers.string.shouldNotBeBlank45import java.time.LocalDate46import org.junit.jupiter.api.Test47/**48 * Kotest assertions49 *50 * - [Kotest Assertions Documentation](https://kotest.io/assertions/)51 * - [Github](https://github.com/kotest/kotest/)52 */53class KotestAsserts {54 @Test55 fun `General assertions`() {56 "text" shouldBe "text"57 " ".shouldBeBlank()58 "hi".shouldNotBeBlank()59 "".shouldBeEmpty()60 "HI".shouldBeUpperCase()61 "hello".shouldContain("ll")62 true.shouldBeTrue()63 false.shouldBeFalse()64 null.shouldBeNull()65 10 shouldBeLessThan 1166 10 shouldBeLessThanOrEqual 1067 11 shouldBeGreaterThan 1068 11 shouldBeGreaterThanOrEqual 1169 10.shouldBeEven()70 0.shouldBeZero()71 }72 @Test73 fun `Exception assertions`() {74 shouldThrowExactly<IllegalStateException> {75 angryFunction()76 }77 shouldThrowAny {78 angryFunction()79 }80 }81 @Test82 fun `Collection assertions`() {83 emptyList<Int>().shouldBeEmpty()84 listOf(1, 2, 3) shouldContain 385 listOf(1, 2, 3).shouldBeSorted()86 listOf(1, 2, 3) shouldBeSameSizeAs listOf(4, 5, 6)87 1 shouldBeOneOf listOf(1, 2, 3)88 emptyMap<Int, String>().shouldBeEmpty()89 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainKey 190 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContainValue "two"91 mapOf(1 to "one", 2 to "two", 3 to "three") shouldContain (3 to "three")92 }93 @Test94 fun `Arrow assertions`() {95 val optionNone = none<String>()96 val optionSome = Some("I am something").toOption()97 optionNone.shouldBeNone()98 optionSome.shouldBeSome()99 val rightEither = Either.Right(1)100 val leftEither = Either.Left("ERROR!!")101 rightEither.shouldBeRight()102 rightEither shouldBeRight 1103 leftEither.shouldBeLeft()104 leftEither shouldBeLeft "ERROR!!"105 val nonEmptyList = NonEmptyList.of(1, 2, 3, 4, 5, null)106 nonEmptyList shouldContain 1107 nonEmptyList.shouldContainNull()108 val valid = Validated.valid()109 val invalid = Validated.invalid()110 valid.shouldBeValid()111 invalid.shouldBeInvalid()112 }113 @Test114 fun `Json assertions`() {115 val jsonString = "{\"test\": \"property\", \"isTest\": true }"116 jsonString shouldMatchJson jsonString117 jsonString shouldContainJsonKey "$.test"118 jsonString shouldNotContainJsonKey "$.notTest"119 jsonString.shouldContainJsonKeyValue("$.isTest", true)120 }121 @Test122 fun `Custom assertions`() {123 val sentMail = Mail(124 dateCreated = LocalDate.of(2020, 10, 27),125 sent = true, message = "May you have an amazing day"126 )127 val unsentMail = Mail(128 dateCreated = LocalDate.of(2020, 10, 27),129 sent = false, message = "May you have an amazing day"130 )131 // This is possible132 sentMail.sent should beSent()133 unsentMail.sent shouldNot beSent()134 // This is recommended135 sentMail.shouldBeSent()136 unsentMail.shouldNotBeSent()137 }138 @Test139 fun `withClue usage`() {140 val mail = Mail(141 dateCreated = LocalDate.of(2020, 10, 27),142 sent = false, message = "May you have an amazing day"143 )144 withClue("sent field should be false") {145 mail.sent shouldBe false146 }147 mail.asClue {148 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)149 it.sent shouldBe false150 }151 }152 @Test153 fun `asClue usage`() {154 val mail = Mail(155 dateCreated = LocalDate.of(2020, 10, 27),156 sent = false, message = "May you have an amazing day"157 )158 mail.asClue {159 it.dateCreated shouldBeAfter LocalDate.of(2020, 10, 26)160 it.sent shouldBe false161 }162 }163 fun beSent() = object : Matcher<Boolean> {164 override fun test(value: Boolean) = MatcherResult(value, "Mail.sent should be true", "Mail.sent should be false")165 }166 fun Mail.shouldBeSent() = this.sent should beSent()167 fun Mail.shouldNotBeSent() = this.sent shouldNot beSent()168}169data class Mail(val dateCreated: LocalDate, val sent: Boolean, val message: String)170fun angryFunction() {171 throw IllegalStateException("How dare you!")172}...

Full Screen

Full Screen

JMeterGuiTaskTest.kt

Source:JMeterGuiTaskTest.kt Github

copy

Full Screen

1package de.qualersoft.jmeter.gradleplugin.task2import de.qualersoft.jmeter.gradleplugin.JMeterExtension3import de.qualersoft.jmeter.gradleplugin.PluginTestBase4import de.qualersoft.jmeter.gradleplugin.entryEndsWith5import de.qualersoft.jmeter.gradleplugin.entryStartsWith6import de.qualersoft.jmeter.gradleplugin.matchingEntry7import io.kotest.assertions.withClue8import io.kotest.matchers.collections.contain9import io.kotest.matchers.collections.shouldHaveSize10import io.kotest.matchers.maps.shouldContain11import io.kotest.matchers.maps.shouldHaveSize12import io.kotest.matchers.nulls.beNull13import io.kotest.matchers.should14import io.kotest.matchers.shouldBe15import io.kotest.matchers.shouldHave16import io.kotest.matchers.shouldNot17import io.kotest.matchers.shouldNotHave18import io.kotest.matchers.types.beInstanceOf19import org.gradle.testfixtures.ProjectBuilder20import org.junit.jupiter.api.Test21import org.junit.jupiter.api.assertAll22import java.io.File23import io.kotest.matchers.collections.beEmpty as beEmptyList24/**25 * Remarks: Because gui task is basically a JMeterBaseTask,26 * test are targeting on property chaining27 */28class JMeterGuiTaskTest : JMeterTaskTestBase() {29 @Test30 fun taskShouldInheritGlobalPropertiesFromExtension() {31 val task = createTask<JMeterGuiTask> {32 globalProperties.put("usr", "prop")33 }34 assertAll(35 { task.get().globalProperties.get() shouldHaveSize 1 },36 { task.get().globalProperties.get() shouldContain ("usr" to "prop") }37 )38 }39 @Test40 fun taskShouldOverrideInheritedExtensionGlobalProperties() {41 val task = createTaskWithConfig<JMeterGuiTask>({42 globalProperties.put("usr", "prop")43 }, {44 globalProperties.set(mapOf("task" to "property"))45 })46 assertAll(47 { task.get().globalProperties.get() shouldHaveSize 1 },48 { task.get().globalProperties.get() shouldContain ("task" to "property") }49 )50 }51 @Test52 fun taskCanExtendInheritedExtensionGlobalProperties() {53 val task = createTaskWithConfig<JMeterGuiTask>({54 globalProperties.put("usr", "prop")55 }, {56 globalProperties.put("task", "property")57 })58 assertAll(59 { task.get().globalProperties.get() shouldHaveSize 2 },60 { task.get().globalProperties.get() shouldContain ("usr" to "prop") },61 { task.get().globalProperties.get() shouldContain ("task" to "property") }62 )63 }64 @Test65 fun taskWithJustJmxFileIsEnough() {66 val task = createTaskWithConfig<JMeterGuiTask>({ }, {67 jmxFile.set("Test.jmx")68 }).get()69 val args = task.createRunArguments()70 assertAll(71 { args shouldNot beEmptyList() },72 { withClue("test file flag") { args should contain("-t") } },73 { args shouldHave entryEndsWith("Test.jmx") },74 { withClue("log file flag") { args should contain("-j") } },75 { args shouldHave entryEndsWith("jmeter.log") },76 { withClue("jMeterProperty") { args shouldNotHave entryStartsWith("-J") } },77 { withClue("globalProperty") { args shouldNotHave entryStartsWith("-G") } },78 { withClue("delete flag") { args shouldNot contain("-f") } }79 )80 }81 @Test82 fun canRunWithoutJmxFile() {83 val task = createTask<JMeterGuiTask> { }.get()84 val args = task.createRunArguments()85 args shouldNot contain("-t")86 }87 @Test88 fun runArgsWithGlobalPropertyFileFromExtension() {89 val fileName = "globalExtPropFile.properties"90 val task = createTaskWithConfig<JMeterGuiTask>(91 { globalPropertiesFile.set(File(fileName)) },92 { jmxFile.set("Test.jmx") }93 ).get()94 val args = task.createRunArguments()95 args shouldHave matchingEntry("-G.*$fileName".toRegex())96 }97 @Test98 fun taskWithGlobalPropertyFileFromTask() {99 val fileName = "globalTaskPropFile.properties"100 val task = createTaskWithConfig<JMeterGuiTask>({ }, {101 globalPropertiesFile.set(File(fileName))102 jmxFile.set("Test.jmx")103 }).get()104 val args = task.createRunArguments()105 args shouldHave matchingEntry("-G.*$fileName".toRegex())106 }107 @Test108 fun taskWithGlobalPropertyFileFromTaskOverridesConfig() {109 val confFileName = "globalConfPropFile.properties"110 val taskFileName = "globalTaskPropFile.properties"111 val task = createTaskWithConfig<JMeterGuiTask>({112 globalPropertiesFile.set(File(confFileName))113 }, {114 globalPropertiesFile.set(File(taskFileName))115 jmxFile.set("Test.jmx")116 }).get()117 val args = task.createRunArguments()118 assertAll(119 { args shouldNotHave matchingEntry("-G.*$confFileName".toRegex()) },120 { args shouldHave matchingEntry("-G.*$taskFileName".toRegex()) }121 )122 }123 @Test124 fun runArgsWithGlobalProperties() {125 val task = createTaskWithConfig<JMeterGuiTask>({126 globalProperties.put("conf", "prop1")127 }, {128 globalProperties.put("task", "prop2")129 jmxFile.set("Test.jmx")130 }).get()131 val args = task.createRunArguments()132 assertAll(133 { args should contain("-Gconf=prop1") },134 { args should contain("-Gtask=prop2") }135 )136 }137 @Test138 fun canCreateGuiTaskFromExtension() {139 val project = createProject()140 val ext = project.extensions.getByType(JMeterExtension::class.java)141 ext.withGuiTask("guiTestTask")142 val result = project.tasks.getByName("guiTestTask")143 assertAll(144 { result shouldNot beNull() },145 { result should beInstanceOf<JMeterGuiTask>() },146 { project.tasks.withType(JMeterGuiTask::class.java) shouldHaveSize 1 }147 )148 }149 @Test150 fun canCreateGuiTaskFromExtensionAndApplyConfig() {151 val project = createProject()152 val ext = project.extensions.getByType(JMeterExtension::class.java)153 ext.withGuiTask("configuredGuiTask") {154 it.jmxFile.set("test.jmx")155 }156 val result = project.tasks.getByName("configuredGuiTask")157 (result as JMeterGuiTask).jmxFile.get() shouldBe "test.jmx"158 }159 private fun createProject() = ProjectBuilder.builder().build()160 .also {161 it.plugins.apply(PluginTestBase.PLUGIN_ID)162 }163}...

Full Screen

Full Screen

ModelTest.kt

Source:ModelTest.kt Github

copy

Full Screen

1import io.kotest.assertions.throwables.shouldThrow2import io.kotest.core.spec.style.StringSpec3import io.kotest.core.test.TestCaseOrder4import io.kotest.data.forAll5import io.kotest.engine.config.ConfigManager.init6import io.kotest.matchers.collections.shouldContain7import io.kotest.matchers.collections.shouldHaveSingleElement8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.maps.shouldHaveValues10import io.kotest.matchers.maps.shouldNotContainKey11import io.kotest.matchers.nulls.shouldNotBeNull12import io.kotest.matchers.shouldBe13import io.kotest.property.Arb14import io.kotest.property.Gen15import io.kotest.property.arbitrary.arb16import io.kotest.property.arbitrary.next17import io.kotest.property.arbitrary.string18import io.kotest.property.checkAll19import io.kotest.property.forAll20import models.Sentence21import models.WebPage22import java.io.File23import java.lang.IllegalArgumentException24class ModelSpec : StringSpec() {25 override fun testCaseOrder(): TestCaseOrder? = TestCaseOrder.Sequential26 init {27 "beforeAll set database configuration" {28 Configuration.databaseFile = "ModelSpecTest.db"29 Configuration.SentenceDirectory = "sentenceTest/"30 clearDirectory()31 Model.items = HashMap<String, Int>()32 }33 "Insert value into Model and save" {34 Model.items["test"] = 235 Model.saveModel()36 }37 "Read value from saved Model" {38 Model.readModel()39 Model.items.keys shouldContain "test"40 Model.items.keys.size shouldBe 141 Model.items.shouldHaveValues(2)42 }43 "Property testing with random words" {44 }45 }46}47class WebPageSpec : StringSpec() {48 init {49 "Before all change webPage directory" {50 //Configuration.WebPageDirectory = "webPageTest"51 //clearDirectory(Configuration.WebPageDirectory)52 }53 "Instantiate sample test class" {54 //val webPage = WebPage("http://test.com")55 }56 }57}58class SentenceSpec : StringSpec() {59 override fun testCaseOrder(): TestCaseOrder? = TestCaseOrder.Sequential60 init {61 "beforeAll change configuration for test purposes" {62 Configuration.databaseFile = "sentenceTest.db"63 Configuration.SentenceDirectory = "sentenceTest"64 clearDirectory()65 Model.items = HashMap<String, Int>()66 }67 "Add test sentence to keyword test" {68 val set = Sentence("test")69 set.addSentence("This is a test sentence.")70 }71 "Retrieve test sentence using constructor" {72 val set = Sentence("test")73 set.getSentences() shouldHaveSingleElement "This is a test sentence."74 }75 "Add another sentence to same keyword" {76 val set = Sentence("test")77 set.addSentence("Another test is not in vain.")78 }79 "Retrieve all sentences" {80 val set = Sentence("test")81 set.getSentences() shouldContain "Another test is not in vain."82 set.getSentences() shouldContain "This is a test sentence."83 }84 "Insert random string and check if it is correctly added" {85 //this is currenlty meaningless86 val sillyArb = Arb.string()87 val secondArb = Arb.string()88 sillyArb.checkAll { a ->89 val set = Sentence(a)90 val b = secondArb.next()91 set.addSentence(b)92 set.getSentences() shouldContain b93 val setTwo = Sentence(a)94 setTwo.getSentences() shouldContain b95 }96 }97 "Insert very long random sentences" {98 val sillyArb = Arb.string()99 val secondArb = Arb.string()100 sillyArb.checkAll { a ->101 val set = Sentence(a)102 var b = ""103 repeat(100) {104 b += secondArb.next()105 }106 set.addSentence(b)107 set.getSentences() shouldContain b108 val setTwo = Sentence(a)109 setTwo.getSentences() shouldContain b110 }111 }112 "Very hardcore file I/O test that will take a really long time" {113 val sillyArb = Arb.string()114 val secondArb = Arb.string()115 sillyArb.checkAll(100) { a ->116 secondArb.checkAll(100) { b ->117 val set = Sentence(a)118 set.addSentence(b)119 set.getSentences() shouldContain b120 val setTwo = Sentence(a)121 setTwo.getSentences() shouldContain b122 }123 }124 }125 "Replaced character should not be replaced with a soft hypen unicode character" {126 val sillyArb = Arb.string()127 sillyArb.checkAll {128 }129 }130 }131}132//TODO("write more tests for establishing debugging")133class FilterWordsSpec : StringSpec() {134 override fun testCaseOrder(): TestCaseOrder? = TestCaseOrder.Sequential135 init {136 "beforeAll reset model" {137 Model.items = HashMap<String, Int>()138 }139 "No filtered world should appear" {140 Model.items["in"] = 17141 Model.filter()142 for (banWord in Model.bansWord) {143 Model.items shouldNotContainKey banWord144 }145 }146 "Allowed Words should not disapper" {147 Model.items["c++"] = 9148 Model.filter()149 Model.items.keys.size shouldBe 1150 Model.items.keys shouldContain "c++"151 }152 "insert very long word into Model" {153 val longStr : String = "thisContainsManyLargeWordsAndShouldNotBreakTheCurrentImplementation"154 Model.items[longStr] = 12155 Model.items[longStr] shouldBe 12156 }157 }158}...

Full Screen

Full Screen

QueryTest.kt

Source:QueryTest.kt Github

copy

Full Screen

1package com.nuglif.kuri2import io.kotest.assertions.assertSoftly3import io.kotest.matchers.maps.beEmpty4import io.kotest.matchers.maps.haveKey5import io.kotest.matchers.maps.haveSize6import io.kotest.matchers.maps.shouldContain7import io.kotest.matchers.should8import io.kotest.matchers.shouldBe9import io.kotest.matchers.string.shouldBeEmpty10import kotlin.test.Test11class ToParametersTest {12 @Test13 fun givenEmptyQuery_thenReturnEmptyMap() {14 "".asQuery().toParameters() should beEmpty()15 }16 @Test17 fun givenQueryWithoutVariableSeparator_thenReturnSingleElement() {18 "someVariable=someValue".asQuery().toParameters() should haveSize(1)19 }20 @Test21 fun givenQueryWithoutValueSeparator_thenReturnElementMappedToEmptyString() {22 val result = "someVariable&someOtherValue".asQuery().toParameters()23 assertSoftly {24 result should haveSize(2)25 result shouldContain ("someVariable" to "")26 result shouldContain ("someOtherValue" to "")27 }28 }29 @Test30 fun givenQueryCustomSeparators_thenReturnElementMappedToProperValue() {31 val subject = "someVariable->someValue<>someOtherVariable>someOtherValue><someThirdVariable=>someThirdValue"32 val result = subject.asQuery().toParameters(33 variableSeparator = "<>|><".toRegex(),34 valueSeparator = "[-=]?>".toRegex(),35 )36 assertSoftly {37 result should haveSize(3)38 result shouldContain ("someVariable" to "someValue")39 result shouldContain ("someOtherVariable" to "someOtherValue")40 result shouldContain ("someThirdVariable" to "someThirdValue")41 }42 }43}44class ToRawTest {45 @Test46 fun givenEmptyMap_thenReturnEmptyQuery() {47 emptyMap<String, String>().asQuery().raw.value.shouldBeEmpty()48 }49 @Test50 fun givenMap_thenReturnEachEntryJoined() {51 mapOf("a" to "1", "b" to "2", "" to "emptyKey", "emptyVariable" to "")52 .asQuery()53 .raw54 .value shouldBe "a=1&b=2&=emptyKey&emptyVariable="55 }56}...

Full Screen

Full Screen

CaseInsensitiveMapTests.kt

Source:CaseInsensitiveMapTests.kt Github

copy

Full Screen

1package me.l3n.bot.discord.lod.collection2import io.kotest.assertions.throwables.shouldNotThrowAny3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.maps.shouldContain5import io.kotest.matchers.maps.shouldNotContain6private val dravenPair = ("draven" to 1337)7private val capitalizedDravenPair = ("Draven" to 1337)8private val capitalizedDravenDifferentValuePair = ("Draven" to 400)9private val hecarimPair = ("Hecarim" to 120)10private val evelynnPair = ("EVELYNN" to 404)11private val differentPairs = arrayOf(dravenPair, hecarimPair, evelynnPair)12private val sameInsensitivePairs = arrayOf(dravenPair, evelynnPair, capitalizedDravenPair)13private val differentInsensitivePairs = arrayOf(14 dravenPair, evelynnPair, capitalizedDravenDifferentValuePair15)16class CaseInsensitiveMapTests : StringSpec({17 "should create map with pairs successfully" {18 val map = shouldNotThrowAny { caseInsensitiveMapOf(*differentPairs) }19 map shouldContain dravenPair20 map shouldContain hecarimPair21 map shouldContain evelynnPair22 }23 "should add pair successfully" {24 val map = caseInsensitiveMapOf(*differentPairs)25 map[dravenPair.first] = dravenPair.second26 map shouldContain dravenPair27 map shouldContain capitalizedDravenPair28 }29 "should get case insensitive pair" {30 val map = caseInsensitiveMapOf(*differentPairs)31 map shouldContain dravenPair32 map shouldContain capitalizedDravenPair33 map shouldContain evelynnPair34 }35 "should replace same case insensitive pair" {36 val map = caseInsensitiveMapOf(*sameInsensitivePairs)37 map shouldContain dravenPair38 map shouldContain capitalizedDravenPair39 map shouldContain evelynnPair40 }41 "should replace different case insensitive pair" {42 val map = caseInsensitiveMapOf(*differentInsensitivePairs)43 map shouldNotContain dravenPair44 map shouldContain capitalizedDravenDifferentValuePair45 map shouldContain evelynnPair46 }47})...

Full Screen

Full Screen

Map.shouldContain

Using AI Code Generation

copy

Full Screen

1val map = mapOf("a" to 1, "b" to 2)2val map = mapOf("a" to 1, "b" to 2)3val map = mapOf("a" to 1, "b" to 2)4val map = mapOf("a" to 1, "b" to 2)5val map = mapOf("a" to 1, "b" to 2)6val map = mapOf("a" to 1, "b" to 2)7val map = mapOf("a" to 1, "b" to 2)8val map = mapOf("a" to 1, "b" to 2)9val map = emptyMap<String, Int>()10map.shouldBeEmpty()11val map = mapOf("

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