Skip to content

Commit 8938ce7

Browse files
author
Ajay Kannan
committed
Minor fixes
1 parent 988a045 commit 8938ce7

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

  • gcloud-java-resourcemanager/src

gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Policy.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public enum Type {
7373
* <li>Set up billing (for a project).
7474
* </ul>
7575
*/
76-
OWNER;
76+
OWNER
7777
}
7878

7979
private static final long serialVersionUID = 2421978909244287488L;
@@ -134,12 +134,16 @@ static Role fromStr(String roleStr) {
134134

135135
@Override
136136
public final int hashCode() {
137-
return Objects.hash(value);
137+
return Objects.hash(value, type);
138138
}
139139

140140
@Override
141141
public final boolean equals(Object obj) {
142-
return obj instanceof Role && Objects.equals(value, ((Role) obj).value());
142+
if (!(obj instanceof Role)) {
143+
return false;
144+
}
145+
Role other = (Role) obj;
146+
return Objects.equals(value, other.value()) && Objects.equals(type, other.type());
143147
}
144148
}
145149

gcloud-java-resourcemanager/src/test/java/com/google/gcloud/resourcemanager/PolicyTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.gcloud.resourcemanager;
1818

1919
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotEquals;
2021
import static org.junit.Assert.assertNull;
2122

2223
import com.google.common.collect.ImmutableSet;
@@ -63,4 +64,16 @@ public void testRoleType() {
6364
assertEquals(Type.VIEWER, Role.viewer().type());
6465
assertNull(Role.rawRole("raw-role").type());
6566
}
67+
68+
@Test
69+
public void testEquals() {
70+
Policy copy = Policy.builder()
71+
.addBinding(Role.owner(), ImmutableSet.of(USER))
72+
.addBinding(Role.viewer(), ImmutableSet.of(ALL_USERS))
73+
.addBinding(Role.editor(), ImmutableSet.of(ALL_AUTH_USERS, DOMAIN))
74+
.addBinding(Role.rawRole("some-role"), ImmutableSet.of(SERVICE_ACCOUNT, GROUP))
75+
.build();
76+
assertEquals(SIMPLE_POLICY, copy);
77+
assertNotEquals(SIMPLE_POLICY, FULL_POLICY);
78+
}
6679
}

0 commit comments

Comments
 (0)