Skip to content

Commit

Permalink
fix: UpdateAppProfileRequest equals and hashcode should build proto (g…
Browse files Browse the repository at this point in the history
…oogleapis#1142)

* fix: UpdateAppProfileRequest equals and hashcode should build proto

* lint

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
kolea2 and gcf-owl-bot[bot] committed Jan 28, 2022
1 parent dfb6085 commit c9f1ed8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ public boolean equals(Object o) {
UpdateAppProfileRequest that = (UpdateAppProfileRequest) o;
return Objects.equal(instanceId, that.instanceId)
&& Objects.equal(appProfileId, that.appProfileId)
&& Objects.equal(proto, that.proto);
&& Objects.equal(proto.build(), that.proto.build());
}

@Override
public int hashCode() {
return Objects.hashCode(instanceId, appProfileId, proto);
return Objects.hashCode(instanceId, appProfileId, proto.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,75 @@ public void testNoPolicyError() {

assertThat(actualException).isInstanceOf(IllegalArgumentException.class);
}

@Test
public void testEquals() {
AppProfile profile =
AppProfile.fromProto(
com.google.bigtable.admin.v2.AppProfile.newBuilder()
.setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString())
.setDescription("my description")
.setMultiClusterRoutingUseAny(
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder()
.addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))
.build())
.setEtag("my-etag")
.build());

UpdateAppProfileRequest updateAppProfileRequest = UpdateAppProfileRequest.of(profile);
UpdateAppProfileRequest updateAppProfileRequest2 = UpdateAppProfileRequest.of(profile);

assertThat(updateAppProfileRequest).isEqualTo(updateAppProfileRequest2);

AppProfile profile2 =
AppProfile.fromProto(
com.google.bigtable.admin.v2.AppProfile.newBuilder()
.setName(AppProfileName.of("my-project-2", "my-instance", "my-profile").toString())
.setDescription("my description")
.setMultiClusterRoutingUseAny(
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder()
.addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))
.build())
.setEtag("my-etag")
.build());
UpdateAppProfileRequest updateAppProfileRequest3 = UpdateAppProfileRequest.of(profile2);

assertThat(updateAppProfileRequest).isNotEqualTo(updateAppProfileRequest3);
}

@Test
public void testHashCode() {
AppProfile profile =
AppProfile.fromProto(
com.google.bigtable.admin.v2.AppProfile.newBuilder()
.setName(AppProfileName.of("my-project", "my-instance", "my-profile").toString())
.setDescription("my description")
.setMultiClusterRoutingUseAny(
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder()
.addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))
.build())
.setEtag("my-etag")
.build());

UpdateAppProfileRequest updateAppProfileRequest = UpdateAppProfileRequest.of(profile);
UpdateAppProfileRequest updateAppProfileRequest2 = UpdateAppProfileRequest.of(profile);

assertThat(updateAppProfileRequest.hashCode()).isEqualTo(updateAppProfileRequest2.hashCode());

AppProfile profile2 =
AppProfile.fromProto(
com.google.bigtable.admin.v2.AppProfile.newBuilder()
.setName(AppProfileName.of("my-project-2", "my-instance", "my-profile").toString())
.setDescription("my description")
.setMultiClusterRoutingUseAny(
com.google.bigtable.admin.v2.AppProfile.MultiClusterRoutingUseAny.newBuilder()
.addAllClusterIds(ImmutableList.of("cluster-id-1", "cluster-id-2"))
.build())
.setEtag("my-etag")
.build());
UpdateAppProfileRequest updateAppProfileRequest3 = UpdateAppProfileRequest.of(profile2);

assertThat(updateAppProfileRequest.hashCode())
.isNotEqualTo(updateAppProfileRequest3.hashCode());
}
}

0 comments on commit c9f1ed8

Please sign in to comment.