Skip to content

Commit a958811

Browse files
test: add errorprone and fix all of the errors (#2638)
Change-Id: I273e614ab8d5e8e1bf73e031e80729dda0b2f0de
1 parent 95e7abf commit a958811

17 files changed

+220
-66
lines changed

google-cloud-bigtable/pom.xml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,50 @@
400400
</plugins>
401401
</build>
402402
</profile>
403+
<profile>
404+
<id>error-prone</id>
405+
<activation>
406+
<!-- errorprone requires >= jdk17 -->
407+
<jdk>[17,)</jdk>
408+
</activation>
409+
<build>
410+
<pluginManagement>
411+
<plugins>
412+
<plugin>
413+
<groupId>org.apache.maven.plugins</groupId>
414+
<artifactId>maven-compiler-plugin</artifactId>
415+
<configuration>
416+
<fork>true</fork>
417+
418+
<compilerArgs>
419+
<arg>-XDcompilePolicy=simple</arg>
420+
<arg>--should-stop=ifError=FLOW</arg>
421+
<arg>-Xplugin:ErrorProne -XepExcludedPaths:.*/generated-sources/.*</arg>
422+
423+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
424+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
425+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
426+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
427+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
428+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
429+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
430+
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
431+
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
432+
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
433+
</compilerArgs>
434+
<annotationProcessorPaths combine.children="append">
435+
<path>
436+
<groupId>com.google.errorprone</groupId>
437+
<artifactId>error_prone_core</artifactId>
438+
<version>${error-prone.version}</version>
439+
</path>
440+
</annotationProcessorPaths>
441+
</configuration>
442+
</plugin>
443+
</plugins>
444+
</pluginManagement>
445+
</build>
446+
</profile>
403447
<profile>
404448
<id>enable-verbose-grpc-logs</id>
405449
<properties>

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/BigtableInstanceAdminSettingsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,6 @@ void checkToString(BigtableInstanceAdminSettings settings) {
163163
for (String subSettings : SETTINGS_LIST) {
164164
assertThat(toString).contains(subSettings + "=");
165165
}
166-
assertThat(toString.contains(settings.getStubSettings().toString()));
166+
assertThat(toString).contains(settings.getStubSettings().toString());
167167
}
168168
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/it/BigtableCmekIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public static void validatePlatform() throws IOException {
100100
Sets.difference(
101101
ImmutableSet.of(
102102
testEnvRule.env().getPrimaryZone(), testEnvRule.env().getSecondaryZone()),
103-
ImmutableSet.of(zones))
103+
ImmutableSet.copyOf(zones))
104104
.iterator()
105105
.next();
106106

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/ConsistencyRequestTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.bigtable.admin.v2.CheckConsistencyRequest;
2121
import com.google.bigtable.admin.v2.GenerateConsistencyTokenRequest;
22+
import com.google.cloud.bigtable.data.v2.internal.NameUtil;
2223
import com.google.cloud.bigtable.data.v2.internal.TableAdminRequestContext;
2324
import org.junit.Test;
2425
import org.junit.runner.RunWith;
@@ -41,12 +42,11 @@ public void testToCheckConsistencyProtoWithStandard() {
4142
CheckConsistencyRequest checkConsistencyRequest =
4243
consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN);
4344

44-
assertThat(checkConsistencyRequest.getName().equals(TABLE_ID));
45-
assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN));
46-
assertThat(
47-
checkConsistencyRequest
48-
.getModeCase()
49-
.equals(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES));
45+
assertThat(checkConsistencyRequest.getName())
46+
.isEqualTo(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID));
47+
assertThat(checkConsistencyRequest.getConsistencyToken()).isEqualTo(CONSISTENCY_TOKEN);
48+
assertThat(checkConsistencyRequest.getModeCase())
49+
.isEqualTo(CheckConsistencyRequest.ModeCase.STANDARD_READ_REMOTE_WRITES);
5050
}
5151

5252
@Test
@@ -59,12 +59,11 @@ public void testToCheckConsistencyProtoWithDataBoost() {
5959
CheckConsistencyRequest checkConsistencyRequest =
6060
consistencyRequest.toCheckConsistencyProto(requestContext, CONSISTENCY_TOKEN);
6161

62-
assertThat(checkConsistencyRequest.getName().equals(TABLE_ID));
63-
assertThat(checkConsistencyRequest.getConsistencyToken().equals(CONSISTENCY_TOKEN));
64-
assertThat(
65-
checkConsistencyRequest
66-
.getModeCase()
67-
.equals(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES));
62+
assertThat(checkConsistencyRequest.getName())
63+
.isEqualTo(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID));
64+
assertThat(checkConsistencyRequest.getConsistencyToken()).isEqualTo(CONSISTENCY_TOKEN);
65+
assertThat(checkConsistencyRequest.getModeCase())
66+
.isEqualTo(CheckConsistencyRequest.ModeCase.DATA_BOOST_READ_LOCAL_WRITES);
6867
}
6968

7069
@Test
@@ -77,6 +76,7 @@ public void testToGenerateTokenProto() {
7776
GenerateConsistencyTokenRequest generateRequest =
7877
consistencyRequest.toGenerateTokenProto(requestContext);
7978

80-
assertThat(generateRequest.getName().equals(TABLE_ID));
79+
assertThat(generateRequest.getName())
80+
.isEqualTo(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID));
8181
}
8282
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/admin/v2/models/GCRulesTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public void durationTimeUnitNegative() {
9090
public void versions() {
9191
VersionRule actual = GCRULES.maxVersions(10);
9292
GcRule expected = buildVersionsRule(10);
93-
assertNotNull(actual.getMaxVersions());
9493
assertThat(actual.toProto()).isEqualTo(expected);
9594
}
9695

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/AbstractProtoStructReaderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import org.junit.runners.Parameterized;
7474
import org.junit.runners.Parameterized.Parameter;
7575

76+
@SuppressWarnings("DoubleBraceInitialization")
7677
@RunWith(Enclosed.class)
7778
public class AbstractProtoStructReaderTest {
7879

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ProtoStructTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.junit.runner.RunWith;
5656
import org.junit.runners.JUnit4;
5757

58+
@SuppressWarnings("DoubleBraceInitialization")
5859
@RunWith(JUnit4.class)
5960
public class ProtoStructTest {
6061

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/internal/ResultSetImplTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ private static ResultSet resultSetWithFakeStream(
8282
return ResultSetImpl.create(SqlServerStreamImpl.create(future, stream.call(fakeCallContext)));
8383
}
8484

85+
@SuppressWarnings("DoubleBraceInitialization")
8586
@Test
8687
public void testSingleRow() throws ExecutionException, InterruptedException {
8788
com.google.bigtable.v2.ResultSetMetadata protoMetadata =

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ExecuteQueryIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ public void withHistoryQuery() {
152152
}
153153
}
154154

155+
@SuppressWarnings("DoubleBraceInitialization")
155156
@Test
156157
public void allTypes() {
157158
PreparedStatement preparedStatement =

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/StreamingMetricsMetadataIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,9 @@ public void testSuccess() throws Exception {
138138
public void testFailure() {
139139
Query query = Query.create("non-exist-table");
140140
try {
141-
Lists.newArrayList(client.readRows(query));
142-
} catch (NotFoundException e) {
141+
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
142+
ArrayList<Row> ignored = Lists.newArrayList(client.readRows(query));
143+
} catch (NotFoundException ignored) {
143144
}
144145

145146
Collection<MetricData> allMetricData = metricReader.collectAllMetrics();

0 commit comments

Comments
 (0)