How to use exist method of io.kotest.matchers.collections.matchers class

Best Kotest code snippet using io.kotest.matchers.collections.matchers.exist

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

EndToEndTest.kt

Source:EndToEndTest.kt Github

copy

Full Screen

...5import io.kotest.assertions.throwables.shouldNotThrowAny6import io.kotest.core.spec.style.FreeSpec7import io.kotest.matchers.collections.shouldContainInOrder8import io.kotest.matchers.collections.shouldHaveSize9import io.kotest.matchers.file.exist10import io.kotest.matchers.should11import io.kotest.matchers.shouldBe12import io.kotest.matchers.shouldNotBe13import io.kotest.matchers.string.shouldContain14import org.gradle.testkit.runner.GradleRunner15import org.gradle.testkit.runner.TaskOutcome.*16import java.io.File17class EndToEndTest : FreeSpec({18 "Given a project using the plugin" - {19 val projectDir = tempdir().projectStruct {20 createSettingsFile()21 createBuildFile().writeText("""22 plugins {23 `java`24 id("$BASE_PLUGIN_ID")25 }26 27 import ${GradlecumberPlugin::class.java.`package`.name}.*28 29 repositories {30 jcenter()31 }32 33 val featureTest by cucumber.suites.creating {34 rules { result ->35 if(result.pickle.tags.contains("@failing")) cucumber.OK36 else cucumber.checkResultNotPassedOrSkipped(result)37 }38 }39 40 dependencies {41 cucumber.configurationName(cucumberJava("6.+"))42 "featureTestImplementation"("org.opentest4j:opentest4j:1.2.+")43 }44 45 val strictCheck by tasks.registering {46 47 val msgs = project.tasks48 .named<${CucumberExec::class.simpleName}>(featureTest.cucumberExecTaskName)49 .flatMap { it.formatDestFile("message") }50 51 inputs.file(msgs)52 53 doLast {54 println("Checking cucumber results strictly")55 cucumber.checkCucumberResults {56 messages.fileProvider(msgs)57 }58 }59 }60 61 val checkNoFeatureTestsExist by tasks.registering(${io.github.hWorblehat.gradlecumber.CucumberCheckResults::class.simpleName}::class) {62 messages.fileProvider(project.tasks63 .named<${CucumberExec::class.simpleName}>(featureTest.cucumberExecTaskName)64 .flatMap { it.formatDestFile("message") }65 )66 67 rules { "Test exists when it shouldn't" }68 }69 """.trimIndent())70 createFile("src/main/java/pkg/MyClass.java").writeText("""71 package pkg;72 73 public class MyClass {74 75 private boolean somethingHasBeenDone = false;76 77 public void doSomething() {78 somethingHasBeenDone = true;79 }80 81 public boolean hasSomethingBeenDone() {82 return somethingHasBeenDone;83 }84 85 }86 """.trimIndent())87 createFile("src/featureTest/java/glue/Glue.java").writeText("""88 package glue;89 90 import pkg.MyClass;91 import org.opentest4j.AssertionFailedError;92 import io.cucumber.java.en.*;93 94 public class Glue {95 96 private MyClass testSubject = null;97 98 @Given("MyClass")99 public void givenMyClass() {100 testSubject = new MyClass();101 }102 103 @When("it does something")104 public void whenItDoesSomething() {105 testSubject.doSomething();106 }107 108 @When("nothing is done")109 public void whenNothingIsDone() {110 // do nothing 111 }112 113 @Then("something has been done")114 public void somethingHasBeenDone() {115 if(!testSubject.hasSomethingBeenDone()) {116 throw new AssertionFailedError("Nothing had been done.");117 }118 }119 120 }121 """.trimIndent())122 createFile("src/featureTest/gherkin/pkg/MyClass.feature").writeText("""123 Feature: My Class124 125 Scenario: MyClass remembers when something has been done126 Given MyClass127 When it does something128 Then something has been done129 130 @failing131 Scenario: MyClass remembers when nothing has been done132 Given MyClass133 When nothing is done134 Then something has been done135 136 """.trimIndent())137 }138 val gradleRunner = GradleRunner.create()139 .withPluginClasspath()140 .withProjectDir(projectDir)141 "running 'build' includes the cucumber tests" {142 val result = shouldNotThrowAny { gradleRunner.withArguments("build").build() }143 result.taskPaths(SUCCESS) shouldContainInOrder listOf(144 ":classes",145 ":cucumberFeatureTest",146 ":checkCucumberResultsFeatureTest"147 )148 File(projectDir, "build/cucumberMessages/featureTest/featureTest.ndjson") should exist()149 }150 "running ad-hoc checkCucumberResults works as expected" {151 val result = shouldNotThrowAny { gradleRunner.withArguments("strictCheck").buildAndFail() }152 result.task(":strictCheck").let {153 it shouldNotBe null154 it?.outcome shouldBe FAILED155 }156 result.output shouldContain "Step FAILED:"157 result.output shouldContain "Scenario: MyClass remembers when nothing has been done"158 }159 "running manually defined ${io.github.hWorblehat.gradlecumber.CucumberCheckResults::class.simpleName} task triggers the referenced ${CucumberExec::class.simpleName} task" {160 val result = shouldNotThrowAny { gradleRunner.withArguments("clean", "checkNoFeatureTestsExist").buildAndFail() }161 result.task(":cucumberFeatureTest").let {162 it shouldNotBe null163 it?.outcome shouldBe SUCCESS164 }165 result.task(":checkNoFeatureTestsExist").let {166 it shouldNotBe null167 it?.outcome shouldBe FAILED168 }169 result.output shouldContain "Test exists when it shouldn't"170 }171 "running a subsequent 'check' doesn't rerun up-to-date cucumber checks" {172 val result = shouldNotThrowAny { gradleRunner.withArguments("check").build() }173 result.task(":featureTestClasses")!!.outcome shouldBe UP_TO_DATE174 result.task(":cucumberFeatureTest")!!.outcome shouldBe UP_TO_DATE175 result.task(":checkCucumberResultsFeatureTest")!!.outcome shouldBe SUCCESS176 }177 }178})...

