test: Disable copying annotation on mocks for Java 8 CIs#13702
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors several test classes across different modules to instantiate Mockito mocks explicitly using withSettings().withoutAnnotations() instead of using @Mock annotations or standard mock() calls. The feedback suggests removing the now-unused mockitoRule fields and their associated imports in SpannerCloudMonitoringExporterTest and BigtableTableAdminClientV2Test since no @Mock annotations remain in those classes.
| @Rule public final MockitoRule mockitoRule = MockitoJUnit.rule(); | ||
|
|
||
| @Mock private MetricServiceStub mockMetricServiceStub; | ||
| private MetricServiceStub mockMetricServiceStub; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| "projects/my-project/instances/my-instance/tables/my-table"; | ||
|
|
||
| @Mock private GrpcBigtableTableAdminStub mockStub; | ||
| private GrpcBigtableTableAdminStub mockStub; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
…e-cloud-java into test-withoutannotations
|
|



In JSpecify 1.0.0, the
@NullMarkedannotation includesElementType.MODULEin its@Targetmetadata. BecauseElementType.MODULEwas introduced in Java 9, reflecting on@NullMarkedclasses under Java 8 (JDK 1.8) throwsEnumConstantNotPresentExceptionProxywrapped in anArrayStoreException.When unit tests run on Java 8, Mockito's default mock generation (via ByteBuddy) attempts to copy all runtime class annotations from target classes onto mock subclasses. This triggers the reflection crash when mocking generated stub and settings classes that are annotated with
@NullMarked.To bypass this Java 8 limitation:
Mockito.mock(Class, Mockito.withSettings().withoutAnnotations())across the failing unit test suites.Class.getAnnotations()on the target class during proxy creation, allowing tests to run and mock stubs successfully on Java 8 pipelines.Modified Mockito mock setups in:
StreamingSubscriberConnectionTestSpannerImplTestSpannerCloudMonitoringExporterTestBigtableInstanceAdminClientV2TestBigtableTableAdminClientV2TestBigtableCloudMonitoringExporterTestGrpcLongRunningClientTest