Skip to content

Commit c4854d5

Browse files
java-team-github-botGuice Team
authored and
Guice Team
committed
Fix tests that break with Java 17 base on suggestions from @mcculls #1536 (comment)
- skip reflection fallback test that only works for java version < 17 - add required jvm flags to mirror maven setup - upgrade mockito version PiperOrigin-RevId: 423389524
1 parent 02c4687 commit c4854d5

File tree

7 files changed

+41
-9
lines changed

7 files changed

+41
-9
lines changed

WORKSPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ maven_install(
7676
"org.hsqldb", "hsqldb-j5", "2.0.0", testonly = True
7777
),
7878
maven.artifact(
79-
"org.mockito", "mockito-core", "1.9.5", testonly = True
79+
"org.mockito", "mockito-core", "4.2.0", testonly = True
8080
),
8181
],
8282
repositories = [

core/test/com/google/inject/BUILD

+15
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ java_library(
7272

7373
guice_test_suites(
7474
name = "gen_tests",
75+
jvm_flags = [
76+
# those 2 options are required for some tests that checks stack traces
77+
"-XX:+UnlockDiagnosticVMOptions",
78+
"-XX:+ShowHiddenFrames",
79+
],
7580
sizes = [
7681
"small",
7782
"medium",
@@ -84,6 +89,11 @@ guice_test_suites(
8489
args = [
8590
"--guice_include_stack_traces=%s" % include_stack_trace_option,
8691
],
92+
jvm_flags = [
93+
# those 2 options are required for some tests that checks stack traces
94+
"-XX:+UnlockDiagnosticVMOptions",
95+
"-XX:+ShowHiddenFrames",
96+
],
8797
sizes = [
8898
"small",
8999
"medium",
@@ -99,6 +109,11 @@ guice_test_suites(
99109
args = [
100110
"--guice_custom_class_loading=%s" % custom_class_loading_option,
101111
],
112+
jvm_flags = [
113+
# those 2 options are required for some tests that checks stack traces
114+
"-XX:+UnlockDiagnosticVMOptions",
115+
"-XX:+ShowHiddenFrames",
116+
],
102117
sizes = [
103118
"small",
104119
"medium",

core/test/com/googlecode/guice/BUILD

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ java_library(
2828

2929
guice_test_suites(
3030
name = "gen_tests",
31+
jvm_flags = [
32+
# those 2 options are required for some tests that checks stack traces
33+
"-XX:+UnlockDiagnosticVMOptions",
34+
"-XX:+ShowHiddenFrames",
35+
],
3136
sizes = [
3237
"small",
3338
"medium",
@@ -40,6 +45,11 @@ guice_test_suites(
4045
args = [
4146
"--guice_custom_class_loading=%s" % custom_class_loading_option,
4247
],
48+
jvm_flags = [
49+
# those 2 options are required for some tests that checks stack traces
50+
"-XX:+UnlockDiagnosticVMOptions",
51+
"-XX:+ShowHiddenFrames",
52+
],
4353
sizes = [
4454
"small",
4555
"medium",

extensions/assistedinject/test/com/google/inject/assistedinject/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ java_library(
1515
"//core/test/com/google/inject:testsupport",
1616
"//extensions/assistedinject/src/com/google/inject/assistedinject",
1717
"//third_party/java/aopalliance",
18+
"//third_party/java/guava/base",
1819
"//third_party/java/guava/collect",
1920
"//third_party/java/jsr330_inject",
2021
"//third_party/java/junit",

extensions/assistedinject/test/com/google/inject/assistedinject/subpkg/SubpackageTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import static org.junit.Assert.fail;
55
import static org.junit.Assume.assumeTrue;
66

7+
import com.google.common.base.StandardSystemProperty;
78
import com.google.common.collect.Iterables;
89
import com.google.common.collect.Lists;
910
import com.google.inject.AbstractModule;
@@ -36,7 +37,8 @@
3637
*/
3738
@RunWith(JUnit4.class)
3839
public final class SubpackageTest {
39-
40+
private static final double JAVA_VERSION =
41+
Double.parseDouble(StandardSystemProperty.JAVA_SPECIFICATION_VERSION.value());
4042
private final Logger loggerToWatch = Logger.getLogger(AssistedInject.class.getName());
4143

4244
private final List<LogRecord> logRecords = Lists.newArrayList();
@@ -144,6 +146,7 @@ protected void configure() {
144146

145147
@Test
146148
public void testReflectionFallbackWorks() throws Exception {
149+
assumeTrue(JAVA_VERSION < 17);
147150
Injector injector =
148151
Guice.createInjector(
149152
new AbstractModule() {
@@ -167,7 +170,7 @@ protected void configure() {
167170
public void testGeneratedDefaultMethodsForwardCorrectly() throws Exception {
168171
// This test requires above java 1.8.
169172
// 1.8's reflection capability is tested via "testReflectionFallbackWorks".
170-
assumeTrue(Double.parseDouble(System.getProperty("java.specification.version")) > 1.8);
173+
assumeTrue(JAVA_VERSION > 1.8);
171174

172175
setLookupReflection(false);
173176
final Key<AbstractAssisted.Factory<ConcreteAssisted, String>> concreteKey =

extensions/persist/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>org.mockito</groupId>
4949
<artifactId>mockito-core</artifactId>
50-
<version>1.9.5</version>
50+
<version>4.2.0</version>
5151
<scope>test</scope>
5252
</dependency>
5353
<dependency>

test_defs.bzl

+8-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ _gen_suite = rule(
4444
implementation = _impl,
4545
)
4646

47-
def guice_test_suites(name, deps, srcs = None, args = [], suffix = "", sizes = None):
47+
def guice_test_suites(name, deps, srcs = None, args = [], suffix = "", sizes = None, jvm_flags = []):
4848
"""
4949
Generates tests for test file in srcs ending in "Test.java"
5050
@@ -53,17 +53,20 @@ def guice_test_suites(name, deps, srcs = None, args = [], suffix = "", sizes = N
5353
srcs: list of test source files, uses 'glob(["**/*Test.java"])' if not specified
5454
deps: list of runtime dependencies requried to run the test
5555
args: list of flags to pass to the test
56+
jvm_flags: list of JVM flags to pass to the test
5657
suffix: suffix to apend to the generated test name
5758
sizes: not used, exists only so that the opensource guice_test_suites mirror exactly the internal one
5859
"""
59-
jvm_flags = []
60+
61+
flags = []
62+
flags.extend(jvm_flags)
6063

6164
# transform flags to JVM options used externally
6265
for arg in args:
6366
if arg.startswith("--"):
64-
jvm_flags.append(arg.replace("--", "-D"))
67+
flags.append(arg.replace("--", "-D"))
6568
else:
66-
jvm_flags.append(arg)
69+
flags.append(arg)
6770

6871
package_name = native.package_name()
6972

@@ -89,7 +92,7 @@ def guice_test_suites(name, deps, srcs = None, args = [], suffix = "", sizes = N
8992
native.java_test(
9093
name = "AllTestsSuite" + suffix,
9194
test_class = (package_name + "/" + suite_name).replace("/", "."),
92-
jvm_flags = jvm_flags,
95+
jvm_flags = flags,
9396
srcs = [":" + suite_name],
9497
deps = deps + [
9598
"//third_party/java/junit",

0 commit comments

Comments
 (0)