Full Screen

Full Screen

IteratorUtilsTests.kt

Source:IteratorUtilsTests.kt Github

copy

Full Screen

...69 iterator.shouldNotHaveNext()70 }71 }72 // TODO: 'asUnmodifiable' is not the easiest to test, as we can't actually just check if it's an instance of73 // 'MutableIterator' as that type doesn't actually exist on the JVM side, so figure out a way to properly74 // test this, for now it's disabled. The way we create the unmodifiable view is also dependent on compiler75 // intrinsics, so it's a bit wishy washy to test, as it depends on behavior that's not publicly defined and76 // may be changed.77 xcontext("Invoking iterator.asUnmodifiable()") {78 should("return an unmodifiable view of the iterator") {79 val originalIterator = mutableListOf("hello").iterator()80 originalIterator.shouldBeInstanceOf<MutableIterator<*>>()81 val unmodifiableIterator = originalIterator.asUnmodifiable()82 unmodifiableIterator.shouldNotBeInstanceOf<MutableIterator<*>>()83 unmodifiableIterator.shouldHaveNext()84 unmodifiableIterator.next() shouldBe "hello"85 unmodifiableIterator.shouldNotHaveNext()86 }87 }...

Full Screen

Full Screen

RestaurantTest.kt

Source:RestaurantTest.kt Github

copy

Full Screen

