Skip to content

Commit

Permalink
Fix test failures with Java 17 + Gradle 7.5.1
Browse files Browse the repository at this point in the history
Prior to version 7.5, Gradle added some `--add-opens` flags,
that hid potential issues with tests, for Java 16+.

gradle/gradle#20999
  • Loading branch information
leonard84 committed Aug 31, 2022
1 parent 6023143 commit 8ede7c3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -404,4 +404,3 @@ class ConditionEvaluation extends EmbeddedSpecification {
def eat(args) { args }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -903,4 +903,3 @@ false
String toString() { "p" }
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.spockframework.spring.docs

import spock.lang.IgnoreIf
import spock.lang.Specification

import javax.inject.Named
Expand Down Expand Up @@ -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 {
}

0 comments on commit 8ede7c3

Please sign in to comment.