Skip to content

Commit

Permalink
Make project compatible with Java 17 (#385)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
psx95 authored Dec 9, 2024
1 parent 53d4fb9 commit c19b136
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ subprojects {
openTelemetryContribVersion = '1.39.0'
junitVersion = '4.13'
junit5Version = '5.10.0'
mockitoVersion = '3.5.10'
mockitoVersion = '5.2.0'
pubSubVersion = '1.133.0'
testContainersVersion = '1.15.1'
wiremockVersion = '2.35.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void testCreateWithMetricServiceSettingExportSucceeds() throws IOExceptio
// verify that the MetricServiceClient used in the exporter was created using the
// MetricServiceSettings provided in configuration
mockedServiceClientClass.verify(
times(1), () -> MetricServiceClient.create(eq(configuration.getMetricServiceSettings())));
() -> MetricServiceClient.create(eq(configuration.getMetricServiceSettings())), times(1));

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

mockedMetricServiceClient.verify(
Mockito.times(1),
() -> MetricServiceClient.create((MetricServiceSettings) Mockito.any()));
mockedServiceOptions.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
() -> MetricServiceClient.create((MetricServiceSettings) Mockito.any()),
Mockito.times(1));
mockedServiceOptions.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
Mockito.verify(this.mockMetricServiceClient)
.createTimeSeries((ProjectName) Mockito.any(), Mockito.anyList());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testConfigurationWithDefaultProjectIdSucceeds() {

MetricConfiguration configuration = MetricConfiguration.builder().build();
assertEquals(PROJECT_ID, configuration.getProjectId());
serviceOptionsMockedStatic.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
serviceOptionsMockedStatic.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
}
}

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

// ServiceOptions#getDefaultProjectId should only be called once per TraceConfiguration object
serviceOptionsMockedStatic.verify(Mockito.times(2), ServiceOptions::getDefaultProjectId);
serviceOptionsMockedStatic.verify(ServiceOptions::getDefaultProjectId, Mockito.times(2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void allowToUseDefaultProjectId() {
TraceConfiguration traceConfiguration = TraceConfiguration.builder().build();
assertEquals(PROJECT_ID, traceConfiguration.getProjectId());

mockedServiceOptions.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
mockedServiceOptions.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
}
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public void verifyCallToDefaultProjectIdIsMemoize() {
traceConfiguration2.getProjectId();

// ServiceOptions#getDefaultProjectId should only be called once per TraceConfiguration object
serviceOptionsMockedStatic.verify(Mockito.times(2), ServiceOptions::getDefaultProjectId);
serviceOptionsMockedStatic.verify(ServiceOptions::getDefaultProjectId, Mockito.times(2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public void verifyExporterWorksWithDefaultConfiguration() {
simulateExport(exporter);

mockedTraceServiceClient.verify(
Mockito.times(1), () -> TraceServiceClient.create((TraceServiceSettings) Mockito.any()));
mockedServiceOptions.verify(Mockito.times(1), ServiceOptions::getDefaultProjectId);
() -> TraceServiceClient.create((TraceServiceSettings) Mockito.any()), Mockito.times(1));
mockedServiceOptions.verify(ServiceOptions::getDefaultProjectId, Mockito.times(1));
Mockito.verify(this.mockedTraceServiceClient)
.batchWriteSpans((ProjectName) Mockito.any(), Mockito.anyList());
}
Expand Down

0 comments on commit c19b136

Please sign in to comment.