1/*2 * Jopiter APP3 * Copyright (C) 2021 Leonardo Colman Lopes4 *5 * This program is free software: you can redistribute it and/or modify6 * it under the terms of the GNU Affero General Public License as published by7 * the Free Software Foundation, either version 3 of the License, or8 * (at your option) any later version.9 *10 * This program is distributed in the hope that it will be useful,11 * but WITHOUT ANY WARRANTY; without even the implied warranty of12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13 * GNU Affero General Public License for more details.14 *15 * You should have received a copy of the GNU Affero General Public License16 * along with this program. If not, see <https://www.gnu.org/licenses/>.17 */18package app.jopiter.restaurants.model19import com.github.kittinunf.fuel.core.Headers20import com.github.kittinunf.fuel.httpPost21import com.github.kittinunf.fuel.jackson.responseObject22import io.kotest.core.annotation.Tags23import io.kotest.core.spec.style.FunSpec24import io.kotest.inspectors.forAll25import io.kotest.matchers.collections.shouldExist26import io.kotest.matchers.collections.shouldHaveSize27import io.kotest.matchers.shouldBe28import java.lang.System.getenv29@Tags("Daily")30class RestaurantTest : FunSpec({31 test("Restaurants model reflects what USP returns") {32 val restaurantsReturnedByUSP = "https://uspdigital.usp.br/rucard/servicos/restaurants".httpPost()33 .header(Headers.CONTENT_TYPE, "application/x-www-form-urlencoded")34 .body("hash=${getenv("USP_RESTAURANT_HASH")}")35 .responseObject<List<RestaurantGroup>>().third.get()36 with(restaurantsReturnedByUSP) {37 Campus.values() shouldHaveSize size38 forEach { group ->39 val campus = Campus.values().single { it.campusName == group.name }40 group.restaurants.forAll { restaurant ->41 campus.restaurants.shouldExist { it.id == restaurant.id && it.restaurantName == restaurant.alias }42 }43 }44 }45 }46 test("Should return restaurant by id") {47 val restaurant = Restaurant.values().random()48 Restaurant.getById(restaurant.id) shouldBe restaurant49 }50})51data class RestaurantGroup(val name: String, val restaurants: List<IndividualRestaurant>)52data class IndividualRestaurant(val alias: String, val id: Int)...

Full Screen

Full Screen

AssertJTest.kt

Source:AssertJTest.kt Github

copy

Full Screen

1package ru.iopump.qa.sample.comment2import io.kotest.assertions.assertSoftly3import io.kotest.assertions.throwables.shouldThrow4import io.kotest.core.spec.style.FreeSpec5import io.kotest.matchers.collections.shouldContainExactlyInAnyOrder6import io.kotest.matchers.collections.shouldExistInOrder7import io.kotest.matchers.ints.shouldBeInRange8import io.kotest.matchers.shouldBe9import org.assertj.core.api.Assertions.assertThat10import org.assertj.core.api.Assertions.within11import org.assertj.core.api.SoftAssertions12class AssertJTest : FreeSpec() {13 init {14 "assertj and kotest asserts" - {15 "assertj simple assert" {16 assertThat(1).isCloseTo(2, within(1))17 }18 "kotest simple assert" {19 1 shouldBeInRange 1..220 }21 val list = listOf(1, 2, 3)22 "assertj collection" {23 assertThat(list).containsExactlyInAnyOrder(1, 2, 3)24 }25 "kotest collection" {26 list shouldContainExactlyInAnyOrder listOf(1, 2, 3)27 list.shouldExistInOrder({ it >= 1 }, { it >= 2 }, { it >= 3 })28 }29 "assertj - assertion error message" {30 shouldThrow<AssertionError> {31 assertThat(1.0).`as` { "Описание ошибки" }.isEqualTo(2.0)32 }.message.also(::println)33 }34 "kotest - assertion error message" {35 shouldThrow<AssertionError> {36 1.0 shouldBe 2.037 }.message.also(::println)38 }39 "assertj - soft assert" {40 shouldThrow<AssertionError> {41 SoftAssertions().apply {42 assertThat(1).isEqualTo(2)43 assertThat(2).isEqualTo(3)44 }.assertAll()45 }.message.also(::println)46 }47 "kotest - soft assert" {48 shouldThrow<AssertionError> {49 assertSoftly {50 1 shouldBe 251 2 shouldBe 352 }53 }.message.also(::println)54 }55 }56 }57}...

