How to use File.shouldBeEmpty method of io.kotest.matchers.file.matchers class

Best Kotest code snippet using io.kotest.matchers.file.matchers.File.shouldBeEmpty

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

ArgumentsTest.kt

Source:ArgumentsTest.kt Github

copy

Full Screen

1package de.qualersoft.robotframework.gradleplugin.utils2import io.kotest.assertions.assertSoftly3import io.kotest.core.spec.style.AnnotationSpec4import io.kotest.matchers.Matcher5import io.kotest.matchers.MatcherResult6import io.kotest.matchers.collections.shouldHaveElementAt7import io.kotest.matchers.collections.shouldHaveSize8import io.kotest.matchers.should9import io.kotest.matchers.shouldNot10import java.io.File11class ArgumentsTest : AnnotationSpec() {12 private lateinit var sut: Arguments13 @BeforeEach14 fun setupTest() {15 sut = Arguments()16 }17 @Test18 fun givenNewArgumentsThenResultIsEmpty() {19 sut.shouldBeEmpty()20 }21 @Test22 fun whenAddingAnOptionalFileOfNullThenResultIsEmpty() {23 sut.addOptionalFile(null, "a")24 sut.shouldBeEmpty()25 }26 @Test27 fun whenAddingAnOptionalNonNullFileThenResultIsNotEmpty() {28 sut.addOptionalFile(File("./test"), "a")29 assertSoftly {30 sut.shouldNotBeEmpty()31 val arr = sut.toArray()32 arr.shouldHaveSize(2)33 arr.shouldHaveElementAt(0, "a")34 arr.shouldHaveElementAt(1, File("./test").path)35 }36 }37 @Test38 fun whenAddingNullFileThenItsConvertedToNone() {39 sut.addFileToArguments(null, "f")40 assertSoftly {41 sut.shouldNotBeEmpty()42 val arr = sut.toArray()43 arr.shouldHaveSize(2)44 arr.shouldHaveElementAt(0, "f")45 arr.shouldHaveElementAt(1, "NONE")46 }47 }48 @Test49 fun whenAddingNonEmptyFileThenItWillBeInResult() {50 sut.addFileToArguments(File("./test"), "f")51 assertSoftly {52 sut.shouldNotBeEmpty()53 val arr = sut.toArray()54 arr.shouldHaveSize(2)55 arr.shouldHaveElementAt(0, "f")56 arr.shouldHaveElementAt(1, File("./test").path)57 }58 }59 @Test60 fun whenAddingEmptyFileThenItsNotInResult() {61 sut.addFileToArguments(File(""), "f")62 sut.shouldBeEmpty()63 }64 @Test65 fun whenAddingNullStringThenItsNotInResult() {66 sut.addNonEmptyStringToArguments(null, "s")67 sut.shouldBeEmpty()68 }69 @Test70 fun whenAddingEmptyStringThenItsNotInResult() {71 sut.addNonEmptyStringToArguments("", "s")72 sut.shouldBeEmpty()73 }74 @Test75 fun whenAddingNonEmptyStringThenItsInResult() {76 sut.addNonEmptyStringToArguments("notEmpty", "s")77 assertSoftly {78 sut.shouldNotBeEmpty()79 val arr = sut.toArray()80 arr.shouldHaveSize(2)81 arr.shouldHaveElementAt(0, "s")82 arr.shouldHaveElementAt(1, "notEmpty")83 }84 }85 @Test86 fun whenAddingEmptyMapThenItsNotInResult() {87 sut.addMapToArguments(mapOf(), "m")88 sut.shouldBeEmpty()89 }90 @Test91 fun whenAddingMapThenItsInResult() {92 sut.addMapToArguments(mapOf("key" to "val"), "m")93 assertSoftly {94 sut.shouldNotBeEmpty()95 val arr = sut.toArray()96 arr.shouldHaveSize(2)97 arr.shouldHaveElementAt(0, "m")98 arr.shouldHaveElementAt(1, "key:val")99 }100 }101 @Test102 fun whenAddingMultiMapThenItsInResult() {103 sut.addMapToArguments(mapOf("key1" to "val1", "key2" to "val2"), "m")104 assertSoftly {105 sut.shouldNotBeEmpty()106 val arr = sut.toArray()107 arr.shouldHaveSize(4)108 arr.shouldHaveElementAt(0, "m")109 arr.shouldHaveElementAt(1, "key1:val1")110 arr.shouldHaveElementAt(2, "m")111 arr.shouldHaveElementAt(3, "key2:val2")112 }113 }114 @Test115 fun whenAddingNullFlagThenItsNotInResult() {116 sut.addFlagToArguments(null, "b")117 sut.shouldBeEmpty()118 }119 @Test120 fun whenAddingFalseFlagThenItsNotInResult() {121 sut.addFlagToArguments(false, "b")122 sut.shouldBeEmpty()123 }124 @Test125 fun whenAddingTrueFlagThenItsInResult() {126 sut.addFlagToArguments(true, "b")127 assertSoftly {128 sut.shouldNotBeEmpty()129 val arr = sut.toArray()130 arr.shouldHaveSize(1)131 arr.shouldHaveElementAt(0, "b")132 }133 }134 @Test135 fun whenAddingOptionalNullStringThenItsNotInResult() {136 sut.addStringToArguments(null, "s")137 sut.shouldBeEmpty()138 }139 @Test140 fun whenAddingOptionalEmptyStringThenItsInResult() {141 sut.addStringToArguments("", "s")142 assertSoftly {143 sut.shouldNotBeEmpty()144 val arr = sut.toArray()145 arr.shouldHaveSize(2)146 arr.shouldHaveElementAt(0, "s")147 arr.shouldHaveElementAt(1, "")148 }149 }150 @Test151 fun whenAddingOptionalNonEmptyStringThenItsInResult() {152 sut.addStringToArguments("NotEmpty", "s")153 assertSoftly {154 sut.shouldNotBeEmpty()155 val arr = sut.toArray()156 arr.shouldHaveSize(2)157 arr.shouldHaveElementAt(0, "s")158 arr.shouldHaveElementAt(1, "NotEmpty")159 }160 }161 @Test162 fun whenAddNullStringListThenItsNotInResult() {163 sut.addListToArguments(null as String?, "s")164 sut.shouldBeEmpty()165 }166 @Test167 fun whenAddStringListThenItsInResult() {168 sut.addListToArguments("aString", "s")169 assertSoftly {170 sut.shouldNotBeEmpty()171 val arr = sut.toArray()172 arr.shouldHaveSize(2)173 arr.shouldHaveElementAt(0, "s")174 arr.shouldHaveElementAt(1, "aString")175 }176 }177 @Test178 fun whenAddingMultiStringListThenEachIsInResult() {179 sut.addListToArguments("str1, str2", "s")180 assertSoftly {181 sut.shouldNotBeEmpty()182 val arr = sut.toArray()183 arr.shouldHaveSize(4)184 arr.shouldHaveElementAt(0, "s")185 arr.shouldHaveElementAt(1, "str1")186 arr.shouldHaveElementAt(2, "s")187 arr.shouldHaveElementAt(3, "str2")188 }189 }190 @Test191 fun whenAddingNullListThenItsNotInResult() {192 sut.addListToArguments(null as List<String?>?, "ls")193 sut.shouldBeEmpty()194 }195 @Test196 fun whenAddingEmptyListThenItsNotInResult() {197 sut.addListToArguments(listOf(), "ls")198 sut.shouldBeEmpty()199 }200 @Test201 fun whenAddingListWithNullThenItsNotInResult() {202 sut.addListToArguments(listOf<String?>(null), "ls")203 sut.shouldBeEmpty()204 }205 @Test206 fun whenAddingListWithEmptyThenItsNotInResult() {207 sut.addListToArguments(listOf(""), "ls")208 sut.shouldBeEmpty()209 }210 @Test211 fun whenAddingListThenItsInResult() {212 sut.addListToArguments(listOf("str"), "ls")213 assertSoftly {214 sut.shouldNotBeEmpty()215 val arr = sut.toArray()216 arr.shouldHaveSize(2)217 arr.shouldHaveElementAt(0, "ls")218 arr.shouldHaveElementAt(1, "str")219 }220 }221 @Test222 fun whenAddingListWithMoreElemsThenEachIsInResult() {223 sut.addListToArguments(listOf("str1", "str2"), "ls")224 assertSoftly {225 sut.shouldNotBeEmpty()226 val arr = sut.toArray()227 arr.shouldHaveSize(4)228 arr.shouldHaveElementAt(0, "ls")229 arr.shouldHaveElementAt(1, "str1")230 arr.shouldHaveElementAt(2, "ls")231 arr.shouldHaveElementAt(3, "str2")232 }233 }234 @Test235 fun whenAddingNullFileListThenItsNotInResult() {236 sut.addFileListToArguments(null, "fl")237 sut.shouldBeEmpty()238 }239 @Test240 fun whenAddingEmptyFileListThenItsNotInResult() {241 sut.addFileListToArguments(listOf(), "fl")242 sut.shouldBeEmpty()243 }244 @Test245 fun whenAddingFileListWithEmptyFileThenItsNotInResult() {246 sut.addFileListToArguments(listOf(File("")), "fl")247 sut.shouldBeEmpty()248 }249 @Test250 fun whenAddingFileListWithFileThenItsInResult() {251 sut.addFileListToArguments(listOf(File("./test")), "fl")252 assertSoftly {253 sut.shouldNotBeEmpty()254 val arr = sut.toArray()255 arr.shouldHaveSize(2)256 arr.shouldHaveElementAt(0, "fl")257 arr.shouldHaveElementAt(1, File("./test").path)258 }259 }260 // <editor-fold desc="Helper extensions">261 private fun beEmpty() = object : Matcher<Arguments> {262 override fun test(value: Arguments) = MatcherResult(263 value.toArray().isEmpty(),264 "Arguments $value should be empty",265 "String $value should not be empty"266 )267 }268 private fun Arguments.shouldBeEmpty() = this should beEmpty()269 private fun Arguments.shouldNotBeEmpty() = this shouldNot beEmpty()270 // </editor-fold>271}...

Full Screen

Full Screen

ContractPluginIntegrationTest.kt

Source:ContractPluginIntegrationTest.kt Github

copy

Full Screen

1package io.provenance.p8e.plugin2import io.kotest.core.spec.IsolationMode3import io.kotest.core.spec.style.WordSpec4import io.kotest.core.test.TestCaseOrder5import io.kotest.matchers.Matcher6import io.kotest.matchers.MatcherResult7import io.kotest.matchers.booleans.shouldBeFalse8import io.kotest.matchers.booleans.shouldBeTrue9import io.kotest.matchers.collections.shouldBeEmpty10import io.kotest.matchers.collections.shouldHaveSize11import io.kotest.matchers.file.shouldHaveFileSize12import io.kotest.matchers.file.shouldNotHaveFileSize13import io.kotest.matchers.should14import io.kotest.matchers.shouldBe15import io.kotest.matchers.shouldNot16import io.kotest.matchers.string.shouldContain17import org.apache.commons.io.FileUtils18import org.apache.commons.io.filefilter.WildcardFileFilter19import org.gradle.testkit.runner.GradleRunner20import org.gradle.testkit.runner.UnexpectedBuildFailure21import java.io.File22import org.gradle.testkit.runner.BuildTask23import org.gradle.testkit.runner.TaskOutcome24class ContractPluginIntegrationTest : WordSpec() {25 override fun testCaseOrder() = TestCaseOrder.Sequential26 override fun isolationMode() = IsolationMode.SingleInstance27 fun haveOutcome(outcome: TaskOutcome) = object: Matcher<BuildTask?> {28 override fun test(value: BuildTask?) = MatcherResult(29 value != null && value.outcome.equals(outcome),30 { "build had outcome ${value?.outcome} but expected outcome: $outcome" },31 { "build should not have outcome: $outcome" },32 )33 }34 fun run(projectDir: File, task: String) = try {35 GradleRunner.create()36 .withProjectDir(projectDir)37 .withPluginClasspath()38 .withArguments(task, "--info", "--stacktrace", "--no-build-cache")39 .build()40 } catch (e: UnexpectedBuildFailure) {41 e.buildResult42 }43 fun p8eClean(projectDir: File) = run(projectDir, "p8eClean")44 fun p8eJar(projectDir: File) = run(projectDir, "p8eJar")45 fun p8eBootstrap(projectDir: File) = run(projectDir, "p8eBootstrap")46 val contractUberJar = "example-kotlin/contracts/build/libs/contracts-1.0-SNAPSHOT-all.jar"47 val contractJar = "example-kotlin/contracts/build/libs/contracts-1.0-SNAPSHOT.jar"48 val contractPath = "example-kotlin/contracts/src/main/kotlin/io/p8e/contracts/examplekotlin/"49 val contractServiceFile = "example-kotlin/contracts/src/main/resources/META-INF/services/io.provenance.scope.contract.contracts.ContractHash"50 val protoJar = "example-kotlin/protos/build/libs/protos-1.0-SNAPSHOT.jar"51 val protoPath = "example-kotlin/protos/src/main/kotlin/io/p8e/proto/examplekotlin/"52 val protoServiceFile = "example-kotlin/protos/src/main/resources/META-INF/services/io.provenance.scope.contract.proto.ProtoHash"53 init {54 "A configured DSL buildscript" should {55 "Start with a clean base" {56 val projectDir = File("example-kotlin")57 val cleanResult = run(projectDir, "clean")58 val p8eCleanResult = p8eClean(projectDir)59 cleanResult.task(":protos:clean") shouldNot haveOutcome(TaskOutcome.FAILED) // UP-TO-DATE or SUCCESS are valid outcomes60 cleanResult.task(":contracts:clean") shouldNot haveOutcome(TaskOutcome.FAILED)61 p8eCleanResult.task(":p8eClean") should haveOutcome(TaskOutcome.SUCCESS)62 FileUtils.listFiles(File(contractPath), WildcardFileFilter("ContractHash*.kt"), WildcardFileFilter("."))63 .shouldBeEmpty()64 FileUtils.listFiles(File(protoPath), WildcardFileFilter("ProtoHash*.kt"), WildcardFileFilter("."))65 .shouldBeEmpty()66 File(contractServiceFile).exists().shouldBeFalse()67 File(protoServiceFile).exists().shouldBeFalse()68 File(contractUberJar).exists().shouldBeFalse()69 File(contractJar).exists().shouldBeFalse()70 File(protoJar).exists().shouldBeFalse()71 }72 "Lead to a successful bootstrap with saved specs" {73 val projectDir = File("example-kotlin")74 val result = p8eBootstrap(projectDir)75 result.task(":p8eBootstrap") should haveOutcome(TaskOutcome.SUCCESS)76 FileUtils.listFiles(File(contractPath), WildcardFileFilter("ContractHash*.kt"), WildcardFileFilter("."))77 .shouldHaveSize(1)78 FileUtils.listFiles(File(protoPath), WildcardFileFilter("ProtoHash*.kt"), WildcardFileFilter("."))79 .shouldHaveSize(1)80 File(contractServiceFile).exists().shouldBeTrue()81 File(protoServiceFile).exists().shouldBeTrue()82 File(contractUberJar).exists().shouldBeTrue()83 result.output.shouldContain("Saved jar")84 result.output.shouldContain("Saved contract specification io.p8e.contracts.examplekotlin.HelloWorldContract")85 }86 "Lead to a successful publish" {87 val projectDir = File("example-kotlin")88 File(contractUberJar).exists().shouldBeTrue()89 val uberJarSize = File(contractUberJar).length()90 File(contractJar).exists().shouldBeFalse()91 File(protoJar).exists().shouldBeTrue()92 val protoJarSize = File(protoJar).length()93 val result = p8eJar(projectDir)94 result.task(":p8eJar") should haveOutcome(TaskOutcome.SUCCESS)95 File(contractUberJar).shouldHaveFileSize(uberJarSize)96 File(contractJar).exists().shouldBeTrue()97 File(protoJar).shouldNotHaveFileSize(protoJarSize)98 }99 "Lead to a successful clean" {100 val projectDir = File("example-kotlin")101 FileUtils.listFiles(File(contractPath), WildcardFileFilter("ContractHash*.kt"), WildcardFileFilter("."))102 .shouldHaveSize(1)103 FileUtils.listFiles(File(protoPath), WildcardFileFilter("ProtoHash*.kt"), WildcardFileFilter("."))104 .shouldHaveSize(1)105 File(contractServiceFile).exists().shouldBeTrue()106 File(protoServiceFile).exists().shouldBeTrue()107 val result = p8eClean(projectDir)108 result.task(":p8eClean") should haveOutcome(TaskOutcome.SUCCESS)109 FileUtils.listFiles(File(contractPath), WildcardFileFilter("ContractHash*.kt"), WildcardFileFilter("."))110 .shouldBeEmpty()111 FileUtils.listFiles(File(protoPath), WildcardFileFilter("ProtoHash*.kt"), WildcardFileFilter("."))112 .shouldBeEmpty()113 File(contractServiceFile).exists().shouldBeFalse()114 File(protoServiceFile).exists().shouldBeFalse()115 }116 }117 }118}...

Full Screen

Full Screen

BagRegulationCheckerTest.kt

Source:BagRegulationCheckerTest.kt Github

copy

Full Screen

1package me.advent.of.code.problems.day72import io.kotest.matchers.collections.shouldBeEmpty3import io.kotest.matchers.collections.shouldContainExactly4import io.kotest.matchers.collections.shouldHaveSize5import io.kotest.matchers.nulls.shouldNotBeNull6import io.kotest.matchers.shouldBe7import me.advent.of.code.reader.readFile8import org.junit.jupiter.api.Test9internal class BagRegulationCheckerTest {10 private val initialInput = readFile("src/test/resources/inputs/day7/input_AoC.txt")11 private var sut = BagRegulationChecker(initialInput)12 @Test13 internal fun `Should split string correctly`() {14 val regulation = "light red bags contain 1 bright white bag, 2 muted yellow bags."15 val extractedRegulation: BagRegulation = sut.extractRegulationFromText(regulation)16 extractedRegulation.bag.colorCode shouldBe "light red"17 val acceptedContent = extractedRegulation.contentRegulation18 acceptedContent shouldHaveSize 219 acceptedContent[0].quantity shouldBe 120 acceptedContent[0].bag shouldBe Bag("bright white", 0)21 acceptedContent[1].quantity shouldBe 222 acceptedContent[1].bag shouldBe Bag("muted yellow", 0)23 }24 @Test25 internal fun `Should split string correctly when final bag`() {26 val regulation = "faded blue bags contain no other bags."27 val extractedRegulation: BagRegulation = sut.extractRegulationFromText(regulation)28 extractedRegulation.bag.colorCode shouldBe "faded blue"29 val acceptedContent = extractedRegulation.contentRegulation30 acceptedContent shouldHaveSize 031 }32 @Test33 internal fun `Should create a map of all bags`() {34 val bags: Map<Bag, List<BagContentRegulation>> = sut.createMapFromBags()35 val expectedKeys =36 listOf("light red", "dark orange", "bright white", "muted yellow", "shiny gold", "dark olive", "vibrant plum", "faded blue", "dotted black")37 bags.keys.shouldContainExactly(expectedKeys.map { Bag(it, 0) })38 bags[Bag("light red", 0)].shouldContainExactly(regulation(1, "bright white"), regulation(2, "muted yellow"))39 bags[Bag("dark orange", 0)].shouldContainExactly(regulation(3, "bright white"), regulation(4, "muted yellow"))40 bags[Bag("bright white", 0)].shouldContainExactly(regulation(1, "shiny gold"))41 bags[Bag("muted yellow", 0)].shouldContainExactly(regulation(2, "shiny gold"), regulation(9, "faded blue"))42 bags[Bag("shiny gold", 0)].shouldContainExactly(regulation(1, "dark olive"), regulation(2, "vibrant plum"))43 bags[Bag("dark olive", 0)].shouldContainExactly(regulation(3, "faded blue"), regulation(4, "dotted black"))44 bags[Bag("vibrant plum", 0)].shouldContainExactly(regulation(5, "faded blue"), regulation(6, "dotted black"))45 bags[Bag("faded blue", 0)].shouldNotBeNull().shouldBeEmpty()46 bags[Bag("dotted black", 0)].shouldNotBeNull().shouldBeEmpty()47 }48 @Test49 internal fun `Should return 4 bag that can contain the shinny gold`() {50 val bags: Int = sut.retrieveNumberOfBagsThatCanContainColor("shiny gold")51 bags shouldBe 452 }53 private fun regulation(quantity: Int, colorCode: String) = BagContentRegulation(quantity, Bag(colorCode, 0))54}...

Full Screen

Full Screen

ActivityServiceTest.kt

Source:ActivityServiceTest.kt Github

copy

Full Screen

1// SPDX-FileCopyrightText: 2020 Lars Geyer-Blaumeiser <lars@lgblaumeiser.de>2// SPDX-License-Identifier: MIT3package de.lgblaumeiser.ptm.service4import io.kotest.assertions.throwables.shouldThrow5import io.kotest.core.spec.style.WordSpec6import io.kotest.matchers.collections.shouldBeEmpty7import io.kotest.matchers.collections.shouldContainExactly8import io.kotest.matchers.should9import io.kotest.matchers.shouldNot10val testUser1 = "userid1"11val testUser2 = "userid2"12val testProjectname1 = "project1"13val testProjectname2 = "project2"14val testProjectid1 = "0815"15val testProjectid2 = "4711"16val testActivityname1 = "activity1"17val testActivityname2 = "activity2"18val testActivityid1 = "1"19val testActivityid2 = "2"20class ActivityServiceTest : WordSpec ({21 fun initializeService() = ActivityService(ActivityTestStore())22 "getActivities" should {23 "return an empty collection when nothing is stored" {24 val service = initializeService()25 should { service.getActivities("testUser").shouldBeEmpty() }26 }27 }28 "getActivityById" should {29 "return an exception if asked for a id that do not exist" {30 val service = initializeService()31 shouldThrow<NotFoundException> { service.getActivityById("testUser1", 1L) }32 }33 }34 "addActivity" should {35 "added activity can be retrieved again" {36 val service = initializeService()37 val id = service.addActivity(testUser1, testProjectname1, testProjectid1, testActivityname1, testActivityid1)38 should { service.getActivities(testUser1).map { it.id }.shouldContainExactly(id) }39 }40 "added activity not retrieved for different user" {41 val service = initializeService()42 service.addActivity(testUser1, testProjectname1, testProjectid1, testActivityname1, testActivityid1)43 should { service.getActivities(testUser2).shouldBeEmpty() }44 }45 "two added activity with different users should be separated" {46 val service = initializeService()47 val id1 = service.addActivity(testUser1, testProjectname1, testProjectid1, testActivityname1, testActivityid1)48 val id2 = service.addActivity(testUser2, testProjectname2, testProjectid2, testActivityname2, testActivityid2)49 should { service.getActivities(testUser1).map { it.id }.shouldContainExactly(id1) }50 should { service.getActivities(testUser2).map { it.id }.shouldContainExactly(id2) }51 }52 "added activity can be retrieved by id" {53 val service = initializeService()54 val id = service.addActivity(testUser1, testProjectname1, testProjectid1, testActivityname1, testActivityid1)55 should { service.getActivityById(testUser1, id).id == id }56 }57 "added activity creates an exception if called with wrong user" {58 val service = initializeService()59 val id = service.addActivity(testUser1, testProjectname1, testProjectid1, testActivityname1, testActivityid1)60 shouldThrow<UserAccessException> { service.getActivityById(testUser2, id) }61 }62 }63})...

Full Screen

Full Screen

DiscoveryRoundTripTest.kt

Source:DiscoveryRoundTripTest.kt Github

copy

Full Screen

1/*2 * This file is part of bowler-kernel.3 *4 * bowler-kernel is free software: you can redistribute it and/or modify5 * it under the terms of the GNU Lesser General Public License as published by6 * the Free Software Foundation, either version 3 of the License, or7 * (at your option) any later version.8 *9 * bowler-kernel is distributed in the hope that it will be useful,10 * but WITHOUT ANY WARRANTY; without even the implied warranty of11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12 * GNU Lesser General Public License for more details.13 *14 * You should have received a copy of the GNU Lesser General Public License15 * along with bowler-kernel. If not, see <https://www.gnu.org/licenses/>.16 */17package com.commonwealthrobotics.bowlerkernel.kerneldiscovery18import io.kotest.matchers.booleans.shouldBeFalse19import io.kotest.matchers.collections.shouldBeEmpty20import io.kotest.matchers.collections.shouldContainExactly21import io.kotest.matchers.comparables.shouldNotBeEqualComparingTo22import io.kotest.matchers.shouldBe23import io.kotest.matchers.string.shouldStartWith24import org.junit.jupiter.api.Test25internal class DiscoveryRoundTripTest {26 @Test27 fun `scan the local host with no servers running`() {28 NameClient.scan().shouldBeEmpty()29 }30 @Test31 fun `scan the local host with one server running`() {32 val name = "kernel"33 val grpcPort = 5392934 val ns = NameServer(name, getGrpcPort = { grpcPort })35 ns.ensureStarted()36 ns.name.shouldBe(name)37 while (!ns.isRunning.get()) { Thread.sleep(10) }38 val scan = NameClient.scan()39 scan.map { it.first }.shouldContainExactly(name)40 NameClient.getGrpcPort(scan.first().second).shouldBe(grpcPort)41 ns.ensureStopped()42 ns.isRunning.get().shouldBeFalse()43 }44 @Test45 fun `determine unique name`() {46 val name = "kernel"47 val uniqueName = NameServer.determineUniqueName(name, listOf(name))48 uniqueName.shouldStartWith(name)49 uniqueName.shouldNotBeEqualComparingTo(name)50 }51}...

Full Screen

Full Screen

ConfigFileLocatorTest.kt

Source:ConfigFileLocatorTest.kt Github

copy

Full Screen

1package dev.nohus.autokonfig2import dev.nohus.autokonfig.utils.ConfigFileLocator3import io.kotest.core.spec.style.FreeSpec4import io.kotest.matchers.collections.shouldBeEmpty5import io.kotest.matchers.collections.shouldContainExactly6import io.kotest.matchers.shouldBe7/**8 * Created by Marcin Wisniowski (Nohus) on 05/01/2020.9 */10class ConfigFileLocatorTest : FreeSpec({11 val directory = "src/test/resources/test"12 fun createLocator(testDirectory: String): ConfigFileLocator {13 return ConfigFileLocator("$directory/$testDirectory")14 }15 "finds single config file" {16 val locator = createLocator("single")17 locator.getConfigFiles().first().name shouldBe "autokonfig.conf"18 }19 "finds multiple config files" {20 val locator = createLocator("multiple")21 locator.getConfigFiles().map { it.name } shouldContainExactly listOf(22 "application.conf", "application.json", "application.properties",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

ChessTest.kt

Source:ChessTest.kt Github

copy

Full Screen

1package io.kotest.property.arbs.games2import io.kotest.core.spec.style.FunSpec3import io.kotest.matchers.collections.shouldBeEmpty4import io.kotest.matchers.collections.shouldContain5import io.kotest.property.Arb6import io.kotest.property.arbitrary.take7import io.kotest.property.checkAll8class ChessTest : FunSpec() {9 private val squares = ('A'..'H').toList().flatMap { file ->10 (1..8).toList().map { rank ->11 "$file$rank"12 }13 }14 init {15 test("Arb.chessSquare should be in valid range") {16 checkAll(Arb.chessSquare()) { squares.shouldContain(it) }17 }18 test("Arb.chessSquare should cover all rank and files") {19 (squares - Arb.chessSquare().take(10000)).shouldBeEmpty()20 }21 }22}...

Full Screen

Full Screen

File.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1file.shouldBeEmpty()2file.shouldBeExecutable()3file.shouldBeFile()4file.shouldBeHidden()5file.shouldBeReadable()6file.shouldBeRelative()7file.shouldBeSymbolicLink()8file.shouldBeWritable()9file.shouldBeAbsolute()10file.shouldBeDirectory()11file.shouldBeRegularFile()12file.shouldBeSymlink()13file.shouldBeSameBinaryAs(otherFile)14file.shouldBeSameTextAs(otherFile)15file.shouldBeSameJsonAs(otherFile)16file.shouldBeSameYamlAs(otherFile)17file.shouldBeSameXmlAs(otherFile)18file.shouldBeSameTOMLAs(otherFile)

Full Screen

Full Screen

File.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1File("filename").shouldBeEmpty()2File("filename").shouldBeExecutable()3File("filename").shouldBeHidden()4File("filename").shouldBeReadable()5File("filename").shouldBeRelative()6File("filename").shouldBeSymbolicLink()7File("filename").shouldBeWritable()8File("filename").shouldContainDirectory("directory")9File("filename").shouldContainFile("file")10File("filename").shouldContainMatchingFiles("pattern")11File("filename").shouldHaveChildren("children")12File("filename").shouldHaveDirectory("directory")13File("filename").shouldHaveExtension("extension")14File("filename").shouldHaveFile("file")15File("filename").shouldHaveName("name")16File("filename").shouldHaveParent("parent")17File("filename").shouldHavePath("path")

Full Screen

Full Screen

File.shouldBeEmpty

Using AI Code Generation

copy

Full Screen

1File( "path/to/file" ).shouldBeEmpty()2File( "path/to/file" ).shouldBeExecutable()3File( "path/to/file" ).shouldBeHidden()4File( "path/to/file" ).shouldBeReadable()5File( "path/to/file" ).shouldBeRelative()6File( "path/to/file" ).shouldBeRelativeNormalized()7File( "path/to/file" ).shouldBeRelativeRaw()8File( "path/to/file" ).shouldBeSymbolicLink()9File( "path/to/file" ).shouldBeWritable()10File( "path/to/file" ).shouldContain( "content to be searched" )11File( "path/to/file" ).shouldEndWith( "content to be searched" )12File( "path/to/file" ).shouldExist()13File( "path/to/file" ).shouldHaveExtension( "extension" )14File( "path/to/file" ).shouldHaveName( "name" )15File( "path/to/file" ).shouldHaveParent( "path/to/parent" )

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