Skip to content
Permalink
Browse files
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
  • Loading branch information
danielgazineu committed Jan 4, 2022
1 parent 275b882 commit e6e7040305b19ec9d5468f4cd44d7a29d0d5e470
@@ -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);
}

@@ -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);
@@ -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
@@ -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();
}
}

0 comments on commit e6e7040

Please sign in to comment.