From e6e7040305b19ec9d5468f4cd44d7a29d0d5e470 Mon Sep 17 00:00:00 2001 From: Daniel Gazineu Date: Tue, 4 Jan 2022 14:49:39 -0500 Subject: [PATCH] fix: fixed compilation warnings from error prone * Fixed equals check to compare against other instead of self * Added annotation to ignore error prone warning (Details here: https://errorprone.info/bugpattern/TruthSelfEquals) * Fixed EqualsTester usage (details on usage error here https://errorprone.info/bugpattern/MissingTestCall, proper usage described at https://www.javadoc.io/doc/com.google.guava/guava-testlib/21.0/com/google/common/testing/EqualsTester.html) * Added missing assertion --- .../java/com/google/cloud/ServiceOptions.java | 2 +- .../google/cloud/BaseServiceExceptionTest.java | 1 + .../src/test/java/com/google/cloud/DateTest.java | 4 +--- .../java/com/google/cloud/StringEnumTest.java | 16 ++++++++-------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 7891088d34..8ffb77eaf5 100644 --- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -697,7 +697,7 @@ protected boolean baseEquals(ServiceOptions other) { && Objects.equals(retrySettings, other.retrySettings) && Objects.equals(serviceFactoryClassName, other.serviceFactoryClassName) && Objects.equals(serviceRpcFactoryClassName, other.serviceRpcFactoryClassName) - && Objects.equals(clock, clock) + && Objects.equals(clock, other.clock) && Objects.equals(quotaProjectId, other.quotaProjectId); } diff --git a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java index 1f6de6007b..4bc5993f7f 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/BaseServiceExceptionTest.java @@ -140,6 +140,7 @@ public void testTranslateAndThrow() throws Exception { } @Test + @SuppressWarnings("TruthSelfEquals") public void testError_Equal() { BaseServiceException.Error error = new BaseServiceException.Error(0, "reason", true); assertThat(error).isEqualTo(error); diff --git a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java index 14b6a139d0..d95efaf094 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/DateTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/DateTest.java @@ -126,9 +126,7 @@ public void equalAndHashCode() { Date d1 = Date.fromYearMonthDay(2016, 9, 18); Date d2 = Date.fromYearMonthDay(2016, 9, 18); Date d3 = Date.fromYearMonthDay(2016, 9, 19); - EqualsTester tester = new EqualsTester(); - tester.addEqualityGroup(d1, d2); - tester.addEqualityGroup(d3); + new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3).testEquals(); } @Test diff --git a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java index edef7820cd..781fbb8925 100644 --- a/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java +++ b/google-cloud-core/src/test/java/com/google/cloud/StringEnumTest.java @@ -101,13 +101,12 @@ public void testValueOfStrict() { @Test public void testEquals() { - EqualsTester tester = new EqualsTester(); - - tester.addEqualityGroup(Letter.A, Letter.valueOf("A"), Letter.valueOfStrict("A")); - tester.addEqualityGroup(Letter.B, Letter.valueOf("B"), Letter.valueOfStrict("B")); - tester.addEqualityGroup(Letter.C, Letter.valueOf("C"), Letter.valueOfStrict("C")); - tester.addEqualityGroup( - Letter.valueOf("NonExistentLetter"), Letter.valueOf("NonExistentLetter")); + new EqualsTester() + .addEqualityGroup(Letter.A, Letter.valueOf("A"), Letter.valueOfStrict("A")) + .addEqualityGroup(Letter.B, Letter.valueOf("B"), Letter.valueOfStrict("B")) + .addEqualityGroup(Letter.C, Letter.valueOf("C"), Letter.valueOfStrict("C")) + .addEqualityGroup(Letter.valueOf("NonExistentLetter"), Letter.valueOf("NonExistentLetter")) + .testEquals(); } @Test @@ -123,6 +122,7 @@ public void testValueOfStrict_invalid() { @Test public void testValues() { assertThat( - Arrays.asList(Letter.values()).containsAll(Arrays.asList(Letter.A, Letter.B, Letter.C))); + Arrays.asList(Letter.values()).containsAll(Arrays.asList(Letter.A, Letter.B, Letter.C))) + .isTrue(); } }