From ad7ecf33323c2aaf58abe830c2ddd1ced40d3f18 Mon Sep 17 00:00:00 2001 From: "marcin.mielnicki" Date: Tue, 14 Nov 2023 19:10:58 +0100 Subject: [PATCH] Simplify tests in part 1.1 --- part1.1-shared-state/README.md | 8 ++----- .../SharedStateExampleTest.groovy | 23 ++++++++----------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/part1.1-shared-state/README.md b/part1.1-shared-state/README.md index 6a5aa8b..a20ef54 100644 --- a/part1.1-shared-state/README.md +++ b/part1.1-shared-state/README.md @@ -115,8 +115,7 @@ Some tests failed. Eliminate shared state by using different `name` in test case Sample output: ```text -name = testName 3 readable: false -name = testName 3 readable: true +name = testName 3 name = testName 1 name = testName 2 ``` @@ -136,7 +135,6 @@ Sample output: name = BM8LX name = Kbc28 name = boR1b -name = 7Oc3i ``` ### Approach no. 3 @@ -153,7 +151,6 @@ Sample output: name = 3 name = 1 name = 2 -name = 4 ``` ### Approach no. 4 @@ -167,8 +164,7 @@ name = 4 Sample output: ```text -name = pl.allegro.tech.workshops.testsparallelexecution:SharedStateExampleTest:should create readable - non-readable file [readable: true, #0] -name = pl.allegro.tech.workshops.testsparallelexecution:SharedStateExampleTest:should create readable - non-readable file [readable: false, #1] +name = pl.allegro.tech.workshops.testsparallelexecution:SharedStateExampleTest:should remove file name = pl.allegro.tech.workshops.testsparallelexecution:SharedStateExampleTest:should create dir name = pl.allegro.tech.workshops.testsparallelexecution:SharedStateExampleTest:should create file ``` diff --git a/part1.1-shared-state/src/test/groovy/pl/allegro/tech/workshops/testsparallelexecution/SharedStateExampleTest.groovy b/part1.1-shared-state/src/test/groovy/pl/allegro/tech/workshops/testsparallelexecution/SharedStateExampleTest.groovy index 06b9218..cb5f5a4 100644 --- a/part1.1-shared-state/src/test/groovy/pl/allegro/tech/workshops/testsparallelexecution/SharedStateExampleTest.groovy +++ b/part1.1-shared-state/src/test/groovy/pl/allegro/tech/workshops/testsparallelexecution/SharedStateExampleTest.groovy @@ -27,10 +27,10 @@ class SharedStateExampleTest extends Specification { println "name = $name" when: - def fileCreated = file.createNewFile() + def fileWasCreated = file.createNewFile() then: - fileCreated + fileWasCreated file.exists() } @@ -41,31 +41,26 @@ class SharedStateExampleTest extends Specification { println "name = $name" when: - def fileCreated = file.mkdir() + def directoryWasCreated = file.mkdir() then: - fileCreated + directoryWasCreated file.exists() } - def "should create readable or non-readable file"() { + def "should remove file"() { given: name = "testName" file = new File(tempDir, name) - file.setReadable(readable) + assert file.createNewFile() println "name = $name" when: - def fileCreated = file.createNewFile() + def fileWasDeleted = file.delete() then: - fileCreated - file.exists() - - where: - readable | _ - true | _ - false | _ + fileWasDeleted + !file.exists() } }