Skip to content

Commit c19b136

Browse files
authored
Make project compatible with Java 17 (#385)
Mockito 3.5.x is incompatible when building with Java 17, therefore an update to a more recent version of Mockito is required. There have been breaking changes in Mockito's releases which are difficult to point out. Some tests required code changes to make them compatible with these changes. Only breaking change that affected this codebase was the handling of static mocks.
1 parent 53d4fb9 commit c19b136

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ subprojects {
165165
openTelemetryContribVersion = '1.39.0'
166166
junitVersion = '4.13'
167167
junit5Version = '5.10.0'
168-
mockitoVersion = '3.5.10'
168+
mockitoVersion = '5.2.0'
169169
pubSubVersion = '1.133.0'
170170
testContainersVersion = '1.15.1'
171171
wiremockVersion = '2.35.0'

exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/GoogleCloudMetricExporterTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void testCreateWithMetricServiceSettingExportSucceeds() throws IOExceptio
171171
// verify that the MetricServiceClient used in the exporter was created using the
172172
// MetricServiceSettings provided in configuration
173173
mockedServiceClientClass.verify(
174-
times(1), () -> MetricServiceClient.create(eq(configuration.getMetricServiceSettings())));
174+
() -> MetricServiceClient.create(eq(configuration.getMetricServiceSettings())), times(1));
175175

176176
// verify that export operation on the resulting exporter can still be called
177177
CompletableResultCode result = exporter.export(ImmutableList.of(aMetricData, aHistogram));
@@ -816,9 +816,9 @@ public void verifyExporterWorksWithDefaultConfiguration() {
816816
simulateExport(metricExporter);
817817

818818
mockedMetricServiceClient.verify(
819-
Mockito.times(1),
820-
() -> MetricServiceClient.create((MetricServiceSettings) Mockito.any()));
821-
mockedServiceOptions.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
819+
() -> MetricServiceClient.create((MetricServiceSettings) Mockito.any()),
820+
Mockito.times(1));
821+
mockedServiceOptions.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
822822
Mockito.verify(this.mockMetricServiceClient)
823823
.createTimeSeries((ProjectName) Mockito.any(), Mockito.anyList());
824824
} finally {

exporters/metrics/src/test/java/com/google/cloud/opentelemetry/metric/MetricConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void testConfigurationWithDefaultProjectIdSucceeds() {
107107

108108
MetricConfiguration configuration = MetricConfiguration.builder().build();
109109
assertEquals(PROJECT_ID, configuration.getProjectId());
110-
serviceOptionsMockedStatic.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
110+
serviceOptionsMockedStatic.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
111111
}
112112
}
113113

@@ -127,7 +127,7 @@ public void verifyCallToDefaultProjectIdIsMemoized() {
127127
metricConfiguration2.getProjectId();
128128

129129
// ServiceOptions#getDefaultProjectId should only be called once per TraceConfiguration object
130-
serviceOptionsMockedStatic.verify(Mockito.times(2), ServiceOptions::getDefaultProjectId);
130+
serviceOptionsMockedStatic.verify(ServiceOptions::getDefaultProjectId, Mockito.times(2));
131131
}
132132
}
133133
}

exporters/trace/src/test/java/com/google/cloud/opentelemetry/trace/TraceConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void allowToUseDefaultProjectId() {
9898
TraceConfiguration traceConfiguration = TraceConfiguration.builder().build();
9999
assertEquals(PROJECT_ID, traceConfiguration.getProjectId());
100100

101-
mockedServiceOptions.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
101+
mockedServiceOptions.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
102102
}
103103
}
104104

@@ -164,7 +164,7 @@ public void verifyCallToDefaultProjectIdIsMemoize() {
164164
traceConfiguration2.getProjectId();
165165

166166
// ServiceOptions#getDefaultProjectId should only be called once per TraceConfiguration object
167-
serviceOptionsMockedStatic.verify(Mockito.times(2), ServiceOptions::getDefaultProjectId);
167+
serviceOptionsMockedStatic.verify(ServiceOptions::getDefaultProjectId, Mockito.times(2));
168168
}
169169
}
170170
}

exporters/trace/src/test/java/com/google/cloud/opentelemetry/trace/TraceExporterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public void verifyExporterWorksWithDefaultConfiguration() {
101101
simulateExport(exporter);
102102

103103
mockedTraceServiceClient.verify(
104-
Mockito.times(1), () -> TraceServiceClient.create((TraceServiceSettings) Mockito.any()));
105-
mockedServiceOptions.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
104+
() -> TraceServiceClient.create((TraceServiceSettings) Mockito.any()), Mockito.times(1));
105+
mockedServiceOptions.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
106106
Mockito.verify(this.mockedTraceServiceClient)
107107
.batchWriteSpans((ProjectName) Mockito.any(), Mockito.anyList());
108108
}

0 commit comments

Comments
 (0)