Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
fix: fixed compilation warnings from error prone
Browse files Browse the repository at this point in the history
* 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
dangazineu committed Jan 4, 2022
1 parent 275b882 commit e6e7040
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Expand Up @@ -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);
}

Expand Down
Expand Up @@ -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);
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand All @@ -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.