From e2c6f84d8df529d5e689bd818c4dcca812c7bbb5 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sat, 21 Oct 2023 21:26:49 +0300 Subject: [PATCH] Project initialization. --- README.adoc | 64 ---------- build.gradle | 31 ++++- pom.xml | 15 ++- settings.gradle | 2 +- src/test/groovy/DataDrivenSpec.groovy | 57 --------- src/test/groovy/HamcrestMatchersSpec.groovy | 35 ----- src/test/groovy/HelloSpockSpec.groovy | 30 ----- .../groovy/IncludeExcludeExtensionSpec.groovy | 74 ----------- .../groovy/OrderedInteractionsSpec.groovy | 45 ------- .../groovy/PublisherSubscriberSpec.groovy | 64 ---------- src/test/groovy/SpecInheritanceSpec.groovy | 41 ------ src/test/groovy/StackSpec.groovy | 120 ------------------ src/test/groovy/StepwiseExtensionSpec.groovy | 42 ------ src/test/groovy/UsingJUnitRulesSpec.groovy | 27 ---- 14 files changed, 38 insertions(+), 609 deletions(-) delete mode 100644 README.adoc delete mode 100644 src/test/groovy/DataDrivenSpec.groovy delete mode 100644 src/test/groovy/HamcrestMatchersSpec.groovy delete mode 100644 src/test/groovy/HelloSpockSpec.groovy delete mode 100644 src/test/groovy/IncludeExcludeExtensionSpec.groovy delete mode 100644 src/test/groovy/OrderedInteractionsSpec.groovy delete mode 100644 src/test/groovy/PublisherSubscriberSpec.groovy delete mode 100644 src/test/groovy/SpecInheritanceSpec.groovy delete mode 100644 src/test/groovy/StackSpec.groovy delete mode 100644 src/test/groovy/StepwiseExtensionSpec.groovy delete mode 100644 src/test/groovy/UsingJUnitRulesSpec.groovy diff --git a/README.adoc b/README.adoc deleted file mode 100644 index 1f029d4..0000000 --- a/README.adoc +++ /dev/null @@ -1,64 +0,0 @@ -[.float-group] --- -image::https://img.shields.io/badge/License-Apache%202.0-blue.svg[link=https://github.com/spockframework/spock/blob/master/LICENSE,float=left] -image::https://github.com/spockframework/spock-example/actions/workflows/main.yml/badge.svg[link=https://github.com/spockframework/spock-example/actions/workflows/main.yml,float=left] -image::https://badges.gitter.im/spockframework/spock.svg[link=https://gitter.im/spockframework/spock?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge,float=left] --- - -== Spock Framework Example Project - - -The purpose of this project is to help you get started with Spock. The project includes several example specifications and build scripts for Gradle and Maven. It also makes it easy to create an Eclipse or IDEA project, allowing you to run the example specs from within your IDE. - -All builds (Gradle and Maven) will automatically download all required dependencies, compile the project, and finally run the example specs. The Gradle build goes one step further by bootstrapping itself, alleviating the need to have a build tool preinstalled. - -=== Prerequisites - -- JDK 8 or higher -- Maven use `mvnw` wrapper -- Gradle use `gradlew` wrapper - -NOTE: This example shows the usage of Spock 2.0, which uses the JUnit Platform. If you want to see how to get Spock 1.x with JUnit 4 up and running see the https://github.com/spockframework/spock-example/tree/spock-1.x[Spock-1.x] Branch. - -=== Building with Gradle -Type: - - ./gradlew clean test - -Downloaded files (including the Gradle distribution itself) will be stored in the Gradle user home directory (typically *user_home*`/.gradle`). - -=== Building with Maven -Type: - - ./mvnw clean test - -Downloaded files will be stored in the local Maven repository (typically *user_home*`/.m2/repository`). - -=== Creating an Eclipse project - -Install the https://projects.eclipse.org/projects/tools.buildship[Buildship plugin] if you want to use gradle as build tool. - -=== Creating an IDEA project -Just open the project directory with Intelli IDEA and it should auto-detect the project settings. - -=== Further Resources - - -* https://spockframework.org[Spock homepage] -* https://meetspock.appspot.com[Spock web console] -* https://docs.spockframework.org/[Main documentation] -* https://stackoverflow.com/questions/tagged/spock[Spock on Stackoverflow] -* https://gitter.im/spockframework/spock[Spock Chat] -* https://github.com/spockframework/spock/discussions[Discussion group] -* https://issues.spockframework.org[Issue tracker] -* https://twitter.com/spockframework[Spock on Twitter] -* https://gradle.org[Gradle homepage] -* https://groovy-lang.org/[Groovy homepage] -* https://maven.apache.org[Maven homepage] - -If you have any comments or questions, please direct them to the Spock discussion group. We appreciate all feedback! - -Happy spec'ing! - -The Spock Framework Team - diff --git a/build.gradle b/build.gradle index ffc8744..8217497 100644 --- a/build.gradle +++ b/build.gradle @@ -1,17 +1,33 @@ plugins { id('groovy') + id('application') + id 'com.github.johnrengelman.shadow' version '7.1.2' } version = "1.0" -description = "Spock Framework - Example Project" +description = "Example of using jdbc for a hostpital." + +application { + mainClassName = 'space.kklochko.jdbc_hospital_example.Main' +} + +shadowJar { + mergeServiceFiles() + minimize() +} -// Spock works with Java 1.8 and above java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(JavaLanguageVersion.of(17)) } } +compileJava { + options.encoding = 'UTF-8' + sourceCompatibility = '1.8' + targetCompatibility = '1.8' +} + repositories { // Spock releases are available from Maven Central mavenCentral() @@ -20,6 +36,14 @@ repositories { } dependencies { + compileOnly 'org.projectlombok:lombok:1.18.30' + annotationProcessor 'org.projectlombok:lombok:1.18.30' + + testCompileOnly 'org.projectlombok:lombok:1.18.30' + testAnnotationProcessor 'org.projectlombok:lombok:1.18.30' + + implementation 'org.postgresql:postgresql:42.6.0' + implementation 'io.github.cdimascio:dotenv-java:3.0.0' // mandatory dependencies for using Spock implementation platform('org.apache.groovy:groovy-bom:4.0.15') implementation 'org.apache.groovy:groovy' @@ -33,7 +57,6 @@ dependencies { testRuntimeOnly "org.objenesis:objenesis:3.3" // allows mocking of classes without default constructor (together with ByteBuddy or CGLIB) // dependencies used by examples in this project - testRuntimeOnly "com.h2database:h2:2.2.222" implementation "org.apache.groovy:groovy-sql" } diff --git a/pom.xml b/pom.xml index 3c5048f..03daabe 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,16 @@ + + org.postgresql + postgresql + 42.6.0 + + + io.github.cdimascio + dotenv-java + 3.0.0 + org.spockframework @@ -113,11 +123,6 @@ test - - com.h2database - h2 - 2.2.222 - org.apache.groovy groovy-sql diff --git a/settings.gradle b/settings.gradle index 6c9b555..16eb0aa 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = "spock-example" \ No newline at end of file +rootProject.name = "jdbc_hospital_example" \ No newline at end of file diff --git a/src/test/groovy/DataDrivenSpec.groovy b/src/test/groovy/DataDrivenSpec.groovy deleted file mode 100644 index 1fd44e5..0000000 --- a/src/test/groovy/DataDrivenSpec.groovy +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.* - -class DataDrivenSpec extends Specification { - def "maximum of two numbers"() { - expect: - Math.max(a, b) == c - - where: - a << [3, 5, 9] - b << [7, 4, 9] - c << [7, 5, 9] - } - - def "minimum of #a and #b is #c"() { - expect: - Math.min(a, b) == c - - where: - a | b || c - 3 | 7 || 3 - 5 | 4 || 4 - 9 | 9 || 9 - } - - def "#person.name is a #sex.toLowerCase() person"() { - expect: - person.getSex() == sex - - where: - person || sex - new Person(name: "Fred") || "Male" - new Person(name: "Wilma") || "Female" - } - - static class Person { - String name - String getSex() { - name == "Fred" ? "Male" : "Female" - } - } -} diff --git a/src/test/groovy/HamcrestMatchersSpec.groovy b/src/test/groovy/HamcrestMatchersSpec.groovy deleted file mode 100644 index afdbf07..0000000 --- a/src/test/groovy/HamcrestMatchersSpec.groovy +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.Specification - -import static spock.util.matcher.HamcrestMatchers.closeTo - -/** - * Hamcrest matchers are deeply integrated with Spock's condition mechanism. - * The syntax for using a matcher in a condition is simple: - * {@code }. If the condition fails, both the usual - * condition output and the matcher's output will be shown. - * - * @author Peter Niederwiser - * @since 0.5 - */ -class HamcrestMatchersSpec extends Specification { - def "comparing two decimal numbers"() { - def myPi = 3.14 - - expect: - myPi closeTo(Math.PI, 0.01) - } -} \ No newline at end of file diff --git a/src/test/groovy/HelloSpockSpec.groovy b/src/test/groovy/HelloSpockSpec.groovy deleted file mode 100644 index d183c89..0000000 --- a/src/test/groovy/HelloSpockSpec.groovy +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.Specification - -class HelloSpockSpec extends Specification { - def "length of Spock's and his friends' names"() { - expect: - name.size() == length - - where: - name | length - "Spock" | 5 - "Kirk" | 4 - "Scotty" | 6 - } -} \ No newline at end of file diff --git a/src/test/groovy/IncludeExcludeExtensionSpec.groovy b/src/test/groovy/IncludeExcludeExtensionSpec.groovy deleted file mode 100644 index e8d5e13..0000000 --- a/src/test/groovy/IncludeExcludeExtensionSpec.groovy +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.lang.annotation.* - -import spock.lang.Specification - -/** - * Shows how methods can be included and excluded from a spec run. For - * demonstration purposes, the configuration script's location is set - * programmatically in a static initializer. Usually, the configuration - * script's location would be set externally (via the same system property), - * or the configuration script would reside in one of the two default locations: - *
  • - *
      SpockConfig.groovy on the class path
    - *
      $user_home/.spock/SpockConfig.groovy on the file system
    - *
  • - * - *

    Note that the configuration script referenced by the system property - * may either reside on the class path or on the file system (make sure to - * include the whole path). - * - *

    What's not shown here is that filtering also works for classes. - * Whereas methods can only be filtered based on annotations, classes can - * also be filtered based on their base class. - * - *

    If you directly want to see the effect of different Spock configurations, - * just run this spec from your IDE with an additional VM parameter - *

  • - *
      -Dspock.configuration=IncludeFastConfig.groovy or
    - *
      -Dspock.configuration=ExcludeSlowConfig.groovy
    - *
  • - * - *

    See also the two corresponding resource files provided with this spec. - * - * @since 0.4 - */ -class IncludeExcludeExtensionSpec extends Specification { - @Fast - def "a fast method"() { - println "fast" - expect: true - } - - @Slow - def "a slow method"() { - println "slow" - expect: true - } - - def "a neither fast nor slow method"() { - println "neither fast nor slow" - expect: true - } -} - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -@interface Fast {} - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -@interface Slow {} diff --git a/src/test/groovy/OrderedInteractionsSpec.groovy b/src/test/groovy/OrderedInteractionsSpec.groovy deleted file mode 100644 index 430b230..0000000 --- a/src/test/groovy/OrderedInteractionsSpec.groovy +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.* - -/** - * The expected order of interactions can now be specified by using multiple - * then-blocks. Interactions in a later then-block must take place after - * interactions in an earlier then-block. The order of interactions within - * the same then-block is unspecified. - * - * @since 0.4 - */ -class OrderedInteractionsSpec extends Specification { - def "collaborators must be invoked in order"() { - def coll1 = Mock(Collaborator) - def coll2 = Mock(Collaborator) - - when: - // try to reverse the order of these invocations and see what happens - coll1.collaborate() - coll2.collaborate() - - then: - 1 * coll1.collaborate() - - then: - 1 * coll2.collaborate() - } -} - -interface Collaborator { - def collaborate() -} diff --git a/src/test/groovy/PublisherSubscriberSpec.groovy b/src/test/groovy/PublisherSubscriberSpec.groovy deleted file mode 100644 index d2d0fef..0000000 --- a/src/test/groovy/PublisherSubscriberSpec.groovy +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.Specification - -class Publisher { - def subscribers = [] - - def send(event) { - subscribers.each { - try { - it.receive(event) - } catch (Exception e) {} - } - } -} - -interface Subscriber { - def receive(event) -} - -class PublisherSpec extends Specification { - def pub = new Publisher() - def sub1 = Mock(Subscriber) - def sub2 = Mock(Subscriber) - - def setup() { - pub.subscribers << sub1 << sub2 - } - - def "delivers events to all subscribers"() { - when: - pub.send("event") - - then: - 1 * sub1.receive("event") - 1 * sub2.receive("event") - } - - def "can cope with misbehaving subscribers"() { - sub1.receive(_) >> { throw new Exception() } - - when: - pub.send("event1") - pub.send("event2") - - then: - 1 * sub2.receive("event1") - 1 * sub2.receive("event2") - } -} diff --git a/src/test/groovy/SpecInheritanceSpec.groovy b/src/test/groovy/SpecInheritanceSpec.groovy deleted file mode 100644 index 3c4a42e..0000000 --- a/src/test/groovy/SpecInheritanceSpec.groovy +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.* - -abstract class BaseSpec extends Specification { - def x = { println 'base field initializer' }() - - def setupSpec() { println 'base setupSpec()' } - def cleanupSpec() { println 'base cleanupSpec()' } - - def setup() { println 'base setup()' } - def cleanup() { println 'base cleanup()' } - - def baseSpecMethod() { setup: println 'base spec method' } -} - -class DerivedSpec extends BaseSpec { - def y = { println 'derived field initializer' }() - - def setupSpec() { println 'derived setupSpec()' } - def cleanupSpec() { println 'derived cleanupSpec()' } - - def setup() { println 'derived setup()' } - def cleanup() { println 'derived cleanup()' } - - def derivedSpecMethod() { setup: println 'derived spec method' } -} \ No newline at end of file diff --git a/src/test/groovy/StackSpec.groovy b/src/test/groovy/StackSpec.groovy deleted file mode 100644 index bf17b19..0000000 --- a/src/test/groovy/StackSpec.groovy +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.Specification - -class EmptyStackSpec extends Specification { - def stack = new Stack() - - def "size"() { - expect: stack.size() == 0 - } - - def "pop"() { - when: stack.pop() - then: thrown(EmptyStackException) - } - - def "peek"() { - when: stack.peek() - then: thrown(EmptyStackException) - } - - def "push"() { - when: - stack.push("elem") - - then: - stack.size() == old(stack.size()) + 1 - stack.peek() == "elem" - } -} - -class StackWithOneElementSpec extends Specification { - def stack = new Stack() - - def setup() { - stack.push("elem") - } - - def "size"() { - expect: stack.size() == 1 - } - - def "pop"() { - when: - def x = stack.pop() - - then: - x == "elem" - stack.size() == 0 - } - - def "peek"() { - when: - def x = stack.peek() - - then: - x == "elem" - stack.size() == 1 - } - - def "push"() { - when: - stack.push("elem2") - - then: - stack.size() == 2 - stack.peek() == "elem2" - } -} - -class StackWithThreeElementsSpec extends Specification { - def stack = new Stack() - - def setup() { - ["elem1", "elem2", "elem3"].each { stack.push(it) } - } - - def "size"() { - expect: stack.size() == 3 - } - - def "pop"() { - expect: - stack.pop() == "elem3" - stack.pop() == "elem2" - stack.pop() == "elem1" - stack.size() == 0 - } - - def "peek"() { - expect: - stack.peek() == "elem3" - stack.peek() == "elem3" - stack.peek() == "elem3" - stack.size() == 3 - } - - def "push"() { - when: - stack.push("elem4") - - then: - stack.size() == 4 - stack.peek() == "elem4" - } -} \ No newline at end of file diff --git a/src/test/groovy/StepwiseExtensionSpec.groovy b/src/test/groovy/StepwiseExtensionSpec.groovy deleted file mode 100644 index e519dbf..0000000 --- a/src/test/groovy/StepwiseExtensionSpec.groovy +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import spock.lang.* - -/** - * Demonstrates how {@code @Stepwise} causes a spec to be run in incremental steps. - * Change a step's condition from {@literal true} to {@literal false}, and observe - * how the remaining steps will be skipped automatically on the next run. - * Also notice that if you run a single step (e.g. from the IDE's context menu), - * all prior steps will also be run. - * - *

    {@code @Stepwise} is particularly useful for higher-level specs whose - * methods have logical dependencies. - * - * @since 0.4 - */ -@Stepwise -class StepwiseExtensionSpec extends Specification { - def "step 1"() { - expect: true // try to change this to 'false' - } - - def "step 2"() { - expect: true - } - - def "step 3"() { - expect: true - } -} diff --git a/src/test/groovy/UsingJUnitRulesSpec.groovy b/src/test/groovy/UsingJUnitRulesSpec.groovy deleted file mode 100644 index 0d7a5f3..0000000 --- a/src/test/groovy/UsingJUnitRulesSpec.groovy +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2009 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.junit.Rule -import org.junit.rules.TestName -import spock.lang.Specification - -class UsingJUnitRulesSpec extends Specification { - @Rule TestName name - - def "retrieve test name at runtime"() { - println "entering '$name.methodName'" - expect: 1 + 1 == 2 - println "leaving '$name.methodName'" - } -}