Full Screen

Full Screen

FormatFileTest.kt

Source:FormatFileTest.kt Github

copy

Full Screen

...6import io.kotest.matchers.collections.beEmpty7import io.kotest.matchers.nulls.beNull8import io.kotest.matchers.paths.aFile9import io.kotest.matchers.paths.beReadable10import io.kotest.matchers.paths.exist11import io.kotest.matchers.should12import io.kotest.matchers.shouldNot13import java.io.File14import java.nio.file.Files15import java.nio.file.Path16import java.nio.file.Paths17import java.nio.file.StandardCopyOption18class FormatFileTest : WordSpec() {19 companion object {20 val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n";21 }22 private lateinit var actual: File23 private fun resourcePath(name: String): Path {24 val path = this.javaClass.getResource(name)?.let {25 Paths.get(it.file)26 }27 path shouldNot beNull()28 path!! should (exist() and aFile() and beReadable())29 return path.normalize()30 }31 init {32 beforeTest {33 actual = tempfile("format-test")34 }35 "eclipselink result file" should {36 "be formatted" {37 val source = resourcePath("/eclipselink-normal-result.txt")38 val expected = resourcePath("/eclipselink-format-result.txt")39 val actualPath = actual.toPath()40 Files.copy(source, actualPath, StandardCopyOption.REPLACE_EXISTING)41 formatFile(actualPath, true, LINE_SEPARATOR)42 val diff = DiffUtils.diff(Files.readAllLines(expected), Files.readAllLines(actualPath))...

Full Screen

Full Screen

ConfigFileLocatorTest.kt

Source:ConfigFileLocatorTest.kt Github

copy

Full Screen

...23 "autokonfig.conf", "autokonfig.json", "autokonfig.properties",24 "config.conf", "config.json", "config.properties"25 )26 }27 "finds no files when no valid files exist" {28 val locator = createLocator("invalid")29 locator.getConfigFiles().shouldBeEmpty()30 }31 "finds no files when no files exist" {32 val locator = createLocator("empty")33 locator.getConfigFiles().shouldBeEmpty()34 }35 "find no files when base directory does not exist" {36 val locator = createLocator("nonexistent")37 locator.getConfigFiles().shouldBeEmpty()38 }39 "does not search in subdirectories" {40 val locator = createLocator("subdir")41 locator.getConfigFiles().shouldBeEmpty()42 }43})...

Full Screen

Full Screen

CloudRunSpec.kt

Source:CloudRunSpec.kt Github

copy

Full Screen

