Best Kotest code snippet using io.kotest.matchers.file.matchers.aFile
FileMatchersTest.kt
Source:FileMatchersTest.kt
1package com.sksamuel.kotest.matchers.file2import io.kotest.assertions.throwables.shouldThrow3import io.kotest.core.spec.style.FunSpec4import io.kotest.matchers.file.aDirectory5import io.kotest.matchers.file.aFile6import io.kotest.matchers.file.beAbsolute7import io.kotest.matchers.file.beRelative8import io.kotest.matchers.file.exist9import io.kotest.matchers.file.haveExtension10import io.kotest.matchers.file.shouldBeADirectory11import io.kotest.matchers.file.shouldBeAFile12import io.kotest.matchers.file.shouldBeAbsolute13import io.kotest.matchers.file.shouldBeEmptyDirectory14import io.kotest.matchers.file.shouldBeRelative15import io.kotest.matchers.file.shouldBeSymbolicLink16import io.kotest.matchers.file.shouldExist17import io.kotest.matchers.file.shouldHaveExtension18import io.kotest.matchers.file.shouldHaveParent19import io.kotest.matchers.file.shouldHaveSameStructureAs20import io.kotest.matchers.file.shouldHaveSameStructureAndContentAs21import io.kotest.matchers.file.shouldNotBeADirectory22import io.kotest.matchers.file.shouldNotBeAFile23import io.kotest.matchers.file.shouldNotBeEmptyDirectory24import io.kotest.matchers.file.shouldNotBeSymbolicLink25import io.kotest.matchers.file.shouldNotExist26import io.kotest.matchers.file.shouldNotHaveExtension27import io.kotest.matchers.file.shouldNotHaveParent28import io.kotest.matchers.file.shouldStartWithPath29import io.kotest.matchers.file.startWithPath30import io.kotest.matchers.paths.shouldBeLarger31import io.kotest.matchers.paths.shouldBeSmaller32import io.kotest.matchers.paths.shouldBeSymbolicLink33import io.kotest.matchers.paths.shouldContainFile34import io.kotest.matchers.paths.shouldContainFileDeep35import io.kotest.matchers.paths.shouldContainFiles36import io.kotest.matchers.paths.shouldHaveParent37import io.kotest.matchers.paths.shouldNotBeSymbolicLink38import io.kotest.matchers.paths.shouldNotContainFile39import io.kotest.matchers.paths.shouldNotContainFileDeep40import io.kotest.matchers.paths.shouldNotContainFiles41import io.kotest.matchers.paths.shouldNotHaveParent42import io.kotest.matchers.should43import io.kotest.matchers.shouldBe44import io.kotest.matchers.shouldNot45import io.kotest.matchers.string.shouldEndWith46import io.kotest.matchers.string.shouldMatch47import java.io.File48import java.nio.file.Files49import java.nio.file.Paths50import org.apache.commons.lang3.SystemUtils.IS_OS_WINDOWS51@Suppress("BlockingMethodInNonBlockingContext")52class FileMatchersTest : FunSpec() {53 init {54 test("relative() should match only relative files") {55 File("sammy/boy") shouldBe beRelative()56 File("sammy/boy").shouldBeRelative()57 }58 test("absolute() should match only absolute files") {59 val root = if (IS_OS_WINDOWS) "C:/" else "/"60 File("${root}sammy/boy") shouldBe beAbsolute()61 File("${root}sammy/boy").shouldBeAbsolute()62 }63 test("startWithPath() should only match files that start with the given path") {64 File("sammy/boy") should startWithPath("sammy")65 File("sammy/boy") should startWithPath(Paths.get("sammy"))66 File("/sammy/boy") should startWithPath("${File.separator}sammy")67 File("/sammy/boy") should startWithPath(Paths.get("/sammy"))68 File("/sammy/boy").shouldStartWithPath("${File.separator}sammy")69 File("/sammy/boy").shouldStartWithPath(Paths.get("/sammy"))70 }71 test("exist() file matcher") {72 val file = Files.createTempFile("test", "test").toFile()73 file should exist()74 shouldThrow<AssertionError> {75 File("qweqwewqewqewee") should exist()76 }.message shouldBe "File qweqwewqewqewee should exist"77 file.shouldExist()78 shouldThrow<AssertionError> {79 file.shouldNotExist()80 }81 file.delete()82 }83 test("haveExtension") {84 val file = Files.createTempFile("test", ".test").toFile()85 file should haveExtension(".test")86 file shouldNot haveExtension(".wibble")87 shouldThrow<AssertionError> {88 file should haveExtension(".jpeg")89 }.message.shouldEndWith("with one of .jpeg")90 shouldThrow<AssertionError> {91 file.shouldHaveExtension(".jpeg")92 }.message.shouldEndWith("with one of .jpeg")93 file.shouldHaveExtension(".test")94 file.shouldNotHaveExtension(".wibble")95 file.delete()96 }97 test("aFile() file matcher") {98 val file = Files.createTempFile("test", "test").toFile()99 file shouldBe aFile()100 file.shouldBeAFile()101 shouldThrow<AssertionError> {102 file shouldBe aDirectory()103 }104 shouldThrow<AssertionError> {105 file.shouldNotBeAFile()106 }107 shouldThrow<AssertionError> {108 file.shouldBeADirectory()109 }110 file.delete()111 }112 test("aDirectory() file matcher") {113 val dir = Files.createTempDirectory("testdir").toFile()114 dir shouldBe aDirectory()115 dir.shouldBeADirectory()116 shouldThrow<AssertionError> {117 dir shouldBe aFile()118 }119 shouldThrow<AssertionError> {120 dir.shouldNotBeADirectory()121 }122 shouldThrow<AssertionError> {123 dir shouldBe aFile()124 }125 }126 test("directory should be empty (deprecated)") {127 val dir = Files.createTempDirectory("testdir").toFile()128 dir.shouldBeEmptyDirectory()129 dir.resolve("testfile.txt").writeBytes(byteArrayOf(1, 2, 3))130 dir.shouldNotBeEmptyDirectory()131 }132 test("directory should be empty") {133 val dir = Files.createTempDirectory("testdir").toFile()134 dir.shouldBeEmptyDirectory()135 dir.resolve("testfile.txt").writeBytes(byteArrayOf(1, 2, 3))136 dir.shouldNotBeEmptyDirectory()137 }...
AttachmentServiceTest.kt
Source:AttachmentServiceTest.kt
1package com.github.njuro.jard.attachment2import com.github.njuro.jard.TEST_ATTACHMENT_AVI3import com.github.njuro.jard.TEST_ATTACHMENT_DOCX4import com.github.njuro.jard.TEST_ATTACHMENT_PNG5import com.github.njuro.jard.TEST_FOLDER_NAME6import com.github.njuro.jard.TestDataRepository7import com.github.njuro.jard.WithContainerDatabase8import com.github.njuro.jard.attachment9import com.github.njuro.jard.attachment.storage.RemoteStorageService10import com.github.njuro.jard.attachmentPath11import com.github.njuro.jard.common.Constants.DEFAULT_THUMBNAIL_EXTENSION12import com.github.njuro.jard.common.Constants.THUMBNAIL_FOLDER_NAME13import com.github.njuro.jard.embedData14import com.github.njuro.jard.metadata15import com.github.njuro.jard.multipartFile16import com.ninjasquad.springmockk.MockkBean17import io.kotest.matchers.booleans.shouldBeTrue18import io.kotest.matchers.file.shouldBeAFile19import io.kotest.matchers.file.shouldBeReadable20import io.kotest.matchers.file.shouldExist21import io.kotest.matchers.file.shouldHaveExtension22import io.kotest.matchers.file.shouldHaveNameWithoutExtension23import io.kotest.matchers.file.shouldNotBeEmpty24import io.kotest.matchers.file.shouldNotExist25import io.kotest.matchers.nulls.shouldBeNull26import io.kotest.matchers.nulls.shouldNotBeNull27import io.kotest.matchers.optional.shouldNotBePresent28import io.kotest.matchers.should29import io.kotest.matchers.shouldBe30import io.kotest.matchers.string.shouldNotBeBlank31import io.mockk.Runs32import io.mockk.every33import io.mockk.just34import org.junit.jupiter.api.AfterEach35import org.junit.jupiter.api.BeforeEach36import org.junit.jupiter.api.DisplayName37import org.junit.jupiter.api.Nested38import org.junit.jupiter.api.Test39import org.springframework.beans.factory.annotation.Autowired40import org.springframework.boot.test.context.SpringBootTest41import org.springframework.transaction.annotation.Transactional42import java.io.File43@SpringBootTest44@WithContainerDatabase45@Transactional46internal class AttachmentServiceTest {47 @Autowired48 private lateinit var attachmentService: AttachmentService49 @MockkBean50 private lateinit var remoteStorageService: RemoteStorageService51 @Autowired52 private lateinit var db: TestDataRepository53 @BeforeEach54 @AfterEach55 fun `delete test folder`() {56 val testFolder = attachmentPath(TEST_FOLDER_NAME).toFile()57 if (testFolder.exists()) {58 testFolder.deleteRecursively().shouldBeTrue()59 }60 }61 @Nested62 @DisplayName("save attachment")63 inner class SaveAttachment {64 private fun getRemoteUrl(folder: String, filename: String) = "https://remote-storage.com/$folder-$filename"65 @BeforeEach66 fun setUpMocks() {67 every {68 remoteStorageService.uploadFile(69 ofType(String::class),70 ofType(String::class),71 ofType(File::class)72 )73 } answers { getRemoteUrl(firstArg(), secondArg()) }74 }75 @Test76 fun `save image attachment with thumbnail`() {77 val file = multipartFile("attachment.png", TEST_ATTACHMENT_PNG)78 val attachment =79 attachment(80 category = AttachmentCategory.IMAGE,81 filename = file.name,82 folder = TEST_FOLDER_NAME,83 metadata = metadata(mimeType = "image/png")84 )85 attachmentService.saveAttachment(attachment, file).should {86 it.metadata.shouldNotBeNull()87 it.remoteStorageUrl shouldBe getRemoteUrl(attachment.folder, attachment.filename)88 it.file.shouldMatchFile("attachment", "png")89 it.remoteStorageThumbnailUrl shouldBe getRemoteUrl(90 "$TEST_FOLDER_NAME/$THUMBNAIL_FOLDER_NAME",91 attachment.filename92 )93 it.thumbnailFile.shouldMatchFile("attachment", "png")94 }95 }96 @Test97 fun `save non-image attachment with thumbnail`() {98 val file = multipartFile("attachment.avi", TEST_ATTACHMENT_AVI)99 val attachment =100 attachment(101 category = AttachmentCategory.VIDEO,102 filename = file.name,103 folder = TEST_FOLDER_NAME,104 metadata = metadata(mimeType = "video/avi")105 )106 attachmentService.saveAttachment(attachment, file).should {107 it.remoteStorageUrl.shouldNotBeBlank()108 it.file.shouldMatchFile("attachment", "avi")109 it.thumbnailFile.shouldMatchFile("attachment", DEFAULT_THUMBNAIL_EXTENSION)110 it.remoteStorageThumbnailUrl.shouldNotBeBlank()111 }112 }113 @Test114 fun `save non-image attachment without thumbnail`() {115 val file = multipartFile("attachment.docx", TEST_ATTACHMENT_DOCX)116 val attachment =117 attachment(118 category = AttachmentCategory.TEXT,119 filename = file.name,120 folder = TEST_FOLDER_NAME,121 metadata = metadata(mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document")122 )123 attachmentService.saveAttachment(attachment, file).should {124 it.file.shouldMatchFile("attachment", "docx")125 it.remoteStorageUrl.shouldNotBeBlank()126 it.thumbnailFile.shouldBeNull()127 it.remoteStorageThumbnailUrl.shouldBeNull()128 }129 }130 @Test131 fun `save embedded attachment`() {132 val attachment =133 attachment(category = AttachmentCategory.EMBED, embedData = embedData(embedUrl = "some-url"))134 attachmentService.saveEmbeddedAttachment(attachment).shouldNotBeNull()135 }136 }137 @Test138 fun `delete attachment`() {139 every { remoteStorageService.uploadFile(any(), any(), any()) } returns null140 every { remoteStorageService.deleteFile(ofType(String::class), ofType(String::class)) } just Runs141 val file = multipartFile("attachment.png", TEST_ATTACHMENT_PNG)142 val attachment =143 attachment(144 category = AttachmentCategory.IMAGE,145 filename = file.name,146 folder = TEST_FOLDER_NAME,147 metadata = metadata(mimeType = "image/png")148 )149 val saved = attachmentService.saveAttachment(attachment, file)150 attachmentService.deleteAttachment(saved)151 db.select(saved).shouldNotBePresent()152 attachment.file.shouldNotExist()153 attachment.thumbnailFile.shouldNotExist()154 }155 private fun File.shouldMatchFile(name: String, extension: String) = should {156 it.shouldExist()157 it.shouldBeAFile()158 it.shouldHaveNameWithoutExtension(name)159 it.shouldHaveExtension(extension)160 it.shouldBeReadable()161 it.shouldNotBeEmpty()162 }163}...
specs.kt
Source:specs.kt
...20import io.kotest.core.spec.style.WordSpec21import io.kotest.core.test.TestStatus22import io.kotest.core.test.TestType23import io.kotest.matchers.and24import io.kotest.matchers.paths.aFile25import io.kotest.matchers.paths.beReadable26import io.kotest.matchers.paths.exist27import io.kotest.matchers.should28import org.gradle.testkit.runner.BuildResult29import org.gradle.testkit.runner.GradleRunner30import java.io.File31import java.nio.charset.Charset32abstract class FunctionalSpec(private val suffix: String = "gradle") : WordSpec() {33 lateinit var testProjectDir: File34 lateinit var testkitDir: File35 lateinit var propertiesFile: File36 lateinit var settingsFile: File37 lateinit var buildFile: File38 init {39 beforeTest {40 if (it.type !== TestType.Test) {41 return@beforeTest42 }43 // create temporary project root and gradle files44 testProjectDir = createTempDir("test-", "", File("build", "tmp"))45 testkitDir = createTempDir("testkit-", "", testProjectDir)46 settingsFile = testProjectDir.resolve("settings.${suffix}").apply {47 writeText("rootProject.name = \"${testProjectDir.name}\"\n")48 }49 buildFile = testProjectDir.resolve("build.${suffix}").apply {50 writeText("// Running test for ${testProjectDir.name}\n\n")51 }52 propertiesFile = testProjectDir.resolve("gradle.properties").apply {53 // issue #52: apply jacoco54 val testkitProps = this@FunctionalSpec.javaClass.classLoader.getResource("testkit-gradle.properties")55 writeText(testkitProps!!.readText())56 appendText("\n")57 }58 // copy example entities for test59 val mainJavaDir = testProjectDir.resolve("src/main/java").apply {60 mkdirs()61 }62 val resourceJavaDir = File("src/functionalTest/resources/java")63 resourceJavaDir.copyRecursively(mainJavaDir, true)64 }65 afterTest {66 if (it.a.type === TestType.Test) {67 if (it.b.status === TestStatus.Success || it.b.status === TestStatus.Ignored) {68 testProjectDir.deleteRecursively()69 }70 }71 }72 }73 fun runTask(vararg args: String): BuildResult =74 GradleRunner.create()75 .withPluginClasspath()76 .withProjectDir(testProjectDir)77 .withArguments(*args).build()78 fun runGenerateSchemaTask() = runTask("generateSchema", "--info", "--stacktrace")79 fun resultFile(path: String): File = testProjectDir.toPath().resolve(path).apply {80 this should (exist() and aFile() and beReadable())81 }.toFile()82 fun resultFileText(path: String, charset: Charset = Charsets.UTF_8) = resultFile(path).readText(charset)83}84abstract class GroovyFunctionalSpec : FunctionalSpec()85abstract class KotlinFunctionalSpec : FunctionalSpec("gradle.kts")...
Tests.kt
Source:Tests.kt
1package org.enrignagna.template.test2import com.uchuhimo.konf.Config3import com.uchuhimo.konf.source.yaml4import io.github.classgraph.ClassGraph5import io.kotest.core.spec.style.StringSpec6import io.kotest.matchers.file.shouldBeAFile7import io.kotest.matchers.file.shouldExist8import io.kotest.matchers.shouldBe9import io.kotest.matchers.string.shouldContain10import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder11import org.gradle.testkit.runner.BuildResult12import org.gradle.testkit.runner.GradleRunner13import org.gradle.testkit.runner.TaskOutcome14import org.slf4j.LoggerFactory15import java.io.File16class Tests : StringSpec(17 {18 val pluginClasspathResource = ClassLoader.getSystemClassLoader()19 .getResource("plugin-classpath.txt")20 ?: throw IllegalStateException("Did not find plugin classpath resource, run \"testClasses\" build task.")21 val classpath = pluginClasspathResource.openStream().bufferedReader().use { reader ->22 reader.readLines().map { File(it) }23 }24 val scan = ClassGraph()25 .enableAllInfo()26 .acceptPackages(Tests::class.java.`package`.name)27 .scan()28 scan.getResourcesWithLeafName("test.yaml")29 .flatMap {30 log.debug("Found test list in $it")31 val yamlFile = File(it.classpathElementFile.absolutePath + "/" + it.path)32 val testConfiguration = Config {33 addSpec(Root)34 }.from.yaml.inputStream(it.open())35 testConfiguration[Root.tests].map { it to yamlFile.parentFile }36 }37 .forEach { (test, location) ->38 log.debug("Test to be executed: $test from $location")39 val testFolder = folder {40 location.copyRecursively(this.root)41 }42 log.debug("Test has been copied into $testFolder and is ready to get executed")43 test.description {44 val result = GradleRunner.create()45 .withProjectDir(testFolder.root)46 .withPluginClasspath(classpath)47 .withArguments(test.configuration.tasks + test.configuration.options)48 .build()49 println(result.tasks)50 println(result.output)51 test.expectation.output_contains.forEach {52 result.output shouldContain it53 }54 test.expectation.success.forEach {55 result.outcomeOf(it) shouldBe TaskOutcome.SUCCESS56 }57 test.expectation.failure.forEach {58 result.outcomeOf(it) shouldBe TaskOutcome.FAILED59 }60 test.expectation.file_exists.forEach {61 with(File("${testFolder.root.absolutePath}/$it")) {62 shouldExist()63 shouldBeAFile()64 }65 }66 }67 }68 }69) {70 companion object {71 val log = LoggerFactory.getLogger(Tests::class.java)72 private fun BuildResult.outcomeOf(name: String) = task(":$name")73 ?.outcome74 ?: throw IllegalStateException("Task $name was not present among the executed tasks")75 private fun folder(closure: TemporaryFolder.() -> Unit) = TemporaryFolder().apply {76 create()77 closure()78 }79 }80}...
PublishToMavenCentralTest.kt
Source:PublishToMavenCentralTest.kt
1package it.nicolasfarabegoli.gradle.central2import io.kotest.core.spec.style.WordSpec3import io.kotest.matchers.file.shouldBeAFile4import io.kotest.matchers.file.shouldExist5import io.kotest.matchers.shouldBe6import io.kotest.matchers.string.shouldContain7import org.gradle.testkit.runner.GradleRunner8import org.gradle.testkit.runner.TaskOutcome9import java.io.File10class PublishToMavenCentralTest : WordSpec({11 val projectDir = File("build/gradleTest")12 fun setupTest() {13 projectDir.mkdirs()14 projectDir.resolve("settings.gradle.kts").writeText("")15 projectDir.resolve("build.gradle.kts").writeText(16 """17 plugins {18 `java-library`19 `java-gradle-plugin`20 id("it.nicolasfarabegoli.publish-to-maven-central")21 }22 23 publishOnMavenCentral {24 projectDescription.set("foo bar")25 repository("https://maven.pkg.github.com/foo/bar", "github") {26 username.set("foo")27 password.set("bar")28 }29 }30 """.trimIndent()31 )32 }33 val taskName = "generatePomFileForJavaMavenPublication"34 "The plugin" should {35 "create the correct tasks" {36 setupTest()37 val tasks = GradleRunner.create()38 .forwardOutput()39 .withPluginClasspath()40 .withProjectDir(projectDir)41 .withArguments("tasks")42 .build()43 tasks.output shouldContain "publishJavaMavenPublication"44 tasks.output shouldContain "publishPluginMavenPublicationToMavenCentralRepository"45 tasks.output shouldContain "publishJavaMavenPublicationToGithubRepository"46 tasks.output shouldContain "releaseJavaMavenOnMavenCentralNexus"47 tasks.output shouldContain "publishPluginMavenPublicationToGithubRepository"48 tasks.output shouldContain "releasePlugin"49 }50 "generate the pom correctly" {51 setupTest()52 val result = GradleRunner.create()53 .forwardOutput()54 .withPluginClasspath()55 .withArguments(taskName, "sourcesJar", "javadocJar", "--stacktrace")56 .withProjectDir(projectDir)57 .build()58 result.task(":$taskName")?.outcome shouldBe TaskOutcome.SUCCESS59 with(File("$projectDir/build/publications/javaMaven/pom-default.xml")) {60 shouldExist()61 shouldBeAFile()62 val content = readText(Charsets.UTF_8)63 content shouldContain "artifactId"64 content shouldContain "groupId"65 content shouldContain "name"66 content shouldContain "url"67 content shouldContain "license"68 }69 }70 }71})...
CycloneDxReporterFunTest.kt
Source:CycloneDxReporterFunTest.kt
...20 */21package org.ossreviewtoolkit.reporter.reporters22import io.kotest.core.spec.style.WordSpec23import io.kotest.matchers.collections.beEmpty24import io.kotest.matchers.file.aFile25import io.kotest.matchers.file.emptyFile26import io.kotest.matchers.should27import io.kotest.matchers.shouldBe28import io.kotest.matchers.shouldNotBe29import org.cyclonedx.parsers.JsonParser30import org.cyclonedx.parsers.XmlParser31import org.ossreviewtoolkit.reporter.ORT_RESULT32import org.ossreviewtoolkit.reporter.ReporterInput33import org.ossreviewtoolkit.utils.test.createSpecTempDir34class CycloneDxReporterFunTest : WordSpec({35 val defaultSchemaVersion = CycloneDxReporter.DEFAULT_SCHEMA_VERSION.versionString36 val options = mapOf("single.bom" to "true")37 val outputDir = createSpecTempDir()38 "A generated BOM" should {39 "be valid XML according to schema version $defaultSchemaVersion" {40 val xmlOptions = options + mapOf("output.file.formats" to "xml")41 val bomFile = CycloneDxReporter().generateReport(ReporterInput(ORT_RESULT), outputDir, xmlOptions).single()42 bomFile shouldBe aFile()43 bomFile shouldNotBe emptyFile()44 XmlParser().validate(bomFile, CycloneDxReporter.DEFAULT_SCHEMA_VERSION) should beEmpty()45 }46 "be valid JSON according to schema version $defaultSchemaVersion" {47 val jsonOptions = options + mapOf("output.file.formats" to "json")48 val bomFile = CycloneDxReporter().generateReport(ReporterInput(ORT_RESULT), outputDir, jsonOptions).single()49 bomFile shouldBe aFile()50 bomFile shouldNotBe emptyFile()51 JsonParser().validate(bomFile, CycloneDxReporter.DEFAULT_SCHEMA_VERSION) should beEmpty()52 }53 }54})...
FormatFileTest.kt
Source:FormatFileTest.kt
...4import io.kotest.core.spec.tempfile5import io.kotest.matchers.and6import 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))...
TestEffectLoading.kt
Source:TestEffectLoading.kt
1/*2 * Copyright (C) 2010-2022, Danilo Pianini and contributors3 * listed, for each module, in the respective subproject's build.gradle.kts file.4 *5 * This file is part of Alchemist, and is distributed under the terms of the6 * GNU General Public License, with a linking exception,7 * as described in the file LICENSE in the Alchemist distribution's top directory.8 */9@file:Suppress("DEPRECATION")10package it.unibo.alchemist.test11import io.kotest.core.spec.style.StringSpec12import io.kotest.engine.spec.tempfile13import io.kotest.matchers.file.shouldBeAFile14import io.kotest.matchers.file.shouldExist15import io.kotest.matchers.file.shouldNotBeEmpty16import io.kotest.matchers.nulls.beNull17import io.kotest.matchers.nulls.shouldNotBeNull18import io.kotest.matchers.shouldBe19import io.kotest.matchers.shouldNot20import it.unibo.alchemist.boundary.gui.effects.DrawBidimensionalGaussianLayersGradient21import it.unibo.alchemist.boundary.gui.effects.EffectSerializationFactory22import org.kaikikm.threadresloader.ResourceLoader23import java.io.File24class TestEffectLoading : StringSpec(25 {26 "effects with layers should be (de)serializable" {27 val target = DrawBidimensionalGaussianLayersGradient()28 val tempFile = tempfile()29 EffectSerializationFactory.effectToFile(tempFile, target)30 println(tempFile.readText())31 tempFile.shouldExist()32 tempFile.shouldBeAFile()33 tempFile.shouldNotBeEmpty()34 EffectSerializationFactory.effectsFromFile(tempFile).shouldNotBeNull()35 }36 "legacy effects with layers should be deserializable" {37 val target = ResourceLoader.getResource("layer.json")38 target shouldNot beNull()39 val file = File(target.file)40 file.shouldExist()41 file.shouldNotBeEmpty()42 file.shouldBeAFile()43 val effects = EffectSerializationFactory.effectsFromFile(file)44 effects.shouldNotBeNull()45 effects.size shouldBe 446 }47 }48)...
aFile
Using AI Code Generation
1val file = File("test.txt")2val dir = File("test")3val rfile = File("test.txt")4val rdir = File("test")5val wfile = File("test.txt")6val wdir = File("test")7val hfile = File("test.txt")8val hdir = File("test")9val slink = File("test.txt")10val efile = File("test.txt")11val edir = File("test")12val rfile = File("test.txt")13val rdir = File("test")14val dir = File("test")15val file = File("test.txt")16dir should be aDirectoryContaining(file)
aFile
Using AI Code Generation
1val file = File("test.txt")2val dir = File("testDir")3val symlink = File("testSymlink")4val existingFile = File("test.txt")5val existingDir = File("testDir")6val existingSymlink = File("testSymlink")7val emptyFile = File("test.txt")8val emptyDir = File("testDir")9val emptySymlink = File("testSymlink")10val readableFile = File("test.txt")11val readableDir = File("testDir")12val readableSymlink = File("testSymlink")13val writableFile = File("test.txt")
aFile
Using AI Code Generation
1aFile("/tmp/test.txt").shouldHaveContent("Hello World")2aFile("/tmp/test.txt").shouldHaveContent("Hello World")3aFile("/tmp/test.txt").shouldHaveContent("Hello World")4aFile("/tmp/test.txt").shouldHaveContent("Hello World")5aFile("/tmp/test.txt").shouldHaveContent("Hello World")6aFile("/tmp/test.txt").shouldHaveContent("Hello World")7aFile("/tmp/test.txt").shouldHaveContent("Hello World")8aFile("/tmp/test.txt").shouldHaveContent("Hello World")9aFile("/tmp/test.txt").shouldHaveContent("Hello World")10aFile("/tmp/test.txt").shouldHaveContent("Hello World")11aFile("/tmp/test.txt").shouldHaveContent("Hello World")12aFile("/tmp/test.txt").shouldHaveContent("Hello World")13aFile("/tmp/test.txt").shouldHaveContent("Hello World")14aFile("/tmp/test.txt").shouldHaveContent("Hello World")15aFile("/tmp/test.txt").shouldHaveContent("Hello World")16aFile("/
aFile
Using AI Code Generation
1aFile should haveContent("hello")2aFile should not haveContent("hello")3aFile should haveContent("hello")4aFile should not haveContent("hello")5aFile should haveContent("hello")6aFile should not haveContent("hello")7aFile should haveContent("hello")8aFile should not haveContent("hello")9aFile should haveContent("hello")10aFile should not haveContent("hello")11aFile should haveContent("hello")12aFile should not haveContent("hello")13aFile should haveContent("hello")14aFile should not haveContent("hello")15aFile should haveContent("hello")16aFile should not haveContent("hello")17aFile should haveContent("hello")18aFile should not haveContent("hello")19aFile should haveContent("hello")20aFile should not haveContent("hello")21aFile should haveContent("hello")22aFile should not haveContent("hello")23aFile should haveContent("hello")24aFile should not haveContent("hello")25aFile should haveContent("hello")26aFile should not haveContent("hello")27aFile should haveContent("hello")28aFile should not haveContent("hello")
aFile
Using AI Code Generation
1aFile should haveExtension(".txt")2aFile should haveName("test.txt")3aFile should haveParent("test")4aFile should havePath("/home/test/test.txt")5aFile should haveSize(100)6aFile should haveNameStartingWith("test")7aFile should haveNameEndingWith(".txt")8aFile should haveNameContaining("es.t")9aFile should haveNameMatching(Regex(".*"))10aFile should haveNoExtension()11aFile should haveNoName()12aFile should haveNoParent()13aFile should haveNoPath()14aFile should haveNoSize()15aFile should haveNoNameStartingWith()16aFile should haveNoNameEndingWith()17aFile should haveNoNameContaining()18aFile should haveNoNameMatching()19aFile should haveContent("Hello World")20aFile should haveContentStartingWith("Hello")21aFile should haveContentEndingWith("World")22aFile should haveContentContaining("or")23aFile should haveContentMatching(Regex(".*"))24aFile should haveNoContent()25aFile should haveNoContentStartingWith()26aFile should haveNoContentEndingWith()27aFile should haveNoContentContaining()28aFile should haveNoContentMatching()29aFile should haveContentBytes(byteArrayOf(0x00, 0x01))30aFile should haveNoContentBytes()31aFile should haveContentLines(listOf("Hello", "World"))32aFile should haveNoContentLines()33aFile should haveContentLinesStartingWith(listOf("Hello"))34aFile should haveContentLinesEndingWith(listOf("World"))35aFile should haveContentLinesContaining(listOf("or"))36aFile should haveContentLinesMatching(listOf(Regex(".*")))37aFile should haveNoContentLinesStartingWith()38aFile should haveNoContentLinesEndingWith()39aFile should haveNoContentLinesContaining()40aFile should haveNoContentLinesMatching()41aFile should haveContentLines(listOf("Hello", "World"))42aFile should haveNoContentLines()43aFile should haveContentLinesStartingWith(listOf("Hello"))44aFile should haveContentLinesEndingWith(listOf("World"))45aFile should haveContentLinesContaining(listOf("or"))46aFile should haveContentLinesMatching(listOf(Regex(".*")))47aFile should haveNoContentLinesStartingWith()48aFile should haveNoContentLinesEndingWith()49aFile should haveNoContentLinesContaining()50aFile should haveNoContentLinesMatching()
aFile
Using AI Code Generation
1val file = File ( "src/test/resources/file.txt" ) 2 file . shouldNotBeEmpty ( ) 3 file . shouldHaveExtension ( "txt" ) 4 file . shouldHaveName ( "file.txt" ) 5 file . shouldHaveParent ( "resources" ) 6 file . shouldHavePath ( "src/test/resources/file.txt" ) 7 file . shouldHaveSize ( 4 ) 8 file . shouldHaveText ( "test" ) 9 file . shouldNotHaveExtension ( "txt" ) 10 file . shouldNotHaveName ( "file.txt" ) 11 file . shouldNotHaveParent ( "resources" ) 12 file . shouldNotHavePath ( "src/test/resources/file.txt" ) 13 file . shouldNotHaveSize ( 4 ) 14 file . shouldNotHaveText ( "test" ) 15 file . shouldNotBeRelative ( ) 16 file . shouldNotBeAbsolute ( ) 17 file . shouldNotBeHidden ( ) 18 file . shouldNotBeSymbolicLink ( ) 19 file . shouldNotBeDirectory ( ) 20 file . shouldNotBeFile ( ) 21 file . shouldNotBeExecutable ( ) 22 file . shouldNotBeReadable ( ) 23 file . shouldNotBeWritable ( ) 24 file . shouldHaveBinaryContent ( byteArrayOf ( 0x00 , 0x01 , 0x02 , 0x03 ) ) 25 file . shouldNotHaveBinaryContent ( byteArrayOf ( 0x00 , 0x01 , 0x02 , 0x03 ) ) 26 file . shouldHaveSameBinaryContentAs ( File ( "src/test/resources/file.txt" ) ) 27 file . shouldHaveSameTextualContentAs ( File ( "src/test/resources/file.txt" ) ) 28 file . shouldHaveSameLinesAs ( File ( "src/test/resources/file.txt" ) ) 29 file . shouldHaveSameLinesAs ( "test" ) 30 file . shouldHaveSameTextualContentAs ( "test" ) 31 file . shouldHaveSameBinaryContentAs ( byteArrayOf ( 0x00 , 0x01 , 0x02 , 0x03 ) ) 32 file . shouldHaveSameTextualContentAs ( byteArrayOf ( 0x00 , 0x01 , 0x02 , 0x03 ) ) 33 file . shouldHaveSameLinesAs ( byteArrayOf ( 0x00 , 0
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!