diff --git a/build.gradle b/build.gradle index 8dbf89c2d1..b3c8e911b4 100755 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,7 @@ ext { junitPlatformTestkit: [group: 'org.junit.platform', name: 'junit-platform-testkit'], junitPlatformConsole: [group: 'org.junit.platform', name: 'junit-platform-console'], log4j : [group: 'log4j', name: 'log4j', version: '1.2.17'], - objenesis : [group: 'org.objenesis', name: 'objenesis', version: '3.2'], + objenesis : [group: 'org.objenesis', name: 'objenesis', version: '3.3'], jacocoAgent : [group: 'org.jacoco', name: 'org.jacoco.agent', version: '0.8.8', classifier: 'runtime'] ] } @@ -122,8 +122,10 @@ subprojects { } tasks.withType(JavaCompile) { - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(8) + if (it.name == 'compileJava') { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(8) + } } options.encoding = 'UTF-8' } @@ -183,7 +185,6 @@ subprojects { from javadoc } - def javaVersionNoShadow = javaVersion // Test task also has javaVersion tasks.withType(Test) { useJUnitPlatform() def taskName = name diff --git a/config/nohttp/checkstyle.xml b/config/nohttp/checkstyle.xml new file mode 100644 index 0000000000..1f34c01f37 --- /dev/null +++ b/config/nohttp/checkstyle.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927a4d..249e5832f0 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b9c57a29e6..fa7964518d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists # https://gradle.org/release-checksums/ -distributionSha256Sum=29e49b10984e585d8118b7d0bc452f944e386458df27371b49b4ac1dec4b7fda -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionSha256Sum=f6b8596b10cce501591e92f229816aa4046424f3b24d771751b06779d58c8ec4 +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787337..a69d9cb6c2 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd32c4..f127cfd49d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/spock-core/src/main/java/org/spockframework/util/ReflectionUtil.java b/spock-core/src/main/java/org/spockframework/util/ReflectionUtil.java index d4a28c0cb4..8cec72fd3b 100644 --- a/spock-core/src/main/java/org/spockframework/util/ReflectionUtil.java +++ b/spock-core/src/main/java/org/spockframework/util/ReflectionUtil.java @@ -249,9 +249,9 @@ public static void deepCopyFields(Object source, Object target) { Class clazz = source.getClass(); while (!clazz.equals(Object.class)) { Field[] fields = clazz.getDeclaredFields(); - for (Field field : fields) { - copyField(field, source, target); - } + Arrays.stream(fields) + .filter(field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()))) + .forEach(field -> copyField(field, source, target)); clazz = clazz.getSuperclass(); } } diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionEvaluation.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionEvaluation.groovy index b9620e677d..aa10f1822f 100755 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionEvaluation.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionEvaluation.groovy @@ -209,7 +209,7 @@ class ConditionEvaluation extends EmbeddedSpecification { def "PropertyExpression"() { expect: - [1, 2, 3].size == 3 + new Person(age: 3).age == 3 (new Properties().next.next.next.x = 10) == 10 Integer.MIN_VALUE < Integer.MAX_VALUE } @@ -404,4 +404,3 @@ class ConditionEvaluation extends EmbeddedSpecification { def eat(args) { args } } } - diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionRendering.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionRendering.groovy index cb8e4fac6f..644973957b 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionRendering.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/condition/ConditionRendering.groovy @@ -488,13 +488,13 @@ null def "PropertyExpression"() { expect: isRendered """ -a.size == null -| | | -| 1 false +a.empty == true +| | | +| false false [9] """, { def a = [9] - assert a.size == null + assert a.empty == true } isRendered """ @@ -903,4 +903,3 @@ false String toString() { "p" } } } - diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/GroovySpiesThatAreGlobal.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/GroovySpiesThatAreGlobal.groovy index 5e48bef018..6a73819ea4 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/GroovySpiesThatAreGlobal.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/GroovySpiesThatAreGlobal.groovy @@ -15,6 +15,7 @@ package org.spockframework.smoke.mock import spock.lang.* +import spock.util.environment.Jvm import java.lang.reflect.Modifier import java.util.regex.Pattern @@ -173,7 +174,8 @@ class GroovySpiesThatAreGlobal extends Specification { } def "mock static method"() { - GroovySpy(Collections, global: true) + // Use objenesis to create instance for Java 17 and later + GroovySpy(Collections, global: true, useObjenesis: Jvm.current.java17Compatible) when: Collections.emptyList() @@ -186,7 +188,7 @@ class GroovySpiesThatAreGlobal extends Specification { } def "mock dynamic static method"() { - GroovySpy(Collections, global: true) + GroovySpy(Collections, global: true, useObjenesis: Jvm.current.java17Compatible) when: Collections.foo() diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy index 25b4f02af4..33550af279 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy @@ -201,6 +201,11 @@ class JavaSpies extends Specification { e.message.contains("global") } + + @IgnoreIf( + value = { jvm.java17Compatible }, + reason = "We can't access private fields in java.util anymore, without an explicit --add-opens" + ) @Issue("https://github.com/spockframework/spock/issues/822") def "inferred type is ignored for instance mocks"() { when: @@ -301,4 +306,3 @@ class JavaSpies extends Specification { } } } - diff --git a/spock-spring/spring.gradle b/spock-spring/spring.gradle index 302a0b1592..43d9a01552 100755 --- a/spock-spring/spring.gradle +++ b/spock-spring/spring.gradle @@ -1,3 +1,7 @@ +plugins { + id 'jvm-test-suite' +} + apply from: script("publishMaven") ext.displayName = "Spock Framework - Spring Module" @@ -6,9 +10,22 @@ description = "Spock's Spring Module makes it possible to use Spring's TestConte Supports Spring 2.5.x, 3.x, and 4.x." def springVersion = "4.3.5.RELEASE" +def testSpringVersions = [ + "3.2.16.RELEASE": (8..8), + (springVersion): (8..11), + "5.0.2.RELEASE": (8..11), + "6.0.0-M5": (17..17) +].findAll { javaVersion in it.value } -if (springVersion.startsWith("2.")) { - sourceSets.test.groovy.exclude "**/*ContextHierarchyExample.groovy" +// necessary until we have a final version of Spring 6 +repositories { + mavenCentral() + maven { + url = "https://repo.spring.io/artifactory/libs-milestone-local/" + content { + includeGroup "org.springframework" + } + } } dependencies { @@ -16,23 +33,62 @@ dependencies { compileOnly "org.springframework:spring-test:$springVersion" compileOnly "org.springframework:spring-beans:$springVersion" compileOnly "org.springframework:spring-context:$springVersion" +} + +testing { + suites { + all { + useJUnitJupiter() + dependencies { + implementation "javax.inject:javax.inject:1" + implementation libs.groovySql // for groovy.sql.Sql + implementation libs.junitPlatformTestkit + runtimeOnly libs.h2database + runtimeOnly libs.log4j + runtimeOnly libs.bytebuddy + runtimeOnly libs.cglib + runtimeOnly libs.objenesis + } + } - // not used directly at implementation-time, but needed by groovyc - testImplementation "org.springframework:spring-test:$springVersion" - testImplementation "org.springframework:spring-beans:$springVersion" - testImplementation "org.springframework:spring-context:$springVersion" - testImplementation "org.springframework:spring-core:$springVersion" - testImplementation "org.springframework:spring-jdbc:$springVersion" - testImplementation "org.springframework:spring-tx:$springVersion" - testImplementation "javax.inject:javax.inject:1" - testImplementation libs.groovySql // for groovy.sql.Sql - testImplementation libs.junitPlatformTestkit - - testRuntimeOnly libs.h2database - testRuntimeOnly libs.log4j - testRuntimeOnly libs.bytebuddy - testRuntimeOnly libs.cglib - testRuntimeOnly libs.objenesis + test { + targets { + all { + testTask.configure { + onlyIf { false } //skip normal test task + } + } + } + } + + + testSpringVersions.each { testSpringVersion, __ -> + "spring${testSpringVersion.charAt(0)}"(JvmTestSuite) { + + sources { + java { + srcDir 'src/test/java' + } + groovy { + srcDir 'src/test/groovy' + } + resources { + srcDir 'src/test/resources' + } + } + + dependencies { + implementation project + implementation "org.springframework:spring-test:$testSpringVersion" + implementation "org.springframework:spring-beans:$testSpringVersion" + implementation "org.springframework:spring-context:$testSpringVersion" + implementation "org.springframework:spring-core:$testSpringVersion" + implementation "org.springframework:spring-jdbc:$testSpringVersion" + implementation "org.springframework:spring-tx:$testSpringVersion" + } + } + } + } } task testCglib(type: Test) { @@ -41,6 +97,7 @@ task testCglib(type: Test) { } check.dependsOn testCglib +check.dependsOn testSpringVersions.collect {k,v -> "spring${k.charAt(0)}" } jar { manifest { diff --git a/spock-spring/src/test/groovy/org/spockframework/spring/MockInjectionExample.groovy b/spock-spring/src/test/groovy/org/spockframework/spring/MockInjectionExample.groovy index a1e81e91a0..429d25c21c 100644 --- a/spock-spring/src/test/groovy/org/spockframework/spring/MockInjectionExample.groovy +++ b/spock-spring/src/test/groovy/org/spockframework/spring/MockInjectionExample.groovy @@ -17,30 +17,39 @@ package org.spockframework.spring import org.spockframework.mock.MockUtil +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import spock.lang.IgnoreIf import spock.lang.Specification import javax.inject.Named -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration - +@IgnoreIf( + value = { jvm.java17Compatible }, + reason = "Spring 4s reflection doesn't work on 17+" +) @ContextConfiguration(locations = "MockExamples-context.xml") class MockInjectionExample extends Specification { - @Autowired @Named('serviceMock') + @Autowired + @Named('serviceMock') IService1 serviceMock - @Autowired @Named('serviceStub') + @Autowired + @Named('serviceStub') IService1 serviceStub - @Autowired @Named('serviceSpy') + @Autowired + @Named('serviceSpy') IService2 serviceSpy - @Autowired @Named('service2') + @Autowired + @Named('service2') IService2 service2 - @Autowired @Named('nonMock') + @Autowired + @Named('nonMock') ArrayList concreteSpy; def "Injected services are mocks"() { diff --git a/spock-spring/src/test/groovy/org/spockframework/spring/docs/MockExamples.groovy b/spock-spring/src/test/groovy/org/spockframework/spring/docs/MockExamples.groovy index 4df7db0f91..c043edd2df 100644 --- a/spock-spring/src/test/groovy/org/spockframework/spring/docs/MockExamples.groovy +++ b/spock-spring/src/test/groovy/org/spockframework/spring/docs/MockExamples.groovy @@ -16,6 +16,7 @@ package org.spockframework.spring.docs +import spock.lang.IgnoreIf import spock.lang.Specification import javax.inject.Named @@ -81,6 +82,10 @@ class DetachedJavaConfigExample extends MockExampleBase { } +@IgnoreIf( + value = { jvm.java17Compatible }, + reason = "Spring 4s reflection doesn't work on 17+" +) @ContextConfiguration(locations = "classpath:org/spockframework/spring/docs/MockDocu-context.xml") class DetachedXmlExample extends MockExampleBase { }