1package utils2import io.kotest.assertions.fail3import io.kotest.core.spec.style.StringSpec4import io.kotest.matchers.collections.shouldExist5import io.kotest.matchers.collections.shouldNotBeEmpty6import io.kotest.matchers.shouldBe7class CloudRunSpec : StringSpec({8 val projectId = System.getenv("PROJECT_ID") ?: fail("Must set PROJECT_ID env var")9 val regionId = System.getenv("REGION_ID") ?: fail("Must set REGION_ID env var")10 val maybeServiceAccount = System.getenv("SERVICE_ACCOUNT")11 "regions" {12 CloudRun.regions(projectId, maybeServiceAccount).getOrThrow() shouldExist { it.locationId == regionId }13 }14 "services" {15 CloudRun.services(projectId, regionId, maybeServiceAccount).getOrThrow().shouldNotBeEmpty()16 }17 "revision" {18 val serviceName = "one-off-cloud-run-test"19 val service = CloudRun.services(projectId, regionId, maybeServiceAccount).getOrThrow().find { it.metadata.name == serviceName }20 if (service == null) {21 fail("Could not find service $serviceName")22 } else {23 val latestRevision = service.status.latest24 if (latestRevision == null) {25 fail("Could not get latest revision for $serviceName")26 } else {27 val revision = CloudRun.revision(projectId, regionId, latestRevision.revisionName, maybeServiceAccount).getOrThrow()28 revision.metadata.annotations.cloudSqlInstances shouldBe("$projectId:$regionId:one-off-cloud-run-test")29 }30 }31 }32})...

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3)2list should contain(1)3list should containAll(1, 2)4list should containExactly(1, 2, 3)5list should containInOrder(1, 2, 3)6list should containInOrderExactly(1, 2, 3)7list should containInAnyOrder(3, 2, 1)8list should containInAnyOrderExactly(3, 2, 1)9list should containNone(4)10list should containOnly(1, 2, 3)11list should containOnlyNulls()12list should containExactlyNulls()13list should containNull()14list should containKey(1)15list should containValue(1)16list should containKeys(1, 2)17list should containValues(1, 2)18list should containExactlyKeys(1, 2, 3)19list should containExactlyValues(1, 2, 3)20list should containExactlyInAnyOrderKeys(3, 2, 1)

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val list = listOf(1,2,3,4)2list should containAll(1,2)3list should containAll(1,2,3,4)4list should containAll(1,2,3,4,5)5list should containAll(1,2,3,4,5,6)6list should containAll(1,2,3,4,5,6,7)7list should containAll(1,2,3,4,5,6,7,8)8list should containAll(1,2,3,4,5,6,7,8,9)9list should containAll(1,2,3,4,5,6,7,8,9,10)10list should containAll(1,2,3,4,5,6,7,8,9,10,11)11list should containAll(1,2,3,4,5,6,7,8,9,10,11,12)12list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13)13list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14)14list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15)15list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)16list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)17list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)18list should containAll(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19)19list should containAll(1,2,3,4,5,6,7,8,9,10,11,12

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1val list = listOf(1, 2, 3)2list should exist { it == 2 }3list shouldNot exist { it == 4 }4val list = listOf(1, 2, 3)5list should exist { it == 2 }6list shouldNot exist { it == 4 }7val list = listOf(1, 2, 3)8list should exist { it == 2 }9list shouldNot exist { it == 4 }10val list = listOf(1, 2, 3)11list should exist { it == 2 }12list shouldNot exist { it == 4 }13val list = listOf(1, 2, 3)14list should exist { it == 2 }15list shouldNot exist { it == 4 }16val list = listOf(1, 2, 3)17list should exist { it == 2 }18list shouldNot exist { it == 4 }19val list = listOf(1, 2, 3)20list should exist { it == 2 }21list shouldNot exist { it == 4 }22val list = listOf(1, 2, 3)23list should exist { it == 2 }24list shouldNot exist { it == 4 }25val list = listOf(1, 2, 3)26list should exist { it == 2 }27list shouldNot exist { it == 4 }28val list = listOf(1, 2, 3)29list should exist { it == 2 }30list shouldNot exist { it == 4 }

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1 io.kotest.matchers.collections.shouldContainAll(listOf("a","b","c"),"a","b","c")2 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)3 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)4 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)5 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)6 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)7 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)8 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)9 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)10 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)11 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)12 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)13 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)14 io.kotest.matchers.collections.shouldContainAll(listOf(1,2,3),1,2,3)15 }16}

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1 val actual = listOf(1, 2, 3)2 actual should exist { it > 1 }3 val actual = listOf(1, 2, 3)4 actual should contain(1)5 val actual = listOf(1, 2, 3)6 actual should containAll(1, 2)7 val actual = listOf(1, 2, 3)8 actual should containAllInOrder(1, 2)9 val actual = listOf(1, 2, 3)10 actual should containExactly(1, 2)11 val actual = listOf(1, 2, 3)12 actual should containExactlyInAnyOrder(1, 2)13 val actual = listOf(1, 2, 3)14 actual should containInAnyOrder(1, 2)15 val actual = mapOf(1 to "a", 2 to "b", 3 to "c")16 actual should containKey(1)17 val actual = mapOf(1 to "a", 2 to "b", 3 to "c")18 actual should containKeys(1, 2)19 val actual = mapOf(1 to "a", 2 to "b", 3 to "c")20 actual should containValue("a")21 val actual = mapOf(1 to "a", 2 to "

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1println("listOf(1, 2, 3, 4, 5) exist method of io.kotest.matchers.collections.matchers class")2println(listOf(1, 2, 3, 4, 5).exist { it > 3 })3println("listOf(1, 2, 3, 4, 5) shouldNotBe method of io.kotest.matchers.should")4println(listOf(1, 2, 3, 4, 5) shouldNotBe listOf(1, 2, 3, 4, 5))5println("listOf(1, 2, 3, 4, 5) shouldNotBe method of io.kotest.matchers.should")6println(listOf(1, 2, 3, 4, 5) shouldNotBe listOf(1, 2, 3, 4, 6))7println("listOf(1, 2, 3, 4, 5) shouldNotBe method of io.kotest.matchers.should")8println(listOf(1, 2, 3, 4, 5) shouldNotBe listOf(1, 2, 3, 4))9println("listOf(1, 2, 3, 4, 5) shouldBe method of io.kotest.matchers.should")10println(listOf(1, 2, 3, 4, 5) shouldBe listOf(1, 2, 3, 4, 5))11println("listOf(1, 2, 3, 4, 5) shouldBe method of io.kotest.matchers.should")12println(listOf(1, 2, 3, 4, 5) shouldBe listOf(1, 2, 3, 4, 6))13println("listOf(1, 2,

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1@DisplayName("Test to check whether the list contains the given element or not")2fun testExistMethod() {3val list = listOf(1, 2, 3, 4, 5)4}5@DisplayName("Test to check whether the list does not contain the given element or not")6fun testShouldNotContainMethod() {7val list = listOf(1, 2, 3, 4, 5)8}9@DisplayName("Test to check whether the list does not contain the given elements in the given order or not")10fun testShouldNotContainInOrderMethod() {11val list = listOf(1, 2, 3, 4, 5)12}13@DisplayName("Test to check whether the list does not contain the given elements in the given order or not")14fun testShouldNotContainInOrderElementsOfMethod() {15val list = listOf(1, 2, 3, 4, 5)16val anotherList = listOf(1, 2, 3)17val anotherList1 = listOf(1, 2, 4)18}

Full Screen

Full Screen

exist

Using AI Code Generation

copy

Full Screen

1println ( "Exist method output : " + list . exist { it == 4 })2println ( "shouldContain method output : " + list . shouldContain ( 4 ))3println ( "shouldNotContain method output : " + list . shouldNotContain ( 5 ))4println ( "shouldContainAll method output : " + list . shouldContainAll ( 1 , 2 , 3 ))5println ( "shouldContainNone method output : " + list . shouldContainNone ( 5 , 6 , 7 ))6println ( "shouldContainExactly method output : " + list . shouldContainExactly ( 1 , 2 , 3 , 4 ))7println ( "shouldContainInOrder method output : " + list . shouldContainInOrder ( 1 , 2 , 3 , 4 ))8println ( "shouldContainInOrderOnly method output : " + list . shouldContainInOrderOnly ( 1 , 2 , 3 , 4 ))9println ( "shouldContainSame method output : " + list . shouldContainSame ( 1 , 2 , 3 , 4 ))10println ( "shouldHaveSize method output : " + list . shouldHaveSize ( 4 ))11println ( "shouldHaveSingleItem method output : " + list . shouldHaveSingleItem ( 4 ))

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