File tree Expand file tree Collapse file tree
gcloud-java-resourcemanager/src
main/java/com/google/gcloud/resourcemanager
test/java/com/google/gcloud/resourcemanager Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1717package com .google .gcloud .resourcemanager ;
1818
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertNotEquals ;
2021import static org .junit .Assert .assertNull ;
2122
2223import 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}
You can’t perform that action at this time.
0 commit comments